From 28f1107dad938dcf99e75fc9ac09e3923b897a82 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 14 Dec 2017 10:45:59 -0500 Subject: [PATCH] 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@7b13e8dc9842fbc4854c1e6fba2d018bfcf59085 --- .../plan/logical/UnresolvedRelationTests.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/sql/server/src/test/java/org/elasticsearch/xpack/sql/plan/logical/UnresolvedRelationTests.java b/sql/server/src/test/java/org/elasticsearch/xpack/sql/plan/logical/UnresolvedRelationTests.java index 402a35f7dd6..5dfe5ffd607 100644 --- a/sql/server/src/test/java/org/elasticsearch/xpack/sql/plan/logical/UnresolvedRelationTests.java +++ b/sql/server/src/test/java/org/elasticsearch/xpack/sql/plan/logical/UnresolvedRelationTests.java @@ -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> 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));