SQL: Fix test for UnresolvedRelation
`UnresolvedRelation`'s equality test would sometimes not properly mutate the object under test. This is because `ESTestCase#randomValueOtherThan` will only run its provider one time if passed `null` for the "other than" value. Original commit: elastic/x-pack-elasticsearch@7b13e8dc98
This commit is contained in:
parent
2268e592c6
commit
28f1107dad
|
@ -8,8 +8,10 @@ package org.elasticsearch.xpack.sql.plan.logical;
|
|||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.sql.plan.TableIdentifier;
|
||||
import org.elasticsearch.xpack.sql.tree.Location;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.elasticsearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashCode;
|
||||
|
@ -23,16 +25,27 @@ public class UnresolvedRelationTests extends ESTestCase {
|
|||
UnresolvedRelation relation = new UnresolvedRelation(location, table, alias, unresolvedMessage);
|
||||
List<Function<UnresolvedRelation, UnresolvedRelation>> mutators = new ArrayList<>();
|
||||
mutators.add(r -> new UnresolvedRelation(
|
||||
new Location(r.location().getLineNumber() + 1, r.location().getColumnNumber()), r.table(), r.alias(), r.unresolvedMessage()));
|
||||
new Location(r.location().getLineNumber() + 1, r.location().getColumnNumber()),
|
||||
r.table(),
|
||||
r.alias(),
|
||||
r.unresolvedMessage()));
|
||||
mutators.add(r -> new UnresolvedRelation(
|
||||
r.location(), new TableIdentifier(r.location(), r.table().index() + "m"), r.alias(), r.unresolvedMessage()));
|
||||
r.location(),
|
||||
new TableIdentifier(r.location(), r.table().index() + "m"),
|
||||
r.alias(),
|
||||
r.unresolvedMessage()));
|
||||
mutators.add(r -> new UnresolvedRelation(
|
||||
r.location(),
|
||||
r.table(),
|
||||
randomValueOtherThan(r.alias(), () -> randomBoolean() ? null : randomAlphaOfLength(5)),
|
||||
randomValueOtherThanMany(
|
||||
a -> Objects.equals(a, r.alias()),
|
||||
() -> randomBoolean() ? null : randomAlphaOfLength(5)),
|
||||
r.unresolvedMessage()));
|
||||
mutators.add(r -> new UnresolvedRelation(
|
||||
r.location(), r.table(), r.alias(), randomValueOtherThan(r.unresolvedMessage(), () -> randomAlphaOfLength(5))));
|
||||
r.location(),
|
||||
r.table(),
|
||||
r.alias(),
|
||||
randomValueOtherThan(r.unresolvedMessage(), () -> randomAlphaOfLength(5))));
|
||||
checkEqualsAndHashCode(relation,
|
||||
r -> new UnresolvedRelation(r.location(), r.table(), r.alias(), r.unresolvedMessage()),
|
||||
r -> randomFrom(mutators).apply(r));
|
||||
|
|
Loading…
Reference in New Issue