mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
Switch to using predicate for testing existing value
This commit is contained in:
parent
4cf5385e4d
commit
372eceb854
@ -30,6 +30,7 @@ import org.elasticsearch.test.ESTestCase;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class FieldSortBuilderTests extends AbstractSortTestCase<FieldSortBuilder> {
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase<ScriptSortBuild
|
||||
exceptThis.add(SortMode.SUM);
|
||||
exceptThis.add(SortMode.AVG);
|
||||
exceptThis.add(SortMode.MEDIAN);
|
||||
builder.sortMode(ESTestCase.randomValueOtherThanMany(exceptThis, () -> randomFrom(SortMode.values())));
|
||||
builder.sortMode(ESTestCase.randomValueOtherThanMany(exceptThis::contains, () -> randomFrom(SortMode.values())));
|
||||
}
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
|
@ -87,6 +87,7 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static org.elasticsearch.common.util.CollectionUtils.arrayAsArrayList;
|
||||
@ -410,21 +411,21 @@ public abstract class ESTestCase extends LuceneTestCase {
|
||||
* helper to get a random value in a certain range that's different from the input
|
||||
*/
|
||||
public static <T> T randomValueOtherThan(T input, Supplier<T> randomSupplier) {
|
||||
T randomValue = null;
|
||||
do {
|
||||
randomValue = randomSupplier.get();
|
||||
} while (randomValue.equals(input));
|
||||
return randomValue;
|
||||
if (input != null) {
|
||||
return randomValueOtherThanMany(input::equals, randomSupplier);
|
||||
}
|
||||
|
||||
return(randomSupplier.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* helper to get a random value in a certain range that's different from the input
|
||||
*/
|
||||
public static <T> T randomValueOtherThanMany(Collection<T> input, Supplier<T> randomSupplier) {
|
||||
public static <T> T randomValueOtherThanMany(Predicate<T> input, Supplier<T> randomSupplier) {
|
||||
T randomValue = null;
|
||||
do {
|
||||
randomValue = randomSupplier.get();
|
||||
} while (input.contains(randomValue));
|
||||
} while (input.test(randomValue));
|
||||
return randomValue;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user