Get rid of no longer needed missing generation method

This commit is contained in:
Isabel Drost-Fromm 2016-04-28 15:27:36 +02:00
parent 0c7e58de93
commit 3490daa7ea
2 changed files with 12 additions and 36 deletions

View File

@ -28,6 +28,8 @@ import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.test.ESTestCase;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
public class FieldSortBuilderTests extends AbstractSortTestCase<FieldSortBuilder> {
@ -36,7 +38,14 @@ public class FieldSortBuilderTests extends AbstractSortTestCase<FieldSortBuilder
return randomFieldSortBuilder();
}
public static FieldSortBuilder randomFieldSortBuilder() {
private List<Object> missingContent = Arrays.asList(
"_last",
"_first",
ESTestCase.randomAsciiOfLength(10), ESTestCase.randomUnicodeOfCodepointLengthBetween(5, 15),
ESTestCase.randomInt());
public FieldSortBuilder randomFieldSortBuilder() {
String fieldName = rarely() ? FieldSortBuilder.DOC_FIELD_NAME : randomAsciiOfLengthBetween(1, 10);
FieldSortBuilder builder = new FieldSortBuilder(fieldName);
if (randomBoolean()) {
@ -44,7 +53,7 @@ public class FieldSortBuilderTests extends AbstractSortTestCase<FieldSortBuilder
}
if (randomBoolean()) {
builder.missing(RandomSortDataGenerator.missing(builder.missing()));
builder.missing(ESTestCase.randomValueOtherThan(builder.missing(), () -> randomFrom(missingContent)));
}
if (randomBoolean()) {
@ -92,7 +101,7 @@ public class FieldSortBuilderTests extends AbstractSortTestCase<FieldSortBuilder
() -> ESTestCase.randomAsciiOfLengthBetween(1, 10)));
break;
case 4:
mutated.missing(RandomSortDataGenerator.missing(mutated.missing()));
mutated.missing(ESTestCase.randomValueOtherThan(mutated.missing(), () -> randomFrom(missingContent)));
break;
case 5:
mutated.order(ESTestCase.randomValueOtherThan(mutated.order(), () -> randomFrom(SortOrder.values())));

View File

@ -19,16 +19,12 @@
package org.elasticsearch.search.sort;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.index.query.IdsQueryBuilder;
import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.test.ESTestCase;
import java.util.HashSet;
import java.util.Set;
public class RandomSortDataGenerator {
private RandomSortDataGenerator() {
// this is a helper class only, doesn't need a constructor
@ -55,33 +51,4 @@ public class RandomSortDataGenerator {
return nested;
}
public static Object missing(Object original) {
Object missing = null;
Object otherMissing = original;
while (missing == null || missing.equals(otherMissing)) {
int missingId = ESTestCase.randomIntBetween(0, 4);
switch (missingId) {
case 0:
missing = ("_last");
break;
case 1:
missing = ("_first");
break;
case 2:
missing = ESTestCase.randomAsciiOfLength(10);
break;
case 3:
missing = ESTestCase.randomUnicodeOfCodepointLengthBetween(5, 15);
break;
case 4:
missing = ESTestCase.randomInt();
break;
default:
throw new IllegalStateException("Unknown missing type.");
}
}
return missing;
}
}