Improve coverage of equals/hashCode tests for IntervalQueryBuilder (#49820)
By default, AbstractQueryTestCase only changes name and boost in its mutateInstance method, used when checking equals and hashcode implementations. This commit adds a mutateInstance method to InveralQueryBuilderTests that will check hashcode and equality when the field or intervals source are changed.
This commit is contained in:
parent
53d801c0d7
commit
312190266e
|
@ -55,6 +55,14 @@ public class IntervalQueryBuilder extends AbstractQueryBuilder<IntervalQueryBuil
|
|||
this.sourceProvider = in.readNamedWriteable(IntervalsSourceProvider.class);
|
||||
}
|
||||
|
||||
public String getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
public IntervalsSourceProvider getSourceProvider() {
|
||||
return sourceProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(field);
|
||||
|
|
|
@ -143,6 +143,17 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
|
|||
assertThat(query, instanceOf(IntervalQuery.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntervalQueryBuilder mutateInstance(IntervalQueryBuilder instance) throws IOException {
|
||||
if (randomBoolean()) {
|
||||
return super.mutateInstance(instance); // just change name/boost
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
return new IntervalQueryBuilder(STRING_FIELD_NAME_2, instance.getSourceProvider());
|
||||
}
|
||||
return new IntervalQueryBuilder(STRING_FIELD_NAME, createRandomSource(0));
|
||||
}
|
||||
|
||||
public void testMatchInterval() throws IOException {
|
||||
|
||||
String json = "{ \"intervals\" : " +
|
||||
|
|
Loading…
Reference in New Issue