From 76d2dd7e68ee4dc390ad9acf253e06d1d8d135c0 Mon Sep 17 00:00:00 2001 From: Bjørn Christian Seime Date: Wed, 27 Jul 2022 16:46:07 +0200 Subject: Convert predicate-search-core to junit5 --- predicate-search-core/pom.xml | 21 ++++- .../yahoo/document/predicate/BinaryFormatTest.java | 28 +++--- .../document/predicate/BooleanPredicateTest.java | 23 ++--- .../yahoo/document/predicate/ConjunctionTest.java | 53 +++++------ .../yahoo/document/predicate/DisjunctionTest.java | 53 +++++------ .../document/predicate/FeatureConjunctionTest.java | 53 ++++++----- .../yahoo/document/predicate/FeatureRangeTest.java | 78 ++++++++-------- .../yahoo/document/predicate/FeatureSetTest.java | 73 +++++++-------- .../com/yahoo/document/predicate/NegationTest.java | 33 +++---- .../document/predicate/PredicateHashTest.java | 8 +- .../document/predicate/PredicateOperatorTest.java | 6 +- .../document/predicate/PredicateParserTest.java | 54 ++++++----- .../yahoo/document/predicate/PredicateTest.java | 62 ++++++------- .../document/predicate/PredicateValueTest.java | 6 +- .../yahoo/document/predicate/PredicatesTest.java | 24 ++--- .../document/predicate/RangeEdgePartitionTest.java | 33 ++++--- .../document/predicate/RangePartitionTest.java | 25 +++-- .../search/predicate/PredicateQueryParserTest.java | 22 ++--- .../optimization/AndOrSimplifierTest.java | 102 ++++++++++----------- .../optimization/BooleanSimplifierTest.java | 18 ++-- .../optimization/ComplexNodeTransformerTest.java | 36 ++++---- .../optimization/NotNodeReordererTest.java | 22 ++--- .../predicate/optimization/OrSimplifierTest.java | 16 ++-- 23 files changed, 424 insertions(+), 425 deletions(-) (limited to 'predicate-search-core') diff --git a/predicate-search-core/pom.xml b/predicate-search-core/pom.xml index 4951b3d40f1..0862d76c5a1 100644 --- a/predicate-search-core/pom.xml +++ b/predicate-search-core/pom.xml @@ -14,14 +14,15 @@ jar ${project.artifactId} - - junit - junit - test - org.antlr antlr-runtime + + + junit + junit + + com.yahoo.vespa @@ -34,6 +35,16 @@ ${project.version} provided + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + com.fasterxml.jackson.core jackson-core diff --git a/predicate-search-core/src/test/java/com/yahoo/document/predicate/BinaryFormatTest.java b/predicate-search-core/src/test/java/com/yahoo/document/predicate/BinaryFormatTest.java index c37d6b246a5..0f15fcd656a 100644 --- a/predicate-search-core/src/test/java/com/yahoo/document/predicate/BinaryFormatTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/document/predicate/BinaryFormatTest.java @@ -3,10 +3,10 @@ package com.yahoo.document.predicate; import com.yahoo.slime.Inspector; import com.yahoo.slime.Slime; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Simon Thoresen Hult @@ -14,7 +14,7 @@ import static org.junit.Assert.fail; public class BinaryFormatTest { @Test - public void requireThatEncodeNullThrows() { + void requireThatEncodeNullThrows() { try { BinaryFormat.encode(null); fail(); @@ -24,7 +24,7 @@ public class BinaryFormatTest { } @Test - public void requireThatDecodeNullThrows() { + void requireThatDecodeNullThrows() { try { BinaryFormat.decode(null); fail(); @@ -34,7 +34,7 @@ public class BinaryFormatTest { } @Test - public void requireThatDecodeEmptyThrows() { + void requireThatDecodeEmptyThrows() { try { BinaryFormat.decode(new byte[0]); fail(); @@ -44,17 +44,17 @@ public class BinaryFormatTest { } @Test - public void requireThatConjunctionCanBeSerialized() { + void requireThatConjunctionCanBeSerialized() { assertSerialize(new Conjunction(new FeatureSet("foo", "bar"), new FeatureSet("baz", "cox"))); } @Test - public void requireThatDisjunctionCanBeSerialized() { + void requireThatDisjunctionCanBeSerialized() { assertSerialize(new Disjunction(new FeatureSet("foo", "bar"), new FeatureSet("baz", "cox"))); } @Test - public void requireThatFeatureRangeCanBeSerialized() { + void requireThatFeatureRangeCanBeSerialized() { assertSerialize(new FeatureRange("foo", null, null)); assertSerialize(new FeatureRange("foo", null, 9L)); assertSerialize(new FeatureRange("foo", 6L, null)); @@ -62,7 +62,7 @@ public class BinaryFormatTest { } @Test - public void requireThatPartitionedFeatureRangeCanBeSerialized() { + void requireThatPartitionedFeatureRangeCanBeSerialized() { FeatureRange expected = new FeatureRange("foo", 8L, 20L); FeatureRange f = new FeatureRange("foo", 8L, 20L); f.addPartition(new RangeEdgePartition("foo=0", 0, 8, -1)); @@ -87,25 +87,25 @@ public class BinaryFormatTest { } @Test - public void requireThatFeatureSetCanBeSerialized() { + void requireThatFeatureSetCanBeSerialized() { assertSerialize(new FeatureSet("foo")); assertSerialize(new FeatureSet("foo", "bar")); assertSerialize(new FeatureSet("foo", "bar", "baz")); } @Test - public void requireThatNegationCanBeSerialized() { + void requireThatNegationCanBeSerialized() { assertSerialize(new Negation(new FeatureSet("foo", "bar"))); } @Test - public void requireThatBooleanCanBeSerialized() { + void requireThatBooleanCanBeSerialized() { assertSerialize(new BooleanPredicate(true)); assertSerialize(new BooleanPredicate(false)); } @Test - public void requireThatUnknownNodeThrows() { + void requireThatUnknownNodeThrows() { try { BinaryFormat.encode(SimplePredicates.newString("foo")); fail(); diff --git a/predicate-search-core/src/test/java/com/yahoo/document/predicate/BooleanPredicateTest.java b/predicate-search-core/src/test/java/com/yahoo/document/predicate/BooleanPredicateTest.java index 92c45520504..0dbfdb2559d 100644 --- a/predicate-search-core/src/test/java/com/yahoo/document/predicate/BooleanPredicateTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/document/predicate/BooleanPredicateTest.java @@ -1,12 +1,9 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author Simon Thoresen Hult @@ -14,12 +11,12 @@ import static org.junit.Assert.assertTrue; public class BooleanPredicateTest { @Test - public void requireThatFalseIsAValue() { + void requireThatFalseIsAValue() { assertTrue(PredicateValue.class.isAssignableFrom(BooleanPredicate.class)); } @Test - public void requireThatCloneIsImplemented() throws CloneNotSupportedException { + void requireThatCloneIsImplemented() throws CloneNotSupportedException { BooleanPredicate node1 = new BooleanPredicate(true); BooleanPredicate node2 = node1.clone(); assertEquals(node1, node2); @@ -27,21 +24,21 @@ public class BooleanPredicateTest { } @Test - public void requireThatHashCodeIsImplemented() { + void requireThatHashCodeIsImplemented() { assertEquals(new BooleanPredicate(true).hashCode(), new BooleanPredicate(true).hashCode()); assertEquals(new BooleanPredicate(false).hashCode(), new BooleanPredicate(false).hashCode()); } @Test - public void requireThatEqualsIsImplemented() { + void requireThatEqualsIsImplemented() { BooleanPredicate lhs = new BooleanPredicate(true); - assertTrue(lhs.equals(lhs)); - assertFalse(lhs.equals(new Object())); + assertEquals(lhs, lhs); + assertNotEquals(lhs, new Object()); BooleanPredicate rhs = new BooleanPredicate(false); - assertFalse(lhs.equals(rhs)); + assertNotEquals(lhs, rhs); rhs.setValue(true); - assertTrue(lhs.equals(rhs)); + assertEquals(lhs, rhs); } } diff --git a/predicate-search-core/src/test/java/com/yahoo/document/predicate/ConjunctionTest.java b/predicate-search-core/src/test/java/com/yahoo/document/predicate/ConjunctionTest.java index cbcab2917e5..fa4872715f6 100644 --- a/predicate-search-core/src/test/java/com/yahoo/document/predicate/ConjunctionTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/document/predicate/ConjunctionTest.java @@ -1,14 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author Simon Thoresen Hult @@ -16,12 +13,12 @@ import static org.junit.Assert.assertTrue; public class ConjunctionTest { @Test - public void requireThatConjunctionIsAnOperator() { + void requireThatConjunctionIsAnOperator() { assertTrue(PredicateOperator.class.isAssignableFrom(Conjunction.class)); } @Test - public void requireThatAccessorsWork() { + void requireThatAccessorsWork() { Conjunction node = new Conjunction(); Predicate a = SimplePredicates.newString("a"); node.addOperand(a); @@ -40,7 +37,7 @@ public class ConjunctionTest { } @Test - public void requireThatConstructorsWork() { + void requireThatConstructorsWork() { Predicate foo = SimplePredicates.newString("foo"); Predicate bar = SimplePredicates.newString("bar"); Conjunction node = new Conjunction(foo, bar); @@ -51,7 +48,7 @@ public class ConjunctionTest { } @Test - public void requireThatCloneIsImplemented() throws CloneNotSupportedException { + void requireThatCloneIsImplemented() throws CloneNotSupportedException { Conjunction node1 = new Conjunction(SimplePredicates.newString("a"), SimplePredicates.newString("b")); Conjunction node2 = node1.clone(); assertEquals(node1, node2); @@ -60,27 +57,27 @@ public class ConjunctionTest { } @Test - public void requireThatHashCodeIsImplemented() { + void requireThatHashCodeIsImplemented() { assertEquals(new Conjunction().hashCode(), new Conjunction().hashCode()); } @Test - public void requireThatEqualsIsImplemented() { + void requireThatEqualsIsImplemented() { Conjunction lhs = new Conjunction(SimplePredicates.newString("foo"), - SimplePredicates.newString("bar")); - assertTrue(lhs.equals(lhs)); - assertFalse(lhs.equals(new Object())); + SimplePredicates.newString("bar")); + assertEquals(lhs, lhs); + assertNotEquals(lhs, new Object()); Conjunction rhs = new Conjunction(); - assertFalse(lhs.equals(rhs)); + assertNotEquals(lhs, rhs); rhs.addOperand(SimplePredicates.newString("foo")); - assertFalse(lhs.equals(rhs)); + assertNotEquals(lhs, rhs); rhs.addOperand(SimplePredicates.newString("bar")); - assertTrue(lhs.equals(rhs)); + assertEquals(lhs, rhs); } @Test - public void requireThatNodeDelimiterIsAND() { + void requireThatNodeDelimiterIsAND() { assertEquals("", newConjunction().toString()); assertEquals("foo", newConjunction("foo").toString()); assertEquals("foo and bar", newConjunction("foo", "bar").toString()); @@ -88,22 +85,22 @@ public class ConjunctionTest { } @Test - public void requireThatSimpleConjunctionsArePrettyPrinted() { + void requireThatSimpleConjunctionsArePrettyPrinted() { assertEquals("foo and bar", - new Conjunction(SimplePredicates.newString("foo"), - SimplePredicates.newString("bar")).toString()); + new Conjunction(SimplePredicates.newString("foo"), + SimplePredicates.newString("bar")).toString()); } @Test - public void requireThatComplexConjunctionsArePrintedAsGroup() { + void requireThatComplexConjunctionsArePrintedAsGroup() { assertEquals("foo and bar and baz", - new Conjunction(SimplePredicates.newString("foo"), - new Conjunction(SimplePredicates.newString("bar"), - SimplePredicates.newString("baz"))).toString()); + new Conjunction(SimplePredicates.newString("foo"), + new Conjunction(SimplePredicates.newString("bar"), + SimplePredicates.newString("baz"))).toString()); assertEquals("foo and (bar or baz)", - new Conjunction(SimplePredicates.newString("foo"), - new Disjunction(SimplePredicates.newString("bar"), - SimplePredicates.newString("baz"))).toString()); + new Conjunction(SimplePredicates.newString("foo"), + new Disjunction(SimplePredicates.newString("bar"), + SimplePredicates.newString("baz"))).toString()); } private static Conjunction newConjunction(String... operands) { diff --git a/predicate-search-core/src/test/java/com/yahoo/document/predicate/DisjunctionTest.java b/predicate-search-core/src/test/java/com/yahoo/document/predicate/DisjunctionTest.java index 1dab0dd80a2..d5640c7f0a2 100644 --- a/predicate-search-core/src/test/java/com/yahoo/document/predicate/DisjunctionTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/document/predicate/DisjunctionTest.java @@ -1,14 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author Simon Thoresen Hult @@ -16,12 +13,12 @@ import static org.junit.Assert.assertTrue; public class DisjunctionTest { @Test - public void requireThatDisjunctionIsAnOperator() { + void requireThatDisjunctionIsAnOperator() { assertTrue(PredicateOperator.class.isAssignableFrom(Disjunction.class)); } @Test - public void requireThatAccessorsWork() { + void requireThatAccessorsWork() { Disjunction node = new Disjunction(); Predicate a = SimplePredicates.newString("a"); node.addOperand(a); @@ -40,7 +37,7 @@ public class DisjunctionTest { } @Test - public void requireThatConstructorsWork() { + void requireThatConstructorsWork() { Predicate foo = SimplePredicates.newString("foo"); Predicate bar = SimplePredicates.newString("bar"); Disjunction node = new Disjunction(foo, bar); @@ -51,7 +48,7 @@ public class DisjunctionTest { } @Test - public void requireThatCloneIsImplemented() throws CloneNotSupportedException { + void requireThatCloneIsImplemented() throws CloneNotSupportedException { Disjunction node1 = new Disjunction(SimplePredicates.newString("a"), SimplePredicates.newString("b")); Disjunction node2 = node1.clone(); assertEquals(node1, node2); @@ -60,27 +57,27 @@ public class DisjunctionTest { } @Test - public void requireThatHashCodeIsImplemented() { + void requireThatHashCodeIsImplemented() { assertEquals(new Disjunction().hashCode(), new Disjunction().hashCode()); } @Test - public void requireThatEqualsIsImplemented() { + void requireThatEqualsIsImplemented() { Disjunction lhs = new Disjunction(SimplePredicates.newString("foo"), - SimplePredicates.newString("bar")); - assertTrue(lhs.equals(lhs)); - assertFalse(lhs.equals(new Object())); + SimplePredicates.newString("bar")); + assertEquals(lhs, lhs); + assertNotEquals(lhs, new Object()); Disjunction rhs = new Disjunction(); - assertFalse(lhs.equals(rhs)); + assertNotEquals(lhs, rhs); rhs.addOperand(SimplePredicates.newString("foo")); - assertFalse(lhs.equals(rhs)); + assertNotEquals(lhs, rhs); rhs.addOperand(SimplePredicates.newString("bar")); - assertTrue(lhs.equals(rhs)); + assertEquals(lhs, rhs); } @Test - public void requireThatNodeDelimiterIsOR() { + void requireThatNodeDelimiterIsOR() { assertEquals("", newDisjunction().toString()); assertEquals("foo", newDisjunction("foo").toString()); assertEquals("foo or bar", newDisjunction("foo", "bar").toString()); @@ -88,22 +85,22 @@ public class DisjunctionTest { } @Test - public void requireThatSimpleDisjunctionsArePrettyPrinted() { + void requireThatSimpleDisjunctionsArePrettyPrinted() { assertEquals("foo or bar", - new Disjunction(SimplePredicates.newString("foo"), - SimplePredicates.newString("bar")).toString()); + new Disjunction(SimplePredicates.newString("foo"), + SimplePredicates.newString("bar")).toString()); } @Test - public void requireThatComplexDisjunctionsArePrintedAsGroup() { + void requireThatComplexDisjunctionsArePrintedAsGroup() { assertEquals("foo or bar or baz", - new Disjunction(SimplePredicates.newString("foo"), - new Disjunction(SimplePredicates.newString("bar"), - SimplePredicates.newString("baz"))).toString()); + new Disjunction(SimplePredicates.newString("foo"), + new Disjunction(SimplePredicates.newString("bar"), + SimplePredicates.newString("baz"))).toString()); assertEquals("foo or (bar and baz)", - new Disjunction(SimplePredicates.newString("foo"), - new Conjunction(SimplePredicates.newString("bar"), - SimplePredicates.newString("baz"))).toString()); + new Disjunction(SimplePredicates.newString("foo"), + new Conjunction(SimplePredicates.newString("bar"), + SimplePredicates.newString("baz"))).toString()); } private static Disjunction newDisjunction(String... operands) { diff --git a/predicate-search-core/src/test/java/com/yahoo/document/predicate/FeatureConjunctionTest.java b/predicate-search-core/src/test/java/com/yahoo/document/predicate/FeatureConjunctionTest.java index 059022f87e8..e44fd0e0a78 100644 --- a/predicate-search-core/src/test/java/com/yahoo/document/predicate/FeatureConjunctionTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/document/predicate/FeatureConjunctionTest.java @@ -1,13 +1,14 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collections; import static com.yahoo.document.predicate.Predicates.feature; import static com.yahoo.document.predicate.Predicates.not; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * @author bjorncs @@ -15,38 +16,48 @@ import static com.yahoo.document.predicate.Predicates.not; public class FeatureConjunctionTest { @Test - public void require_that_featureconjunction_with_valid_operands_can_be_constructed() { + void require_that_featureconjunction_with_valid_operands_can_be_constructed() { new FeatureConjunction(Arrays.asList( not(feature("a").inSet("1")), feature("b").inSet("1"))); } - @Test(expected = IllegalArgumentException.class) - public void require_that_constructor_throws_exception_if_all_operands_are_not_featuresets() { - new FeatureConjunction(Arrays.asList( - not(feature("a").inSet("1")), - feature("b").inRange(1, 2))); + @Test + void require_that_constructor_throws_exception_if_all_operands_are_not_featuresets() { + assertThrows(IllegalArgumentException.class, () -> { + new FeatureConjunction(Arrays.asList( + not(feature("a").inSet("1")), + feature("b").inRange(1, 2))); + }); } - @Test(expected = IllegalArgumentException.class) - public void require_that_constructor_throws_exception_if_single_operand() { - new FeatureConjunction(Arrays.asList(feature("a").inSet("1"))); + @Test + void require_that_constructor_throws_exception_if_single_operand() { + assertThrows(IllegalArgumentException.class, () -> { + new FeatureConjunction(Arrays.asList(feature("a").inSet("1"))); + }); } - @Test(expected = IllegalArgumentException.class) - public void require_that_constructor_throws_exception_if_no_operands() { - new FeatureConjunction(Collections.emptyList()); + @Test + void require_that_constructor_throws_exception_if_no_operands() { + assertThrows(IllegalArgumentException.class, () -> { + new FeatureConjunction(Collections.emptyList()); + }); } - @Test(expected = IllegalArgumentException.class) - public void require_that_contructor_throws_exception_if_featuresets_contain_multiple_values() { - new FeatureConjunction(Arrays.asList(feature("a").inSet("1"), feature("b").inSet("2", "3"))); + @Test + void require_that_contructor_throws_exception_if_featuresets_contain_multiple_values() { + assertThrows(IllegalArgumentException.class, () -> { + new FeatureConjunction(Arrays.asList(feature("a").inSet("1"), feature("b").inSet("2", "3"))); + }); } - @Test(expected = IllegalArgumentException.class) - public void require_that_constructor_throws_exception_if_featureset_keys_are_not_unique() { - new FeatureConjunction(Arrays.asList( - not(feature("a").inSet("1")), - feature("a").inSet("2"))); + @Test + void require_that_constructor_throws_exception_if_featureset_keys_are_not_unique() { + assertThrows(IllegalArgumentException.class, () -> { + new FeatureConjunction(Arrays.asList( + not(feature("a").inSet("1")), + feature("a").inSet("2"))); + }); } } diff --git a/predicate-search-core/src/test/java/com/yahoo/document/predicate/FeatureRangeTest.java b/predicate-search-core/src/test/java/com/yahoo/document/predicate/FeatureRangeTest.java index 0951ae3bbc6..8d31765cf1b 100644 --- a/predicate-search-core/src/test/java/com/yahoo/document/predicate/FeatureRangeTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/document/predicate/FeatureRangeTest.java @@ -1,11 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * @author Simon Thoresen Hult @@ -13,12 +13,12 @@ import static org.junit.Assert.*; public class FeatureRangeTest { @Test - public void requireThatFeatureRangeIsAValue() { + void requireThatFeatureRangeIsAValue() { assertTrue(PredicateValue.class.isAssignableFrom(FeatureRange.class)); } @Test - public void requireThatAccessorsWork() { + void requireThatAccessorsWork() { FeatureRange node = new FeatureRange("foo"); assertEquals("foo", node.getKey()); node.setKey("bar"); @@ -36,7 +36,7 @@ public class FeatureRangeTest { } @Test - public void requireThatConstructorsWork() { + void requireThatConstructorsWork() { FeatureRange node = new FeatureRange("foo"); assertEquals("foo", node.getKey()); assertNull(node.getFromInclusive()); @@ -64,7 +64,7 @@ public class FeatureRangeTest { } @Test - public void requireThatCloneIsImplemented() throws CloneNotSupportedException { + void requireThatCloneIsImplemented() throws CloneNotSupportedException { FeatureRange node1 = new FeatureRange("foo", 6L, 9L); FeatureRange node2 = node1.clone(); assertEquals(node1, node2); @@ -72,36 +72,36 @@ public class FeatureRangeTest { } @Test - public void requireThatHashCodeIsImplemented() { + void requireThatHashCodeIsImplemented() { assertEquals(new FeatureRange("key").hashCode(), new FeatureRange("key").hashCode()); } @Test - public void requireThatEqualsIsImplemented() { + void requireThatEqualsIsImplemented() { FeatureRange lhs = new FeatureRange("foo", 6L, 9L); - assertTrue(lhs.equals(lhs)); - assertFalse(lhs.equals(new Object())); + assertEquals(lhs, lhs); + assertNotEquals(lhs, new Object()); FeatureRange rhs = new FeatureRange("bar"); - assertFalse(lhs.equals(rhs)); + assertNotEquals(lhs, rhs); rhs.setKey("foo"); - assertFalse(lhs.equals(rhs)); + assertNotEquals(lhs, rhs); rhs.setFromInclusive(6L); - assertFalse(lhs.equals(rhs)); + assertNotEquals(lhs, rhs); rhs.setToInclusive(9L); - assertTrue(lhs.equals(rhs)); + assertEquals(lhs, rhs); rhs.addPartition(new RangePartition("foo")); - assertFalse(lhs.equals(rhs)); + assertNotEquals(lhs, rhs); lhs.addPartition(new RangePartition("foo")); - assertTrue(lhs.equals(rhs)); + assertEquals(lhs, rhs); rhs.addPartition(new RangeEdgePartition("foo", 10, 0, 2)); - assertFalse(lhs.equals(rhs)); + assertNotEquals(lhs, rhs); lhs.addPartition(new RangeEdgePartition("foo", 10, 0, 2)); - assertTrue(lhs.equals(rhs)); + assertEquals(lhs, rhs); } @Test - public void requireThatFeatureKeyIsMandatoryInConstructor() { + void requireThatFeatureKeyIsMandatoryInConstructor() { try { new FeatureRange(null); fail(); @@ -111,7 +111,7 @@ public class FeatureRangeTest { } @Test - public void requireThatFeatureKeyIsMandatoryInSetter() { + void requireThatFeatureKeyIsMandatoryInSetter() { FeatureRange node = new FeatureRange("foo"); try { node.setKey(null); @@ -123,7 +123,7 @@ public class FeatureRangeTest { } @Test - public void requireThatRangeCanBeSingleValue() { + void requireThatRangeCanBeSingleValue() { FeatureRange node = new FeatureRange("key", 6L, 6L); assertEquals(6, node.getFromInclusive().intValue()); assertEquals(6, node.getToInclusive().intValue()); @@ -134,7 +134,7 @@ public class FeatureRangeTest { } @Test - public void requireThatFromCanNotBeConstructedGreaterThanTo() { + void requireThatFromCanNotBeConstructedGreaterThanTo() { try { new FeatureRange("key", 9L, 6L); fail(); @@ -144,7 +144,7 @@ public class FeatureRangeTest { } @Test - public void requireThatFromCanNotBeSetGreaterThanTo() { + void requireThatFromCanNotBeSetGreaterThanTo() { FeatureRange node = new FeatureRange("key", null, 6L); try { node.setFromInclusive(9L); @@ -165,7 +165,7 @@ public class FeatureRangeTest { } @Test - public void requireThatToCanNotBeSetLessThanFrom() { + void requireThatToCanNotBeSetLessThanFrom() { FeatureRange node = new FeatureRange("key", 9L, null); try { node.setToInclusive(6L); @@ -186,49 +186,49 @@ public class FeatureRangeTest { } @Test - public void requireThatKeyIsEscapedInToString() { + void requireThatKeyIsEscapedInToString() { assertEquals("foo in [6..9]", - new FeatureRange("foo", 6L, 9L).toString()); + new FeatureRange("foo", 6L, 9L).toString()); assertEquals("'\\foo' in [6..9]", - new FeatureRange("\foo", 6L, 9L).toString()); + new FeatureRange("\foo", 6L, 9L).toString()); assertEquals("'\\x27foo\\x27' in [6..9]", - new FeatureRange("'foo'", 6L, 9L).toString()); + new FeatureRange("'foo'", 6L, 9L).toString()); } @Test - public void requireThatToStringIncludesLimits() { + void requireThatToStringIncludesLimits() { assertEquals("foo in [6..9]", new FeatureRange("foo", 6L, 9L).toString()); } @Test - public void requireThatToStringAllowsNullLimits() { + void requireThatToStringAllowsNullLimits() { assertEquals("foo in [..]", new FeatureRange("foo").toString()); } @Test - public void requireThatToStringAllowsNullFromLimit() { + void requireThatToStringAllowsNullFromLimit() { assertEquals("foo in [..69]", new FeatureRange("foo", null, 69L).toString()); } @Test - public void requireThatToStringAllowsNullToLimit() { + void requireThatToStringAllowsNullToLimit() { assertEquals("foo in [69..]", new FeatureRange("foo", 69L, null).toString()); } @Test - public void requireThatSimpleStringsArePrettyPrinted() { + void requireThatSimpleStringsArePrettyPrinted() { assertEquals("foo in [6..9]", - new FeatureRange("foo", 6L, 9L).toString()); + new FeatureRange("foo", 6L, 9L).toString()); } @Test - public void requireThatComplexStringsAreEscaped() { + void requireThatComplexStringsAreEscaped() { assertEquals("'\\foo' in [6..9]", - new FeatureRange("\foo", 6L, 9L).toString()); + new FeatureRange("\foo", 6L, 9L).toString()); } @Test - public void requireThatRangePartitionsCanBeAdded() { + void requireThatRangePartitionsCanBeAdded() { FeatureRange range = new FeatureRange("foo", 10L, 22L); range.addPartition(new RangePartition("foo=10-19")); range.addPartition(new RangePartition("foo", 0, 0x8000000000000000L, true)); @@ -237,7 +237,7 @@ public class FeatureRangeTest { } @Test - public void requireThatRangePartitionsCanBeCleared() { + void requireThatRangePartitionsCanBeCleared() { FeatureRange range = new FeatureRange("foo", 10L, 22L); range.addPartition(new RangePartition("foo=10-19")); range.addPartition(new RangeEdgePartition("foo=20", 20, 0, 2)); @@ -247,7 +247,7 @@ public class FeatureRangeTest { } @Test - public void requireThatFeatureRangeCanBeBuiltFromMixedInNode() { + void requireThatFeatureRangeCanBeBuiltFromMixedInNode() { assertEquals(new FeatureRange("foo", 10L, 19L), FeatureRange.buildFromMixedIn("foo", Arrays.asList("foo=10-19"), 10)); assertEquals(new FeatureRange("foo", -19L, -10L), diff --git a/predicate-search-core/src/test/java/com/yahoo/document/predicate/FeatureSetTest.java b/predicate-search-core/src/test/java/com/yahoo/document/predicate/FeatureSetTest.java index e0ed8da13c8..7068538a1e0 100644 --- a/predicate-search-core/src/test/java/com/yahoo/document/predicate/FeatureSetTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/document/predicate/FeatureSetTest.java @@ -1,7 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Arrays; @@ -9,12 +9,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; /** * @author Simon Thoresen Hult @@ -22,12 +17,12 @@ import static org.junit.Assert.fail; public class FeatureSetTest { @Test - public void requireThatFeatureSetIsAValue() { + void requireThatFeatureSetIsAValue() { assertTrue(PredicateValue.class.isAssignableFrom(FeatureSet.class)); } @Test - public void requireThatAccessorsWork() { + void requireThatAccessorsWork() { FeatureSet node = new FeatureSet("key", "valueA", "valueB"); assertEquals("key", node.getKey()); assertValues(Arrays.asList("valueA", "valueB"), node); @@ -40,7 +35,7 @@ public class FeatureSetTest { } @Test - public void requireThatValueSetIsMutable() { + void requireThatValueSetIsMutable() { FeatureSet node = new FeatureSet("key"); node.getValues().add("valueA"); assertValues(Arrays.asList("valueA"), node); @@ -51,7 +46,7 @@ public class FeatureSetTest { } @Test - public void requireThatConstructorsWork() { + void requireThatConstructorsWork() { FeatureSet node = new FeatureSet("key", "valueA", "valueB"); assertEquals("key", node.getKey()); assertValues(Arrays.asList("valueA", "valueB"), node); @@ -62,7 +57,7 @@ public class FeatureSetTest { } @Test - public void requireThatCloneIsImplemented() throws CloneNotSupportedException { + void requireThatCloneIsImplemented() throws CloneNotSupportedException { FeatureSet node1 = new FeatureSet("key", "valueA", "valueB"); FeatureSet node2 = node1.clone(); assertEquals(node1, node2); @@ -71,28 +66,28 @@ public class FeatureSetTest { } @Test - public void requireThatHashCodeIsImplemented() { + void requireThatHashCodeIsImplemented() { assertEquals(new FeatureSet("key").hashCode(), new FeatureSet("key").hashCode()); } @Test - public void requireThatEqualsIsImplemented() { + void requireThatEqualsIsImplemented() { FeatureSet lhs = new FeatureSet("keyA", "valueA", "valueB"); - assertTrue(lhs.equals(lhs)); - assertFalse(lhs.equals(new Object())); + assertEquals(lhs, lhs); + assertNotEquals(lhs, new Object()); FeatureSet rhs = new FeatureSet("keyB"); - assertFalse(lhs.equals(rhs)); + assertNotEquals(lhs, rhs); rhs.setKey("keyA"); - assertFalse(lhs.equals(rhs)); + assertNotEquals(lhs, rhs); rhs.addValue("valueA"); - assertFalse(lhs.equals(rhs)); + assertNotEquals(lhs, rhs); rhs.addValue("valueB"); - assertTrue(lhs.equals(rhs)); + assertEquals(lhs, rhs); } @Test - public void requireThatkeyIsMandatoryInConstructor() { + void requireThatkeyIsMandatoryInConstructor() { try { new FeatureSet(null); fail(); @@ -108,7 +103,7 @@ public class FeatureSetTest { } @Test - public void requireThatkeyIsMandatoryInSetter() { + void requireThatkeyIsMandatoryInSetter() { FeatureSet node = new FeatureSet("foo"); try { node.setKey(null); @@ -120,7 +115,7 @@ public class FeatureSetTest { } @Test - public void requireThatValueIsMandatoryInSetter() { + void requireThatValueIsMandatoryInSetter() { FeatureSet node = new FeatureSet("foo", "bar"); try { node.addValue(null); @@ -132,49 +127,49 @@ public class FeatureSetTest { } @Test - public void requireThatKeyIsEscapedInToString() { + void requireThatKeyIsEscapedInToString() { assertEquals("foo in [val]", - new FeatureSet("foo", "val").toString()); + new FeatureSet("foo", "val").toString()); assertEquals("'\\foo' in [val]", - new FeatureSet("\foo", "val").toString()); + new FeatureSet("\foo", "val").toString()); assertEquals("'\\x27foo\\x27' in [val]", - new FeatureSet("'foo'", "val").toString()); + new FeatureSet("'foo'", "val").toString()); } @Test - public void requireThatValuesAreEscapedInToString() { + void requireThatValuesAreEscapedInToString() { assertEquals("key in [bar, foo]", - new FeatureSet("key", "foo", "bar").toString()); + new FeatureSet("key", "foo", "bar").toString()); assertEquals("key in ['\\foo', 'ba\\r']", - new FeatureSet("key", "\foo", "ba\r").toString()); + new FeatureSet("key", "\foo", "ba\r").toString()); assertEquals("key in ['\\x27bar\\x27', '\\x27foo\\x27']", - new FeatureSet("key", "'foo'", "'bar'").toString()); + new FeatureSet("key", "'foo'", "'bar'").toString()); } @Test - public void requireThatSimpleStringsArePrettyPrinted() { + void requireThatSimpleStringsArePrettyPrinted() { assertEquals("foo in [bar]", - new FeatureSet("foo", "bar").toString()); + new FeatureSet("foo", "bar").toString()); } @Test - public void requireThatComplexStringsAreEscaped() { + void requireThatComplexStringsAreEscaped() { assertEquals("'\\foo' in ['ba\\r']", - new FeatureSet("\foo", "ba\r").toString()); + new FeatureSet("\foo", "ba\r").toString()); } @Test - public void requireThatNegatedFeatureSetsArePrettyPrinted() { + void requireThatNegatedFeatureSetsArePrettyPrinted() { assertEquals("country not in [no, se]", - new Negation(new FeatureSet("country", "no", "se")).toString()); + new Negation(new FeatureSet("country", "no", "se")).toString()); } private static void assertValues(Collection expected, FeatureSet actual) { List tmp = new ArrayList<>(expected); for (String value : actual.getValues()) { - assertNotNull(value, tmp.remove(value)); + assertNotNull(tmp.remove(value), value); } - assertTrue(tmp.toString(), tmp.isEmpty()); + assertTrue(tmp.isEmpty(), tmp.toString()); } } diff --git a/predicate-search-core/src/test/java/com/yahoo/document/predicate/NegationTest.java b/predicate-search-core/src/test/java/com/yahoo/document/predicate/NegationTest.java index 904dce795c3..2a86727c81a 100644 --- a/predicate-search-core/src/test/java/com/yahoo/document/predicate/NegationTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/document/predicate/NegationTest.java @@ -1,14 +1,9 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; /** * @author Simon Thoresen Hult @@ -16,12 +11,12 @@ import static org.junit.Assert.fail; public class NegationTest { @Test - public void requireThatNegationIsAnOperator() { + void requireThatNegationIsAnOperator() { assertTrue(PredicateOperator.class.isAssignableFrom(Negation.class)); } @Test - public void requireThatAccessorsWork() { + void requireThatAccessorsWork() { Predicate foo = SimplePredicates.newString("foo"); Negation node = new Negation(foo); assertSame(foo, node.getOperand()); @@ -32,7 +27,7 @@ public class NegationTest { } @Test - public void requireThatCloneIsImplemented() throws CloneNotSupportedException { + void requireThatCloneIsImplemented() throws CloneNotSupportedException { Negation node1 = new Negation(SimplePredicates.newString("a")); Negation node2 = node1.clone(); assertEquals(node1, node2); @@ -41,25 +36,25 @@ public class NegationTest { } @Test - public void requireThatHashCodeIsImplemented() { + void requireThatHashCodeIsImplemented() { Predicate predicate = SimplePredicates.newPredicate(); assertEquals(new Negation(predicate).hashCode(), new Negation(predicate).hashCode()); } @Test - public void requireThatEqualsIsImplemented() { + void requireThatEqualsIsImplemented() { Negation lhs = new Negation(SimplePredicates.newString("foo")); - assertTrue(lhs.equals(lhs)); - assertFalse(lhs.equals(new Object())); + assertEquals(lhs, lhs); + assertNotEquals(lhs, new Object()); Negation rhs = new Negation(SimplePredicates.newString("bar")); - assertFalse(lhs.equals(rhs)); + assertNotEquals(lhs, rhs); rhs.setOperand(SimplePredicates.newString("foo")); - assertTrue(lhs.equals(rhs)); + assertEquals(lhs, rhs); } @Test - public void requireThatChildIsMandatoryInConstructor() { + void requireThatChildIsMandatoryInConstructor() { try { new Negation(null); fail(); @@ -69,7 +64,7 @@ public class NegationTest { } @Test - public void requireThatChildIsMandatoryInSetter() { + void requireThatChildIsMandatoryInSetter() { Predicate operand = SimplePredicates.newPredicate(); Negation negation = new Negation(operand); try { @@ -82,7 +77,7 @@ public class NegationTest { } @Test - public void requireThatChildIsIncludedInToString() { + void requireThatChildIsIncludedInToString() { assertEquals("not (foo)", new Negation(SimplePredicates.newString("foo")).toString()); } diff --git a/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateHashTest.java b/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateHashTest.java index 7b1b6886aa0..2db73aff6fe 100644 --- a/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateHashTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateHashTest.java @@ -1,16 +1,16 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Magnar Nedland */ public class PredicateHashTest{ @Test - public void requireThatShortStringsGetsHashes() { + void requireThatShortStringsGetsHashes() { assertHashesTo(0x82af3d1de65ec252L, "abcdefg"); assertHashesTo(0xdc50d922fb0e91d6L, "雅虎"); assertHashesTo(0x709bd6ff1a84dc14L, "country=日本"); @@ -44,7 +44,7 @@ public class PredicateHashTest{ } @Test - public void requireThatLongStringsGetsHashes() { + void requireThatLongStringsGetsHashes() { assertHashesTo(0x79fac97d13f4cc84L, "abcdefghijklmn1234567890"); assertHashesTo(0xd7af1798f1d5de44L, "abcdefghijklmn1234567890a"); assertHashesTo(0x5a259ad887478cccL, "abcdefghijklmn1234567890ab"); diff --git a/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateOperatorTest.java b/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateOperatorTest.java index 2bcc62b76e0..d1e36c2b117 100644 --- a/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateOperatorTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateOperatorTest.java @@ -1,9 +1,9 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Simon Thoresen Hult @@ -11,7 +11,7 @@ import static org.junit.Assert.assertTrue; public class PredicateOperatorTest { @Test - public void requireThatOperatorIsAPredicate() { + void requireThatOperatorIsAPredicate() { assertTrue(Predicate.class.isAssignableFrom(PredicateOperator.class)); } } diff --git a/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateParserTest.java b/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateParserTest.java index b4b45ab198e..96c774fe8ed 100644 --- a/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateParserTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateParserTest.java @@ -1,11 +1,9 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; /** * @author Magnar Nedland @@ -14,7 +12,7 @@ import static org.junit.Assert.fail; public class PredicateParserTest { @Test - public void requireThatParseErrorThrowsException() { + void requireThatParseErrorThrowsException() { try { Predicate.fromString("a in b"); fail("Expected an exception"); @@ -24,7 +22,7 @@ public class PredicateParserTest { } @Test - public void requireThatLexerErrorThrowsException() { + void requireThatLexerErrorThrowsException() { try { Predicate.fromString("a-b in [b]"); fail("Expected an exception"); @@ -34,7 +32,7 @@ public class PredicateParserTest { } @Test - public void requireThatSingleValueLeafNodesParse() { + void requireThatSingleValueLeafNodesParse() { assertParsesTo("a in [b]", "a in [b]"); assertParsesTo("0 in [1]", "0 in [1]"); assertParsesTo("in in [in]", "in in [in]"); @@ -44,17 +42,17 @@ public class PredicateParserTest { assertParsesTo("string in ['!@#$%^&*()[]']", "'string' in ['!@#$%^&*()[]']"); assertParsesTo("a in [b]", "a in [b]"); assertParsesTo("string in ['foo\\\\_\"\\t\\n\\f\\rbar']", - "string in ['foo\\\\_\\x22\\t\\n\\f\\rbar']"); + "string in ['foo\\\\_\\x22\\t\\n\\f\\rbar']"); assertParsesTo("'\\xC3\\xB8' in [b]", "'ø' in [b]"); assertParsesTo("'\\xEF\\xBF\\xBD' in [b]", "'\\xf8' in [b]"); assertParsesTo("'\\xEF\\xBF\\xBD' in [b]", "'\\xef\\xbf\\xbd' in ['b']"); assertParsesTo("'\\xE4\\xB8\\x9C\\xE8\\xA5\\xBF' in ['\\xE8\\x87\\xAA\\xE8\\xA1\\x8C\\xE8\\xBD\\xA6']", - "'东西' in ['自行车']"); + "'东西' in ['自行车']"); assertParsesTo("true in [false]", "true in [false]"); } @Test - public void requireThatMultiValueLeafNodesParse() { + void requireThatMultiValueLeafNodesParse() { assertParsesTo("a in [b]", "a in [b]"); assertParsesTo("0 in [1]", "0 in [1]"); assertParsesTo("in in [and, in]", "in in [in, and]"); @@ -62,7 +60,7 @@ public class PredicateParserTest { } @Test - public void requireThatBothSingleAndDoubleQuotesWork() { + void requireThatBothSingleAndDoubleQuotesWork() { assertParsesTo("a in [b]", "'a' in ['b']"); assertParsesTo("a in [b]", "\"a\" in [\"b\"]"); assertParsesTo("'a\\x27' in [b]", "'a\\'' in ['b']"); @@ -70,7 +68,7 @@ public class PredicateParserTest { } @Test - public void requireThatRangeLeafNodesParse() { + void requireThatRangeLeafNodesParse() { assertParsesTo("a in [0..100]", "a in [0..100]"); assertParsesTo("0 in [..100]", "0 in [..100]"); assertParsesTo("0 in [0..]", "0 in [0..]"); @@ -81,7 +79,7 @@ public class PredicateParserTest { } @Test - public void requireThatRangePartitionsAreIgnored() { + void requireThatRangePartitionsAreIgnored() { assertParsesTo("a in [0..100]", "a in [0..100 (a=0-99,a=100+[..0])]"); assertParsesTo("a in [-100..0]", "a in [-100..0 (a=-0-99,a=-100+[..0])]"); assertParsesTo("a in [-9223372036854775808..0]", "a in [-9223372036854775808..0 (a=-0-9223372036854775808)]"); @@ -91,57 +89,57 @@ public class PredicateParserTest { } @Test - public void requireThatNotInSetWorks() { + void requireThatNotInSetWorks() { assertParsesTo("a not in [b]", "a not in [b]"); } @Test - public void requireThatConjunctionWorks() { + void requireThatConjunctionWorks() { assertParsesTo("a in [b] and c in [d]", "a in [b] and c in [d]"); assertParsesTo("a in [b] and c in [d] and e in [f]", "a in [b] and c in [d] and e in [f]"); } @Test - public void requireThatDisjunctionWorks() { + void requireThatDisjunctionWorks() { assertParsesTo("a in [b] or c in [d]", "a in [b] or c in [d]"); assertParsesTo("a in [b] or c in [d] or e in [f]", "a in [b] or c in [d] or e in [f]"); } @Test - public void requireThatParenthesesWorks() { + void requireThatParenthesesWorks() { assertParsesTo("a in [b] or c in [d]", - "(a in [b]) or (c in [d])"); + "(a in [b]) or (c in [d])"); assertParsesTo("a in [b] or c in [d] or e in [f]", - "(((a in [b]) or c in [d]) or e in [f])"); + "(((a in [b]) or c in [d]) or e in [f])"); assertParsesTo("(a in [b] and c in [d]) or e in [f]", - "a in [b] and c in [d] or e in [f]"); + "a in [b] and c in [d] or e in [f]"); assertParsesTo("a in [b] and (c in [d] or e in [f])", - "a in [b] and (c in [d] or e in [f])"); + "a in [b] and (c in [d] or e in [f])"); assertParsesTo("a in [b] and (c in [d] or e in [f]) and g in [h]", - "a in [b] and (c in [d] or e in [f]) and g in [h]"); + "a in [b] and (c in [d] or e in [f]) and g in [h]"); } @Test - public void requireThatNotOutsideParenthesesWorks() { + void requireThatNotOutsideParenthesesWorks() { assertParsesTo("a not in [b]", "not (a in [b])"); } @Test - public void requireThatConjunctionsCanGetMoreThanTwoChildren() { + void requireThatConjunctionsCanGetMoreThanTwoChildren() { Predicate p = Predicate.fromString("a in [b] and c in [d] and e in [f] and g in [h]"); assertTrue(p instanceof Conjunction); - assertEquals(4, ((Conjunction)p).getOperands().size()); + assertEquals(4, ((Conjunction) p).getOperands().size()); } @Test - public void requireThatDisjunctionsCanGetMoreThanTwoChildren() { + void requireThatDisjunctionsCanGetMoreThanTwoChildren() { Predicate p = Predicate.fromString("a in [b] or c in [d] or e in [f] or g in [h]"); assertTrue(p instanceof Disjunction); - assertEquals(4, ((Disjunction)p).getOperands().size()); + assertEquals(4, ((Disjunction) p).getOperands().size()); } @Test - public void requireThatBooleanCanBeParsed() { + void requireThatBooleanCanBeParsed() { assertParsesTo("true", "true"); assertParsesTo("false", "false"); assertParsesTo("true or false", "true or false"); diff --git a/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateTest.java b/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateTest.java index 10de465f342..544403f6c9f 100644 --- a/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateTest.java @@ -1,14 +1,14 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static com.yahoo.document.predicate.Predicates.and; import static com.yahoo.document.predicate.Predicates.feature; import static com.yahoo.document.predicate.Predicates.not; import static com.yahoo.document.predicate.Predicates.or; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Simon Thoresen Hult @@ -16,12 +16,12 @@ import static org.junit.Assert.assertTrue; public class PredicateTest { @Test - public void requireThatPredicateIsCloneable() { + void requireThatPredicateIsCloneable() { assertTrue(Cloneable.class.isAssignableFrom(Predicate.class)); } @Test - public void requireThatANDConstructsAConjunction() { + void requireThatANDConstructsAConjunction() { Predicate foo = SimplePredicates.newString("foo"); Predicate bar = SimplePredicates.newString("bar"); Predicate predicate = and(foo, bar); @@ -30,7 +30,7 @@ public class PredicateTest { } @Test - public void requireThatORConstructsADisjunction() { + void requireThatORConstructsADisjunction() { Predicate foo = SimplePredicates.newString("foo"); Predicate bar = SimplePredicates.newString("bar"); Predicate predicate = or(foo, bar); @@ -39,7 +39,7 @@ public class PredicateTest { } @Test - public void requireThatNOTConstructsANegation() { + void requireThatNOTConstructsANegation() { Predicate foo = SimplePredicates.newString("foo"); Predicate predicate = not(foo); assertEquals(Negation.class, predicate.getClass()); @@ -47,52 +47,52 @@ public class PredicateTest { } @Test - public void requireThatFeatureBuilderCanConstructFeatureRange() { + void requireThatFeatureBuilderCanConstructFeatureRange() { assertEquals(new FeatureRange("key", 6L, 9L), - feature("key").inRange(6, 9)); + feature("key").inRange(6, 9)); assertEquals(new Negation(new FeatureRange("key", 6L, 9L)), - feature("key").notInRange(6, 9)); + feature("key").notInRange(6, 9)); assertEquals(new FeatureRange("key", 7L, null), - feature("key").greaterThan(6)); + feature("key").greaterThan(6)); assertEquals(new FeatureRange("key", 6L, null), - feature("key").greaterThanOrEqualTo(6)); + feature("key").greaterThanOrEqualTo(6)); assertEquals(new FeatureRange("key", null, 5L), - feature("key").lessThan(6)); + feature("key").lessThan(6)); assertEquals(new FeatureRange("key", null, 9L), - feature("key").lessThanOrEqualTo(9)); + feature("key").lessThanOrEqualTo(9)); } @Test - public void requireThatFeatureBuilderCanConstructFeatureSet() { + void requireThatFeatureBuilderCanConstructFeatureSet() { assertEquals(new FeatureSet("key", "valueA", "valueB"), - feature("key").inSet("valueA", "valueB")); + feature("key").inSet("valueA", "valueB")); assertEquals(new Negation(new FeatureSet("key", "valueA", "valueB")), - feature("key").notInSet("valueA", "valueB")); + feature("key").notInSet("valueA", "valueB")); } @Test - public void requireThatPredicatesCanBeConstructedUsingConstructors() { + void requireThatPredicatesCanBeConstructedUsingConstructors() { assertEquals("country in [no, se] and age in [20..30]", - new Conjunction(new FeatureSet("country", "no", "se"), - new FeatureRange("age", 20L, 30L)).toString()); + new Conjunction(new FeatureSet("country", "no", "se"), + new FeatureRange("age", 20L, 30L)).toString()); assertEquals("country not in [no, se] or age in [20..] or height in [..160]", - new Disjunction(new Negation(new FeatureSet("country", "no", "se")), - new FeatureRange("age", 20L, null), - new FeatureRange("height", null, 160L)).toString()); + new Disjunction(new Negation(new FeatureSet("country", "no", "se")), + new FeatureRange("age", 20L, null), + new FeatureRange("height", null, 160L)).toString()); } @Test - public void requireThatPredicatesCanBeBuiltUsingChainedMethodCalls() { + void requireThatPredicatesCanBeBuiltUsingChainedMethodCalls() { assertEquals("country not in [no, se] or age in [20..] or height in [..160]", - new Disjunction() - .addOperand(new Negation(new FeatureSet("country").addValue("no").addValue("se"))) - .addOperand(new FeatureRange("age").setFromInclusive(20L)) - .addOperand(new FeatureRange("height").setToInclusive(160L)) - .toString()); + new Disjunction() + .addOperand(new Negation(new FeatureSet("country").addValue("no").addValue("se"))) + .addOperand(new FeatureRange("age").setFromInclusive(20L)) + .addOperand(new FeatureRange("height").setToInclusive(160L)) + .toString()); } @Test - public void requireThatPredicatesCanBeBuiltUsingSeparateMethodCalls() { + void requireThatPredicatesCanBeBuiltUsingSeparateMethodCalls() { Conjunction conjunction = new Conjunction(); FeatureSet countrySet = new FeatureSet("country"); countrySet.addValue("no"); @@ -105,6 +105,6 @@ public class PredicateTest { heightRange.setToInclusive(160L); conjunction.addOperand(heightRange); assertEquals("country in [no, se] and age in [20..] and height in [..160]", - conjunction.toString()); + conjunction.toString()); } } diff --git a/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateValueTest.java b/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateValueTest.java index fe5f6db1cfa..c32a36f153b 100644 --- a/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateValueTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicateValueTest.java @@ -1,9 +1,9 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Simon Thoresen Hult @@ -11,7 +11,7 @@ import static org.junit.Assert.assertTrue; public class PredicateValueTest { @Test - public void requireThatValueIsAPredicate() { + void requireThatValueIsAPredicate() { assertTrue(Predicate.class.isAssignableFrom(PredicateValue.class)); } } diff --git a/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicatesTest.java b/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicatesTest.java index c8cd3f776c8..a40e577fae5 100644 --- a/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicatesTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicatesTest.java @@ -1,14 +1,14 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static com.yahoo.document.predicate.Predicates.and; import static com.yahoo.document.predicate.Predicates.feature; import static com.yahoo.document.predicate.Predicates.not; import static com.yahoo.document.predicate.Predicates.or; import static com.yahoo.document.predicate.Predicates.value; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Simon Thoresen Hult @@ -16,21 +16,21 @@ import static org.junit.Assert.assertEquals; public class PredicatesTest { @Test - public void requireThatApiIsUsable() { + void requireThatApiIsUsable() { assertEquals( new Disjunction( new Conjunction(new FeatureSet("country", "de", "no"), - new Negation(new FeatureSet("gender", "female")), - new FeatureRange("age", 6L, 9L)), + new Negation(new FeatureSet("gender", "female")), + new FeatureRange("age", 6L, 9L)), new Conjunction(new Negation(new FeatureSet("country", "se")), - new FeatureSet("gender", "female"), - new FeatureRange("age", 69L, null))), + new FeatureSet("gender", "female"), + new FeatureRange("age", 69L, null))), or(and(feature("country").inSet("de", "no"), - feature("gender").notInSet("female"), - feature("age").inRange(6, 9)), - and(not(feature("country").inSet("se")), - feature("gender").inSet("female"), - feature("age").greaterThanOrEqualTo(69)))); + feature("gender").notInSet("female"), + feature("age").inRange(6, 9)), + and(not(feature("country").inSet("se")), + feature("gender").inSet("female"), + feature("age").greaterThanOrEqualTo(69)))); assertEquals(new BooleanPredicate(true), value(true)); assertEquals(new BooleanPredicate(false), value(false)); diff --git a/predicate-search-core/src/test/java/com/yahoo/document/predicate/RangeEdgePartitionTest.java b/predicate-search-core/src/test/java/com/yahoo/document/predicate/RangeEdgePartitionTest.java index be01b1cd842..00a25e4dc49 100644 --- a/predicate-search-core/src/test/java/com/yahoo/document/predicate/RangeEdgePartitionTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/document/predicate/RangeEdgePartitionTest.java @@ -1,10 +1,9 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; /** * @author Magnar Nedland @@ -12,12 +11,12 @@ import static org.junit.Assert.assertEquals; public class RangeEdgePartitionTest { @Test - public void requireThatRangeEdgePartitionIsAValue() { + void requireThatRangeEdgePartitionIsAValue() { assertTrue(PredicateValue.class.isAssignableFrom(RangeEdgePartition.class)); } @Test - public void requireThatConstructorsWork() { + void requireThatConstructorsWork() { RangeEdgePartition part = new RangeEdgePartition("foo=10", 10, 0, -1); assertEquals("foo=10", part.getLabel()); assertEquals(0, part.getLowerBound()); @@ -25,7 +24,7 @@ public class RangeEdgePartitionTest { } @Test - public void requireThatCloneIsImplemented() throws CloneNotSupportedException { + void requireThatCloneIsImplemented() throws CloneNotSupportedException { RangeEdgePartition node1 = new RangeEdgePartition("foo=10", 10, 0, 0); RangeEdgePartition node2 = node1.clone(); assertEquals(node1, node2); @@ -33,29 +32,29 @@ public class RangeEdgePartitionTest { } @Test - public void requireThatHashCodeIsImplemented() { + void requireThatHashCodeIsImplemented() { assertEquals(new RangeEdgePartition("foo=-10", 10, 2, 3).hashCode(), new RangeEdgePartition("foo=-10", 10, 2, 3).hashCode()); } @Test - public void requireThatEqualsIsImplemented() { + void requireThatEqualsIsImplemented() { RangeEdgePartition lhs = new RangeEdgePartition("foo=10", 10, 5, 10); - assertTrue(lhs.equals(lhs)); - assertFalse(lhs.equals(new Object())); + assertEquals(lhs, lhs); + assertNotEquals(lhs, new Object()); RangeEdgePartition rhs = new RangeEdgePartition("foo=20", 20, 0, 0); - assertFalse(lhs.equals(rhs)); + assertNotEquals(lhs, rhs); rhs = new RangeEdgePartition("foo=10", 10, 5, 10); - assertTrue(lhs.equals(rhs)); - assertFalse(lhs.equals(new RangeEdgePartition("foo=10", 10, 5, 11))); - assertFalse(lhs.equals(new RangeEdgePartition("foo=10", 10, 6, 10))); - assertFalse(lhs.equals(new RangeEdgePartition("foo=10", 11, 5, 10))); - assertFalse(lhs.equals(new RangeEdgePartition("foo=11", 10, 5, 10))); + assertEquals(lhs, rhs); + assertNotEquals(lhs, new RangeEdgePartition("foo=10", 10, 5, 11)); + assertNotEquals(lhs, new RangeEdgePartition("foo=10", 10, 6, 10)); + assertNotEquals(lhs, new RangeEdgePartition("foo=10", 11, 5, 10)); + assertNotEquals(lhs, new RangeEdgePartition("foo=11", 10, 5, 10)); } @Test - public void requireThatKeyIsEscapedInToString() { + void requireThatKeyIsEscapedInToString() { assertEquals("foo=10+[2..3]", new RangeEdgePartition("foo=10", 10, 2, 3).toString()); assertEquals("'\\foo=10'+[2..3]", new RangeEdgePartition("\foo=10", 10, 2, 3).toString()); assertEquals("'\\x27foo\\x27=10'+[2..3]", new RangeEdgePartition("'foo'=10", 10, 2, 3).toString()); diff --git a/predicate-search-core/src/test/java/com/yahoo/document/predicate/RangePartitionTest.java b/predicate-search-core/src/test/java/com/yahoo/document/predicate/RangePartitionTest.java index c11a7fb433f..ea191c705a5 100644 --- a/predicate-search-core/src/test/java/com/yahoo/document/predicate/RangePartitionTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/document/predicate/RangePartitionTest.java @@ -1,10 +1,9 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; /** * @author Magnar Nedland @@ -12,12 +11,12 @@ import static org.junit.Assert.assertEquals; public class RangePartitionTest { @Test - public void requireThatRangePartitionIsAValue() { + void requireThatRangePartitionIsAValue() { assertTrue(PredicateValue.class.isAssignableFrom(RangePartition.class)); } @Test - public void requireThatConstructorsWork() { + void requireThatConstructorsWork() { RangePartition part = new RangePartition("foo=10-19"); assertEquals("foo=10-19", part.getLabel()); part = new RangePartition("foo", 10, 19, false); @@ -27,7 +26,7 @@ public class RangePartitionTest { } @Test - public void requireThatCloneIsImplemented() throws CloneNotSupportedException { + void requireThatCloneIsImplemented() throws CloneNotSupportedException { RangePartition node1 = new RangePartition("foo=300-399"); RangePartition node2 = node1.clone(); assertEquals(node1, node2); @@ -35,24 +34,24 @@ public class RangePartitionTest { } @Test - public void requireThatHashCodeIsImplemented() { + void requireThatHashCodeIsImplemented() { assertEquals(new RangePartition("foo=0-9").hashCode(), new RangePartition("foo=0-9").hashCode()); } @Test - public void requireThatEqualsIsImplemented() { + void requireThatEqualsIsImplemented() { RangePartition lhs = new RangePartition("foo=10-19"); - assertTrue(lhs.equals(lhs)); - assertFalse(lhs.equals(new Object())); + assertEquals(lhs, lhs); + assertNotEquals(lhs, new Object()); RangePartition rhs = new RangePartition("bar=1000-1999"); - assertFalse(lhs.equals(rhs)); + assertNotEquals(lhs, rhs); rhs = new RangePartition("foo=10-19"); - assertTrue(lhs.equals(rhs)); + assertEquals(lhs, rhs); } @Test - public void requireThatKeyIsEscapedInToString() { + void requireThatKeyIsEscapedInToString() { assertEquals("foo=10-19", new RangePartition("foo=10-19").toString()); assertEquals("'\\foo=10-19'", new RangePartition("\foo=10-19").toString()); assertEquals("'\\x27foo\\x27=10-19'", new RangePartition("'foo'=10-19").toString()); diff --git a/predicate-search-core/src/test/java/com/yahoo/search/predicate/PredicateQueryParserTest.java b/predicate-search-core/src/test/java/com/yahoo/search/predicate/PredicateQueryParserTest.java index bd580ac232e..8e8a4f45562 100644 --- a/predicate-search-core/src/test/java/com/yahoo/search/predicate/PredicateQueryParserTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/search/predicate/PredicateQueryParserTest.java @@ -1,13 +1,13 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author bjorncs @@ -15,17 +15,17 @@ import static org.junit.Assert.assertEquals; public class PredicateQueryParserTest { @Test - public void require_that_json_is_correctly_parsed() { + void require_that_json_is_correctly_parsed() { String json = "{" + - " \"features\":[" + - " {\"k\":\"k1\",\"v\":\"value1\",\"s\":\"0x1\"}," + - " {\"k\":\"k2\",\"v\":\"value2\",\"s\":\"0x3\"}" + - " ],\"rangeFeatures\":[" + - " {\"k\":\"range1\",\"v\":123456789123,\"s\":\"0xffff\"}," + - " {\"k\":\"range2\",\"v\":0,\"s\":\"0xffffffffffffffff\"}" + - " ]" + - "}"; + " \"features\":[" + + " {\"k\":\"k1\",\"v\":\"value1\",\"s\":\"0x1\"}," + + " {\"k\":\"k2\",\"v\":\"value2\",\"s\":\"0x3\"}" + + " ],\"rangeFeatures\":[" + + " {\"k\":\"range1\",\"v\":123456789123,\"s\":\"0xffff\"}," + + " {\"k\":\"range2\",\"v\":0,\"s\":\"0xffffffffffffffff\"}" + + " ]" + + "}"; PredicateQueryParser parser = new PredicateQueryParser(); List result = new ArrayList<>(); diff --git a/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/AndOrSimplifierTest.java b/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/AndOrSimplifierTest.java index 2725132e68a..497c490b844 100644 --- a/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/AndOrSimplifierTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/AndOrSimplifierTest.java @@ -2,13 +2,13 @@ package com.yahoo.search.predicate.optimization; import com.yahoo.document.predicate.Predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static com.yahoo.document.predicate.Predicates.and; import static com.yahoo.document.predicate.Predicates.feature; import static com.yahoo.document.predicate.Predicates.not; import static com.yahoo.document.predicate.Predicates.or; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Magnar Nedland @@ -16,93 +16,93 @@ import static org.junit.Assert.assertEquals; public class AndOrSimplifierTest { @Test - public void requireThatNestedConjunctionsAreCollapsed() { + void requireThatNestedConjunctionsAreCollapsed() { assertSimplified(and(feature("a").inSet("b"), - feature("c").inSet("d")), - and(and(feature("a").inSet("b"), - feature("c").inSet("d")))); + feature("c").inSet("d")), + and(and(feature("a").inSet("b"), + feature("c").inSet("d")))); } @Test - public void requireThatNestedConjuctionsAreCollapsedInPlace() { + void requireThatNestedConjuctionsAreCollapsedInPlace() { assertSimplified(and(feature("a").inSet("b"), - feature("c").inSet("d"), - feature("e").inSet("f")), - and(feature("a").inSet("b"), - and(feature("c").inSet("d")), - feature("e").inSet("f"))); + feature("c").inSet("d"), + feature("e").inSet("f")), + and(feature("a").inSet("b"), + and(feature("c").inSet("d")), + feature("e").inSet("f"))); } @Test - public void requireThatDeeplyNestedConjunctionsAreCollapsed() { + void requireThatDeeplyNestedConjunctionsAreCollapsed() { assertSimplified(and(feature("a").inSet("b"), - feature("c").inSet("d"), - feature("e").inSet("f"), - feature("g").inSet("h"), - feature("i").inSet("j")), - and(feature("a").inSet("b"), - and(feature("c").inSet("d")), - feature("e").inSet("f"), - and(and(feature("g").inSet("h"), - feature("i").inSet("j"))))); + feature("c").inSet("d"), + feature("e").inSet("f"), + feature("g").inSet("h"), + feature("i").inSet("j")), + and(feature("a").inSet("b"), + and(feature("c").inSet("d")), + feature("e").inSet("f"), + and(and(feature("g").inSet("h"), + feature("i").inSet("j"))))); } @Test - public void requireThatNestedDisjunctionsAreCollapsed() { + void requireThatNestedDisjunctionsAreCollapsed() { assertSimplified(or(feature("a").inSet("b"), - feature("c").inSet("d")), - or(or(feature("a").inSet("b"), - feature("c").inSet("d")))); + feature("c").inSet("d")), + or(or(feature("a").inSet("b"), + feature("c").inSet("d")))); } @Test - public void requireThatNestedDisjuctionsAreCollapsedInPlace() { + void requireThatNestedDisjuctionsAreCollapsedInPlace() { assertSimplified(or(feature("a").inSet("b"), - feature("c").inSet("d"), - feature("e").inSet("f")), - or(feature("a").inSet("b"), - or(feature("c").inSet("d")), - feature("e").inSet("f"))); + feature("c").inSet("d"), + feature("e").inSet("f")), + or(feature("a").inSet("b"), + or(feature("c").inSet("d")), + feature("e").inSet("f"))); } @Test - public void requireThatDeeplyNestedDisjunctionsAreCollapsed() { + void requireThatDeeplyNestedDisjunctionsAreCollapsed() { assertSimplified(or(feature("a").inSet("b"), - feature("c").inSet("d"), - feature("e").inSet("f"), - feature("g").inSet("h"), - feature("i").inSet("j")), - or(feature("a").inSet("b"), - or(feature("c").inSet("d")), - feature("e").inSet("f"), - or(or(feature("g").inSet("h"), - feature("i").inSet("j"))))); + feature("c").inSet("d"), + feature("e").inSet("f"), + feature("g").inSet("h"), + feature("i").inSet("j")), + or(feature("a").inSet("b"), + or(feature("c").inSet("d")), + feature("e").inSet("f"), + or(or(feature("g").inSet("h"), + feature("i").inSet("j"))))); } @Test - public void requireThatConjunctionsAndDisjunctionsAreNotCollapsed() { + void requireThatConjunctionsAndDisjunctionsAreNotCollapsed() { assertSimplified(and(or(feature("a").inSet("b"), - feature("c").inSet("d"))), - and(or(feature("a").inSet("b"), - feature("c").inSet("d")))); + feature("c").inSet("d"))), + and(or(feature("a").inSet("b"), + feature("c").inSet("d")))); } @Test - public void requireThatNotOrIsTranslatedToAndNot() { + void requireThatNotOrIsTranslatedToAndNot() { assertSimplified( and(feature("a").notInSet("b"), feature("c").inSet("d")), not(or(feature("a").inSet("b"), feature("c").notInSet("d")))); } @Test - public void requireThatNotAndIsTranslatedToOrNot() { + void requireThatNotAndIsTranslatedToOrNot() { assertSimplified( or(feature("a").notInSet("b"), feature("c").inSet("d")), not(and(feature("a").inSet("b"), feature("c").notInSet("d")))); } @Test - public void requireThatTreeWithoutNotIsNotAffected() { + void requireThatTreeWithoutNotIsNotAffected() { assertSimplified( and(feature("a").inSet("b"), feature("c").notInSet("d")), and(feature("a").inSet("b"), feature("c").notInSet("d"))); @@ -113,14 +113,14 @@ public class AndOrSimplifierTest { } @Test - public void requireThatNotOfNotIsRemoved() { + void requireThatNotOfNotIsRemoved() { assertSimplified(feature("a").inSet("b"), not(not(feature("a").inSet("b")))); assertSimplified(feature("a").inSet("b"), not(feature("a").notInSet("b"))); assertSimplified(feature("a").notInSet("b"), not(not(feature("a").notInSet("b")))); } @Test - public void requireThatNotBeneathAndIsTranslated() { + void requireThatNotBeneathAndIsTranslated() { assertSimplified( and(feature("a").notInSet("b"), feature("c").inSet("d"), feature("b").inSet("c")), and(not(or(feature("a").inSet("b"), feature("c").notInSet("d"))), feature("b").inSet("c"))); diff --git a/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/BooleanSimplifierTest.java b/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/BooleanSimplifierTest.java index 54031d36b47..e03a01d3996 100644 --- a/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/BooleanSimplifierTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/BooleanSimplifierTest.java @@ -2,10 +2,10 @@ package com.yahoo.search.predicate.optimization; import com.yahoo.document.predicate.Predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static com.yahoo.document.predicate.Predicates.*; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Magnar Nedland @@ -13,32 +13,32 @@ import static org.junit.Assert.assertEquals; public class BooleanSimplifierTest { @Test - public void requireThatOrOfTrueIsTrue() { + void requireThatOrOfTrueIsTrue() { assertSimplifiedTo(value(true), or(feature("a").inSet("b"), value(true))); } @Test - public void requireThatFalseChildrenOfOrAreRemoved() { + void requireThatFalseChildrenOfOrAreRemoved() { assertSimplifiedTo(feature("a").inSet("b"), or(feature("a").inSet("b"), value(false))); } @Test - public void requireThatAndOfFalseIsFalse() { + void requireThatAndOfFalseIsFalse() { assertSimplifiedTo(value(false), and(feature("a").inSet("b"), value(false))); } @Test - public void requireThatTrueChildrenOfAndAreRemoved() { + void requireThatTrueChildrenOfAndAreRemoved() { assertSimplifiedTo(feature("a").inSet("b"), and(feature("a").inSet("b"), value(true))); } @Test - public void requireThatSingleChildAndOrAreRemoved() { + void requireThatSingleChildAndOrAreRemoved() { assertSimplifiedTo(feature("a").inSet("b"), and(or(and(feature("a").inSet("b"))))); } @Test - public void requireThatValueChildrenOfNotAreInverted() { + void requireThatValueChildrenOfNotAreInverted() { assertSimplifiedTo(value(true), not(value(false))); assertSimplifiedTo(value(false), not(value(true))); assertSimplifiedTo(value(true), not(not(not(value(false))))); @@ -46,7 +46,7 @@ public class BooleanSimplifierTest { } @Test - public void requireThatComplexExpressionIsSimplified() { + void requireThatComplexExpressionIsSimplified() { assertSimplifiedTo( Predicate.fromString("'pub_entity' not in [301951]"), Predicate.fromString("true and true and true and true and true and 'pub_entity' not in [301951] and ((true and true and true and true) or (true and true and true and true) or (true and true and true and true and 'pub_entity' in [86271]))")); diff --git a/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/ComplexNodeTransformerTest.java b/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/ComplexNodeTransformerTest.java index ac491d57ecd..596b28e8395 100644 --- a/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/ComplexNodeTransformerTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/ComplexNodeTransformerTest.java @@ -4,9 +4,9 @@ package com.yahoo.search.predicate.optimization; import com.yahoo.document.predicate.FeatureRange; import com.yahoo.document.predicate.Predicate; import com.yahoo.document.predicate.RangePartition; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Magnar Nedland @@ -29,7 +29,7 @@ public class ComplexNodeTransformerTest { } @Test - public void requireThatSingleValueRangesAreConverted() { + void requireThatSingleValueRangesAreConverted() { testConvert("foo in [0..0]", "foo in [0..0 (foo=0+[..0])]"); testConvert("foo in [5..5]", "foo in [5..5 (foo=0+[5..5])]"); testConvert("foo in [9..9]", "foo in [9..9 (foo=0+[9..])]"); @@ -40,7 +40,7 @@ public class ComplexNodeTransformerTest { } @Test - public void requireThatVeryShortRangesAreConverted() { + void requireThatVeryShortRangesAreConverted() { testConvert("foo in [10..17]", "foo in [10..17 (foo=10+[..7])]"); testConvert("foo in [12..19]", "foo in [12..19 (foo=10+[2..])]"); testConvert("foo in [11..18]", "foo in [11..18 (foo=10+[1..8])]"); @@ -53,7 +53,7 @@ public class ComplexNodeTransformerTest { } @Test - public void requireThatShortRangeIsConverted() { + void requireThatShortRangeIsConverted() { testConvert("foo in [9..19]", "foo in [9..19 (foo=0+[9..],foo=10-19)]"); testConvert("foo in [10..19]", "foo in [10..19 (foo=10-19)]"); testConvert("foo in [10..20]", "foo in [10..20 (foo=20+[..0],foo=10-19)]"); @@ -67,7 +67,7 @@ public class ComplexNodeTransformerTest { } @Test - public void requireThatMediumRangeIsConverted() { + void requireThatMediumRangeIsConverted() { testConvert("foo in [10..39]", "foo in [10..39 (foo=10-19,foo=20-29,foo=30-39)]"); testConvert("foo in [10..38]", "foo in [10..38 (foo=30+[..8],foo=10-19,foo=20-29)]"); testConvert("foo in [18..39]", "foo in [18..39 (foo=10+[8..],foo=20-29,foo=30-39)]"); @@ -80,7 +80,7 @@ public class ComplexNodeTransformerTest { } @Test - public void requireThatLargeRangeIsConverted() { + void requireThatLargeRangeIsConverted() { testConvert("foo in [10..199]", "foo in [10..199 (foo=10-19,foo=20-29,foo=30-39,foo=40-49,foo=50-59,foo=60-69,foo=70-79,foo=80-89,foo=90-99,foo=100-199)]"); testConvert("foo in [8..207]", "foo in [8..207 (foo=0+[8..],foo=200+[..7],foo=10-19,foo=20-29,foo=30-39,foo=40-49,foo=50-59,foo=60-69,foo=70-79,foo=80-89,foo=90-99,foo=100-199)]"); testConvert("foo in [999..2001]", "foo in [999..2001 (foo=990+[9..],foo=2000+[..1],foo=1000-1999)]"); @@ -94,7 +94,7 @@ public class ComplexNodeTransformerTest { } @Test - public void requireThatLongMaxIsConverted() { + void requireThatLongMaxIsConverted() { testConvert("foo in [0..9223372036854775807]", "foo in [0..9223372036854775807 (" + "foo=9223372036854775800+[..7]," + @@ -184,7 +184,7 @@ public class ComplexNodeTransformerTest { } @Test - public void requireThatLongMinIsConverted() { + void requireThatLongMinIsConverted() { testConvert("foo in [-9223372036854775808..-1]", "foo in [-9223372036854775808..-1 (" + "foo=-9223372036854775800+[..8]," + @@ -273,7 +273,7 @@ public class ComplexNodeTransformerTest { } @Test - public void requireThatLowAritiesWork() { + void requireThatLowAritiesWork() { testConvert("foo in [10..39]", "foo in [10..39 (foo=10-11,foo=12-15,foo=32-39,foo=16-31)]", 2); testConvert("foo in [2..32]", "foo in [2..32 (foo=32+[..0],foo=2-3,foo=4-7,foo=8-15,foo=16-31)]", 2); testConvert("foo in [-31..63]", "foo in [-31..63 (foo=-31-0,foo=0-63)]", 2); @@ -327,7 +327,7 @@ public class ComplexNodeTransformerTest { } @Test - public void requireThatHighAritiesWork() { + void requireThatHighAritiesWork() { testConvert("foo in [10..39]", "foo in [10..39 (foo=0+[10..39])]", 1000); testConvert("foo in [9000..11000]", "foo in [9000..11000 (foo=0+[9000..],foo=10000+[..1000])]", 10000); testConvert("foo in [10..39]", "foo in [10..39 (foo=0+[10..39])]", 16384); @@ -338,13 +338,13 @@ public class ComplexNodeTransformerTest { } @Test - public void requireThatOpenRangesWork() { + void requireThatOpenRangesWork() { testConvert("foo in [-7..]", "foo in [-7.. (foo=-7-0,foo=0-9223372036854775807)]", 2); testConvert("foo in [..7]", "foo in [..7 (foo=-9223372036854775808+[..0],foo=-9223372036854775807-0,foo=0-7)]", 2); } @Test - public void requireThatUpperAndLowerBoundsWork() { + void requireThatUpperAndLowerBoundsWork() { lowerBound = -999; upperBound = 999; testConvert("foo in [-9..]", "foo in [-9.. (foo=-9-0,foo=0-999)]", 10); @@ -353,7 +353,7 @@ public class ComplexNodeTransformerTest { } @Test - public void requireThatUpperAndLowerBoundsPruneClosedRanges() { + void requireThatUpperAndLowerBoundsPruneClosedRanges() { lowerBound = -999; upperBound = 999; testConvert("foo in [0..10000]", "foo in [0..10000 (foo=0-999)]", 10); @@ -364,7 +364,7 @@ public class ComplexNodeTransformerTest { } @Test - public void requireThatRangesOutsideBoundsAreSimplifiedToOneImpossibleRange() { + void requireThatRangesOutsideBoundsAreSimplifiedToOneImpossibleRange() { lowerBound = 900; upperBound = 999; testConvert("foo in [0..100]", "foo in [0..100 (foo=-9223372036854775799-9223372036854775790)]", 10); @@ -380,7 +380,7 @@ public class ComplexNodeTransformerTest { } @Test - public void requireThatUpperAndLowerBoundsAreAdjustedWithArity() { + void requireThatUpperAndLowerBoundsAreAdjustedWithArity() { lowerBound = -999; upperBound = 999; testConvert("foo in [0..10000]", "foo in [0..10000 (foo=0-999)]", 10); @@ -592,10 +592,10 @@ public class ComplexNodeTransformerTest { } @Test - public void requireThatExistingPartitionsAreCleared() { + void requireThatExistingPartitionsAreCleared() { testConvert("foo in [10..19]", "foo in [10..19 (foo=10-19)]"); Predicate p = Predicate.fromString("foo in [10..19]"); - ((FeatureRange)p).addPartition(new RangePartition("foo", 10000L, 20000L, false)); + ((FeatureRange) p).addPartition(new RangePartition("foo", 10000L, 20000L, false)); ComplexNodeTransformer tranformer = new ComplexNodeTransformer(); Predicate converted = tranformer.process(p, new PredicateOptions(10, lowerBound, upperBound)); assertEquals("foo in [10..19 (foo=10-19)]", converted.toString()); diff --git a/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/NotNodeReordererTest.java b/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/NotNodeReordererTest.java index b1a0be796ab..665b88d3af5 100644 --- a/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/NotNodeReordererTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/NotNodeReordererTest.java @@ -2,19 +2,19 @@ package com.yahoo.search.predicate.optimization; import com.yahoo.document.predicate.Predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static com.yahoo.document.predicate.Predicates.and; import static com.yahoo.document.predicate.Predicates.feature; import static com.yahoo.document.predicate.Predicates.or; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Magnar Nedland */ public class NotNodeReordererTest { @Test - public void requireThatNotChildrenAreMovedAwayFromLastAndChild() { + void requireThatNotChildrenAreMovedAwayFromLastAndChild() { checkReorder( and(feature("a").inSet("b"), feature("c").notInSet("d")), and(feature("c").notInSet("d"), feature("a").inSet("b"))); @@ -25,7 +25,7 @@ public class NotNodeReordererTest { } @Test - public void requireThatNotChildrenAreMovedToLastOrChild() { + void requireThatNotChildrenAreMovedToLastOrChild() { checkReorder( or(feature("c").notInSet("d"), feature("a").inSet("b")), or(feature("a").inSet("b"), feature("c").notInSet("d"))); @@ -36,15 +36,15 @@ public class NotNodeReordererTest { } @Test - public void requireThatComplexReorderingWork() { + void requireThatComplexReorderingWork() { checkReorder(and(feature("g").inSet("h"), - or(and(feature("a").notInSet("b"), - feature("c").notInSet("d")), - feature("e").inSet("f"))), + or(and(feature("a").notInSet("b"), + feature("c").notInSet("d")), + feature("e").inSet("f"))), and(or(feature("e").inSet("f"), - and(feature("a").notInSet("b"), - feature("c").notInSet("d"))), - feature("g").inSet("h"))); + and(feature("a").notInSet("b"), + feature("c").notInSet("d"))), + feature("g").inSet("h"))); } private static void checkReorder(Predicate input, Predicate expected) { diff --git a/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/OrSimplifierTest.java b/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/OrSimplifierTest.java index 90487b761db..e51e3d29ac2 100644 --- a/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/OrSimplifierTest.java +++ b/predicate-search-core/src/test/java/com/yahoo/search/predicate/optimization/OrSimplifierTest.java @@ -2,18 +2,18 @@ package com.yahoo.search.predicate.optimization; import com.yahoo.document.predicate.Predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static com.yahoo.document.predicate.Predicates.and; import static com.yahoo.document.predicate.Predicates.feature; import static com.yahoo.document.predicate.Predicates.not; import static com.yahoo.document.predicate.Predicates.or; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class OrSimplifierTest { @Test - public void require_that_or_with_feature_sets_of_same_key_is_simplified_to_single_feature_set() { + void require_that_or_with_feature_sets_of_same_key_is_simplified_to_single_feature_set() { Predicate p = or( feature("key1").inSet("value1", "value4"), @@ -24,7 +24,7 @@ public class OrSimplifierTest { } @Test - public void require_that_or_with_feature_sets_of_different_keys_is_simplified() { + void require_that_or_with_feature_sets_of_different_keys_is_simplified() { Predicate p = or( feature("key1").inSet("value1", "value3"), @@ -39,7 +39,7 @@ public class OrSimplifierTest { } @Test - public void require_that_conversion_is_recursive_and_cascades() { + void require_that_conversion_is_recursive_and_cascades() { Predicate p = or( feature("key1").inSet("value1", "value4"), @@ -52,7 +52,7 @@ public class OrSimplifierTest { } @Test - public void require_that_or_below_and_is_converted() { + void require_that_or_below_and_is_converted() { Predicate p = and( or( @@ -67,7 +67,7 @@ public class OrSimplifierTest { } @Test - public void require_that_or_below_not_is_converted() { + void require_that_or_below_not_is_converted() { Predicate p = not( or( @@ -78,7 +78,7 @@ public class OrSimplifierTest { } @Test - public void require_that_non_feature_set_nodes_are_left_untouched() { + void require_that_non_feature_set_nodes_are_left_untouched() { Predicate p = or( feature("key1").inSet("value1"), -- cgit v1.2.3