diff options
Diffstat (limited to 'container-search/src/test/java/com/yahoo/prelude')
103 files changed, 2484 insertions, 2507 deletions
diff --git a/container-search/src/test/java/com/yahoo/prelude/cluster/ClusterSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/cluster/ClusterSearcherTestCase.java index ac860faffa5..2b560713c57 100644 --- a/container-search/src/test/java/com/yahoo/prelude/cluster/ClusterSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/cluster/ClusterSearcherTestCase.java @@ -26,7 +26,7 @@ import com.yahoo.search.schema.Schema; import com.yahoo.search.schema.SchemaInfo; import com.yahoo.search.searchchain.Execution; import com.yahoo.vespa.config.search.DispatchConfig; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Arrays; @@ -38,10 +38,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Tests cluster monitoring @@ -53,7 +50,7 @@ public class ClusterSearcherTestCase { private static final double DELTA = 0.0000000000000001; @Test - public void testNoBackends() { + void testNoBackends() { ClusterSearcher cluster = new ClusterSearcher(new LinkedHashSet<>(Arrays.asList("dummy"))); try { Execution execution = new Execution(cluster, Execution.Context.createContextStub()); @@ -87,7 +84,7 @@ public class ClusterSearcherTestCase { } @Test - public void testThatDocumentTypesAreResolved() { + void testThatDocumentTypesAreResolved() { ClusterSearcher cluster1 = new ClusterSearcher(new LinkedHashSet<>(Arrays.asList("type1", "type2", "type3"))); try { ClusterSearcher type1 = new ClusterSearcher(new LinkedHashSet<>(Arrays.asList("type6"))); @@ -126,7 +123,7 @@ public class ClusterSearcherTestCase { } @Test - public void testThatDocumentTypesAreResolvedTODO_REMOVE() { + void testThatDocumentTypesAreResolvedTODO_REMOVE() { ClusterSearcher cluster1 = new ClusterSearcher(new LinkedHashSet<>(List.of("type1", "type2", "type3"))); try { ClusterSearcher type1 = new ClusterSearcher(new LinkedHashSet<>(List.of("type6"))); @@ -284,7 +281,7 @@ public class ClusterSearcherTestCase { } @Test - public void testThatSingleDocumentTypeCanBeSearched() { + void testThatSingleDocumentTypeCanBeSearched() { { // Explicit 1 type in restrict set Execution execution = createExecution(); Query query = new Query("?query=hello&restrict=type1"); @@ -311,7 +308,7 @@ public class ClusterSearcherTestCase { } @Test - public void testThatSubsetOfDocumentTypesCanBeSearched() { + void testThatSubsetOfDocumentTypesCanBeSearched() { Execution execution = createExecution(); Query query = new Query("?query=hello&restrict=type1,type3"); @@ -328,7 +325,7 @@ public class ClusterSearcherTestCase { } @Test - public void testThatMultipleDocumentTypesCanBeSearchedAndFilled() { + void testThatMultipleDocumentTypesCanBeSearchedAndFilled() { Execution execution = createExecution(); Query query = new Query("?query=hello"); @@ -386,7 +383,7 @@ public class ClusterSearcherTestCase { } @Test - public void testThatWeCanSpecifyNumHitsAndHitOffset() { + void testThatWeCanSpecifyNumHitsAndHitOffset() { Execution ex = createExecution(); // all types @@ -411,7 +408,7 @@ public class ClusterSearcherTestCase { } @Test - public void testThatWeCanSpecifyNumHitsAndHitOffsetWhenSorting() { + void testThatWeCanSpecifyNumHitsAndHitOffsetWhenSorting() { Execution ex = createExecution(true); String extra = "&restrict=type1,type2&sorting=%2Basc-score"; @@ -485,7 +482,7 @@ public class ClusterSearcherTestCase { } @Test - public void testThatVipStatusIsSetUpForStreamingSearch() { + void testThatVipStatusIsSetUpForStreamingSearch() { String clusterName = "test-cluster"; VipStatus vipStatus = new VipStatus(new QrSearchersConfig.Builder().searchcluster(new QrSearchersConfig.Searchcluster.Builder().name(clusterName)).build(), new ClustersStatus()); assertFalse(vipStatus.isInRotation()); @@ -494,7 +491,7 @@ public class ClusterSearcherTestCase { } @Test - public void testThatQueryTimeoutIsCappedWithDefaultMax() { + void testThatQueryTimeoutIsCappedWithDefaultMax() { QueryTimeoutFixture f = new QueryTimeoutFixture(null, null); f.query.setTimeout(600001); f.search(); @@ -502,7 +499,7 @@ public class ClusterSearcherTestCase { } @Test - public void testThatQueryTimeoutIsNotCapped() { + void testThatQueryTimeoutIsNotCapped() { QueryTimeoutFixture f = new QueryTimeoutFixture(null, null); f.query.setTimeout(599999); f.search(); @@ -510,7 +507,7 @@ public class ClusterSearcherTestCase { } @Test - public void testThatQueryTimeoutIsCappedWithSpecifiedMax() { + void testThatQueryTimeoutIsCappedWithSpecifiedMax() { QueryTimeoutFixture f = new QueryTimeoutFixture(70.0, null); f.query.setTimeout(70001); f.search(); @@ -518,7 +515,7 @@ public class ClusterSearcherTestCase { } @Test - public void testThatQueryCacheIsDisabledIfTimeoutIsLargerThanMax() { + void testThatQueryCacheIsDisabledIfTimeoutIsLargerThanMax() { QueryTimeoutFixture f = new QueryTimeoutFixture(null, null); f.query.setTimeout(10001); f.query.getRanking().setQueryCache(true); @@ -527,7 +524,7 @@ public class ClusterSearcherTestCase { } @Test - public void testThatQueryCacheIsNotDisabledIfTimeoutIsOk() { + void testThatQueryCacheIsNotDisabledIfTimeoutIsOk() { QueryTimeoutFixture f = new QueryTimeoutFixture(null, null); f.query.setTimeout(10000); f.query.getRanking().setQueryCache(true); @@ -536,7 +533,7 @@ public class ClusterSearcherTestCase { } @Test - public void testThatQueryCacheIsDisabledIfTimeoutIsLargerThanConfiguredMax() { + void testThatQueryCacheIsDisabledIfTimeoutIsLargerThanConfiguredMax() { QueryTimeoutFixture f = new QueryTimeoutFixture(null, 5.0); f.query.setTimeout(5001); f.query.getRanking().setQueryCache(true); diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/SlimeSummaryTestCase.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/SlimeSummaryTestCase.java index c39efe21e70..74874c28452 100644 --- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/SlimeSummaryTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/SlimeSummaryTestCase.java @@ -16,7 +16,7 @@ import com.yahoo.slime.Cursor; import com.yahoo.slime.Slime; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.serialization.TypedBinaryFormat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -27,12 +27,7 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; public class SlimeSummaryTestCase { @@ -43,7 +38,7 @@ public class SlimeSummaryTestCase { private static final String partial_summary3_cf = cf_pre + "partial-summary3.cfg"; @Test - public void testDecodingEmpty() { + void testDecodingEmpty() { DocsumDefinitionSet docsum = createDocsumDefinitionSet(); FastHit hit = new FastHit(); assertNull(docsum.lazyDecode("default", emptySummary(), hit)); @@ -69,23 +64,23 @@ public class SlimeSummaryTestCase { } @Test - public void testTimeout() { + void testTimeout() { DocsumDefinitionSet docsum = createDocsumDefinitionSet(); FastHit hit = new FastHit(); assertEquals("Hit hit index:null/0/000000000000000000000000 (relevance 0.0) [fasthit, globalid: 0 0 0 0 0 0 0 0 0 0 0 0, partId: 0, distributionkey: 0] failed: Timed out....", - docsum.lazyDecode("default", timeoutSummary(), hit)); + docsum.lazyDecode("default", timeoutSummary(), hit)); } @Test - public void testDecoding() { + void testDecoding() { Tensor tensor1 = Tensor.from("tensor(x{},y{}):{{x:foo,y:bar}:0.1}"); Tensor tensor2 = Tensor.from("tensor(x[1],y[1]):{{x:0,y:0}:-0.3}"); DocsumDefinitionSet docsum = createDocsumDefinitionSet(); FastHit hit = new FastHit(); assertNull(docsum.lazyDecode("default", fullSummary(tensor1, tensor2), hit)); assertEquals(4, hit.getField("integer_field")); - assertEquals((short)2, hit.getField("short_field")); - assertEquals((byte)1, hit.getField("byte_field")); + assertEquals((short) 2, hit.getField("short_field")); + assertEquals((byte) 1, hit.getField("byte_field")); assertEquals(4.5F, hit.getField("float_field")); assertEquals(8.75, hit.getField("double_field")); assertEquals(8L, hit.getField("int64_field")); @@ -117,7 +112,7 @@ public class SlimeSummaryTestCase { assertEquals(tensor2, hit.getField("tensor_field2")); FeatureData featureData = hit.features(); assertEquals("double_feature,rankingExpression(tensor1_feature),tensor2_feature", - featureData.featureNames().stream().sorted().collect(Collectors.joining(","))); + featureData.featureNames().stream().sorted().collect(Collectors.joining(","))); assertEquals(0.5, featureData.getDouble("double_feature"), 0.00000001); assertEquals(tensor1, featureData.getTensor("tensor1_feature")); assertEquals(tensor1, featureData.getTensor("rankingExpression(tensor1_feature)")); @@ -125,7 +120,7 @@ public class SlimeSummaryTestCase { } @Test - public void testFieldAccessAPI() { + void testFieldAccessAPI() { DocsumDefinitionSet partialDocsum1 = createPartialDocsumDefinitionSet1(); DocsumDefinitionSet partialDocsum2 = createPartialDocsumDefinitionSet2(); DocsumDefinitionSet partialDocsum3 = createPartialDocsumDefinitionSet3(); @@ -253,8 +248,8 @@ public class SlimeSummaryTestCase { Tensor tensor2 = Tensor.from("tensor(x[1],y[1]):{{x:0,y:0}:-0.3}"); assertNull(fullDocsum.lazyDecode("default", fullishSummary(tensor1, tensor2), hit)); expected.put("integer_field", 4); - expected.put("short_field", (short)2); - expected.put("byte_field", (byte)1); + expected.put("short_field", (short) 2); + expected.put("byte_field", (byte) 1); expected.put("float_field", 4.5f); expected.put("double_field", 8.75d); expected.put("int64_field", 8L); @@ -303,7 +298,7 @@ public class SlimeSummaryTestCase { for (Iterator<String> i = hit.fieldKeys().iterator(); i.hasNext(); ) { fieldNameIteratorFieldCount++; String name = i.next(); - assertTrue("Expected field " + name, expected.containsKey(name)); + assertTrue(expected.containsKey(name), "Expected field " + name); } assertEquals(expected.size(), fieldNameIteratorFieldCount); // fieldKeys @@ -324,11 +319,10 @@ public class SlimeSummaryTestCase { } private void assertEqualMaps(Map<String, Object> expected, Map<String, Object> actual) { - assertEquals("Map sizes", expected.size(), actual.size()); - assertEquals("Keys", expected.keySet(), actual.keySet()); + assertEquals(expected.size(), actual.size(), "Map sizes"); + assertEquals(expected.keySet(), actual.keySet(), "Keys"); for (var expectedEntry : expected.entrySet()) { - assertEquals("Key '" + expectedEntry.getKey() + "'", - expectedEntry.getValue(), actual.get(expectedEntry.getKey())); + assertEquals(expectedEntry.getValue(), actual.get(expectedEntry.getKey()), "Key '" + expectedEntry.getKey() + "'"); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/DocsumDefinitionTestCase.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/DocsumDefinitionTestCase.java index da9d849db90..f07ef0f733b 100644 --- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/DocsumDefinitionTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/DocsumDefinitionTestCase.java @@ -15,15 +15,12 @@ import com.yahoo.search.schema.Schema; import com.yahoo.slime.BinaryFormat; import com.yahoo.slime.Cursor; import com.yahoo.slime.Slime; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests docsum class functionality @@ -33,7 +30,7 @@ import static org.junit.Assert.assertTrue; public class DocsumDefinitionTestCase { @Test - public void testDecoding() { + void testDecoding() { DocsumDefinitionSet set = createDocsumDefinitionSet(); FastHit hit = new FastHit(); diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java index d5630063f4b..dbc827ea5c2 100644 --- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java @@ -30,7 +30,7 @@ import com.yahoo.search.schema.RankProfile; import com.yahoo.search.schema.Schema; import com.yahoo.search.schema.SchemaInfo; import com.yahoo.search.searchchain.Execution; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Collections; @@ -39,11 +39,7 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** @@ -54,20 +50,20 @@ import static org.junit.Assert.assertTrue; public class FastSearcherTestCase { @Test - public void testNullQuery() { + void testNullQuery() { Logger.getLogger(FastSearcher.class.getName()).setLevel(Level.ALL); FastSearcher fastSearcher = new FastSearcher("container.0", - MockDispatcher.create(Collections.emptyList()), - new SummaryParameters(null), - new ClusterParams("testhittype"), - documentdbInfoConfig("test"), - schemaInfo("test")); + MockDispatcher.create(Collections.emptyList()), + new SummaryParameters(null), + new ClusterParams("testhittype"), + documentdbInfoConfig("test"), + schemaInfo("test")); String query = "?junkparam=ignored"; Result result = doSearch(fastSearcher, new Query(query), 0, 10); ErrorMessage message = result.hits().getError(); - assertNotNull("Got error", message); + assertNotNull(message, "Got error"); assertEquals("Null query", message.getMessage()); assertEquals(query, message.getDetailedMessage()); assertEquals(Error.NULL_QUERY.code, message.getCode()); @@ -90,13 +86,13 @@ public class FastSearcherTestCase { } @Test - public void testSinglePassGroupingIsForcedWithSingleNodeGroups() { + void testSinglePassGroupingIsForcedWithSingleNodeGroups() { FastSearcher fastSearcher = new FastSearcher("container.0", - MockDispatcher.create(List.of(new Node(0, "host0", 0))), - new SummaryParameters(null), - new ClusterParams("testhittype"), - documentdbInfoConfig("test"), - schemaInfo("test")); + MockDispatcher.create(List.of(new Node(0, "host0", 0))), + new SummaryParameters(null), + new ClusterParams("testhittype"), + documentdbInfoConfig("test"), + schemaInfo("test")); Query q = new Query("?query=foo"); GroupingRequest request1 = GroupingRequest.newInstance(q); request1.setRootOperation(new AllOperation()); @@ -113,32 +109,32 @@ public class FastSearcherTestCase { } @Test - public void testRankProfileValidation() { + void testRankProfileValidation() { FastSearcher fastSearcher = new FastSearcher("container.0", - MockDispatcher.create(List.of(new Node(0, "host0", 0))), - new SummaryParameters(null), - new ClusterParams("testhittype"), - documentdbInfoConfig("test"), - schemaInfo("test")); + MockDispatcher.create(List.of(new Node(0, "host0", 0))), + new SummaryParameters(null), + new ClusterParams("testhittype"), + documentdbInfoConfig("test"), + schemaInfo("test")); assertFalse(searchError("?query=q", fastSearcher).contains("does not contain requested rank profile")); assertFalse(searchError("?query=q&ranking.profile=default", fastSearcher).contains("does not contain requested rank profile")); assertTrue(searchError("?query=q&ranking.profile=nosuch", fastSearcher).contains("does not contain requested rank profile")); } @Test - public void testSummaryNeedsQuery() { + void testSummaryNeedsQuery() { var documentDb = new DocumentdbInfoConfig(new DocumentdbInfoConfig.Builder().documentdb(new DocumentdbInfoConfig.Documentdb.Builder().name("test"))); var schema = new Schema.Builder("test") - .add(new DocumentSummary.Builder("default").build()) - .add(new RankProfile.Builder("default").setHasRankFeatures(false) - .setHasSummaryFeatures(false) - .build()); + .add(new DocumentSummary.Builder("default").build()) + .add(new RankProfile.Builder("default").setHasRankFeatures(false) + .setHasSummaryFeatures(false) + .build()); FastSearcher backend = new FastSearcher("container.0", - MockDispatcher.create(Collections.singletonList(new Node(0, "host0", 0))), - new SummaryParameters(null), - new ClusterParams("testhittype"), - documentDb, - new SchemaInfo(List.of(schema.build()), Map.of())); + MockDispatcher.create(Collections.singletonList(new Node(0, "host0", 0))), + new SummaryParameters(null), + new ClusterParams("testhittype"), + documentDb, + new SchemaInfo(List.of(schema.build()), Map.of())); Query q = new Query("?query=foo"); Result result = doSearch(backend, q, 0, 10); assertFalse(backend.summaryNeedsQuery(q)); @@ -150,15 +146,15 @@ public class FastSearcherTestCase { } @Test - public void testSinglePassGroupingIsNotForcedWithSingleNodeGroups() { + void testSinglePassGroupingIsNotForcedWithSingleNodeGroups() { MockDispatcher dispatcher = MockDispatcher.create(ImmutableList.of(new Node(0, "host0", 0), new Node(2, "host1", 0))); FastSearcher fastSearcher = new FastSearcher("container.0", - dispatcher, - new SummaryParameters(null), - new ClusterParams("testhittype"), - documentdbInfoConfig("test"), - schemaInfo("test")); + dispatcher, + new SummaryParameters(null), + new ClusterParams("testhittype"), + documentdbInfoConfig("test"), + schemaInfo("test")); Query q = new Query("?query=foo"); GroupingRequest request1 = GroupingRequest.newInstance(q); request1.setRootOperation(new AllOperation()); @@ -180,14 +176,13 @@ public class FastSearcherTestCase { } private void assertForceSinglePassIs(boolean expected, GroupingOperation operation) { - assertEquals("Force single pass is " + expected + " in " + operation, - expected, operation.getForceSinglePass()); + assertEquals(expected, operation.getForceSinglePass(), "Force single pass is " + expected + " in " + operation); for (GroupingOperation child : operation.getChildren()) assertForceSinglePassIs(expected, child); } @Test - public void testDispatchReconfig() { + void testDispatchReconfig() { String clusterName = "a"; var b = new QrSearchersConfig.Builder(); var searchClusterB = new QrSearchersConfig.Searchcluster.Builder(); diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/PartialFillTestCase.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/PartialFillTestCase.java index 45ae8241696..f73edfec4c5 100644 --- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/PartialFillTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/PartialFillTestCase.java @@ -12,16 +12,13 @@ import com.yahoo.search.rendering.RendererRegistry; import com.yahoo.search.result.ErrorHit; import com.yahoo.search.result.ErrorMessage; import com.yahoo.search.searchchain.Execution; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author havardpe @@ -50,7 +47,7 @@ public class PartialFillTestCase { } @Test - public void testPartitioning() { + void testPartitioning() { FS4 fs4 = new FS4(); Query a = new Query("/?query=foo"); Query b = new Query("/?query=bar"); @@ -107,7 +104,7 @@ public class PartialFillTestCase { } @Test - public void testMergeErrors() { + void testMergeErrors() { BadFS4 fs4 = new BadFS4(); Query a = new Query("/?query=foo"); Query b = new Query("/?query=bar"); @@ -129,17 +126,17 @@ public class PartialFillTestCase { assertNotNull(eh); ErrorMessage exp_sub = ErrorMessage.createUnspecifiedError("error"); int n = 0; - for (Iterator<? extends com.yahoo.search.result.ErrorMessage> i = eh.errorIterator(); i.hasNext();) { + for (Iterator<? extends com.yahoo.search.result.ErrorMessage> i = eh.errorIterator(); i.hasNext(); ) { com.yahoo.search.result.ErrorMessage error = i.next(); switch (n) { - case 0: - assertEquals(exp_sub, error); - break; - case 1: - assertEquals(exp_sub, error); - break; - default: - assertTrue(false); + case 0: + assertEquals(exp_sub, error); + break; + case 1: + assertEquals(exp_sub, error); + break; + default: + assertTrue(false); } n++; } diff --git a/container-search/src/test/java/com/yahoo/prelude/hitfield/XmlRendererTestCase.java b/container-search/src/test/java/com/yahoo/prelude/hitfield/XmlRendererTestCase.java index f35c45e7ad6..bf020b5ca84 100644 --- a/container-search/src/test/java/com/yahoo/prelude/hitfield/XmlRendererTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/hitfield/XmlRendererTestCase.java @@ -2,71 +2,71 @@ package com.yahoo.prelude.hitfield; import com.yahoo.data.access.simple.Value; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class XmlRendererTestCase { @Test - public void testWeightedSet1() { + void testWeightedSet1() { Value.ArrayValue top = new Value.ArrayValue(); top - .add(new Value.ArrayValue() - .add(new Value.StringValue("per")) - .add(new Value.LongValue(10))) - .add(new Value.ArrayValue() - .add(new Value.StringValue("paal")) - .add(new Value.LongValue(20))) - .add(new Value.ArrayValue() - .add(new Value.StringValue("espen")) - .add(new Value.LongValue(30))); + .add(new Value.ArrayValue() + .add(new Value.StringValue("per")) + .add(new Value.LongValue(10))) + .add(new Value.ArrayValue() + .add(new Value.StringValue("paal")) + .add(new Value.LongValue(20))) + .add(new Value.ArrayValue() + .add(new Value.StringValue("espen")) + .add(new Value.LongValue(30))); String rendered = XmlRenderer.render(new StringBuilder(), top).toString(); String correct = "\n" - + " <item weight=\"10\">per</item>\n" - + " <item weight=\"20\">paal</item>\n" - + " <item weight=\"30\">espen</item>\n" - + " "; + + " <item weight=\"10\">per</item>\n" + + " <item weight=\"20\">paal</item>\n" + + " <item weight=\"30\">espen</item>\n" + + " "; assertEquals(correct, rendered); } @Test - public void testWeightedSet2() { + void testWeightedSet2() { Value.ObjectValue top = new Value.ObjectValue(); top - .put("foo", new Value.ArrayValue() - .add(new Value.ArrayValue() - .add(new Value.StringValue("per")) - .add(new Value.LongValue(10))) - .add(new Value.ArrayValue() - .add(new Value.StringValue("paal")) - .add(new Value.LongValue(20))) - .add(new Value.ArrayValue() - .add(new Value.StringValue("espen")) - .add(new Value.LongValue(30)))) - .put("bar", new Value.ArrayValue() - .add(new Value.ObjectValue() - .put("item",new Value.StringValue("per")) - .put("weight",new Value.LongValue(10))) - .add(new Value.ObjectValue() - .put("item",new Value.StringValue("paal")) - .put("weight",new Value.LongValue(20))) - .add(new Value.ObjectValue() - .put("weight",new Value.LongValue(30)) - .put("item",new Value.StringValue("espen")))); + .put("foo", new Value.ArrayValue() + .add(new Value.ArrayValue() + .add(new Value.StringValue("per")) + .add(new Value.LongValue(10))) + .add(new Value.ArrayValue() + .add(new Value.StringValue("paal")) + .add(new Value.LongValue(20))) + .add(new Value.ArrayValue() + .add(new Value.StringValue("espen")) + .add(new Value.LongValue(30)))) + .put("bar", new Value.ArrayValue() + .add(new Value.ObjectValue() + .put("item", new Value.StringValue("per")) + .put("weight", new Value.LongValue(10))) + .add(new Value.ObjectValue() + .put("item", new Value.StringValue("paal")) + .put("weight", new Value.LongValue(20))) + .add(new Value.ObjectValue() + .put("weight", new Value.LongValue(30)) + .put("item", new Value.StringValue("espen")))); String rendered = XmlRenderer.render(new StringBuilder(), top).toString(); String correct = "\n" - + " <struct-field name=\"foo\">\n" - + " <item weight=\"10\">per</item>\n" - + " <item weight=\"20\">paal</item>\n" - + " <item weight=\"30\">espen</item>\n" - + " </struct-field>\n" - + " <struct-field name=\"bar\">\n" - + " <item weight=\"10\">per</item>\n" - + " <item weight=\"20\">paal</item>\n" - + " <item weight=\"30\">espen</item>\n" - + " </struct-field>\n" - + " "; + + " <struct-field name=\"foo\">\n" + + " <item weight=\"10\">per</item>\n" + + " <item weight=\"20\">paal</item>\n" + + " <item weight=\"30\">espen</item>\n" + + " </struct-field>\n" + + " <struct-field name=\"bar\">\n" + + " <item weight=\"10\">per</item>\n" + + " <item weight=\"20\">paal</item>\n" + + " <item weight=\"30\">espen</item>\n" + + " </struct-field>\n" + + " "; assertEquals(correct, rendered); } diff --git a/container-search/src/test/java/com/yahoo/prelude/hitfield/test/HitFieldTestCase.java b/container-search/src/test/java/com/yahoo/prelude/hitfield/test/HitFieldTestCase.java index 7c264f40388..f6b3ee65d12 100644 --- a/container-search/src/test/java/com/yahoo/prelude/hitfield/test/HitFieldTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/hitfield/test/HitFieldTestCase.java @@ -5,10 +5,10 @@ import java.util.ArrayList; import java.util.List; import com.yahoo.prelude.hitfield.HitField; -import com.yahoo.prelude.hitfield.StringFieldPart; -import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import com.yahoo.prelude.hitfield.StringFieldPart; +import org.junit.jupiter.api.Test; /** * Tests the HitField class @@ -19,7 +19,7 @@ import static org.junit.Assert.assertEquals; public class HitFieldTestCase { @Test - public void testHitField() { + void testHitField() { HitField hf = new HitField("boo", "hei paa deg"); assertEquals(3, hf.getTokenizedContent().size()); List l = new ArrayList(); @@ -32,7 +32,7 @@ public class HitFieldTestCase { } @Test - public void testCjk() { + void testCjk() { HitField hf = new HitField("boo", "hmm\u001fgr"); assertEquals(2, hf.getTokenizedContent().size()); assertEquals("hmmgr", hf.getContent()); @@ -44,7 +44,7 @@ public class HitFieldTestCase { } @Test - public void testAnnotateField() { + void testAnnotateField() { HitField hf = new HitField("boo", "The <hi>Eclipse</hi> SDK \uFFF9include\uFFFAincludes\uFFFB the <hi>Eclipse</hi> Platform"); assertEquals(11, hf.getTokenizedContent().size()); hf = new HitField("boo", "\uFFF9include\uFFFAincludes\uFFFB the <hi>Eclipse</hi> Platform"); @@ -72,7 +72,7 @@ public class HitFieldTestCase { } @Test - public void testEmptyField() { + void testEmptyField() { HitField hf = new HitField("boo", ""); assertEquals(0, hf.getTokenizedContent().size()); } diff --git a/container-search/src/test/java/com/yahoo/prelude/hitfield/test/JSONStringTestCase.java b/container-search/src/test/java/com/yahoo/prelude/hitfield/test/JSONStringTestCase.java index 256014b7df4..944e1e0a02f 100644 --- a/container-search/src/test/java/com/yahoo/prelude/hitfield/test/JSONStringTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/hitfield/test/JSONStringTestCase.java @@ -8,10 +8,10 @@ import com.yahoo.data.access.Inspector; import com.yahoo.data.access.Type; import com.yahoo.slime.Slime; import com.yahoo.slime.Cursor; -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.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests the JSONString XML rendering. @@ -23,7 +23,7 @@ import static org.junit.Assert.assertTrue; public class JSONStringTestCase { @Test - public void testWeightedSet() { + void testWeightedSet() { String json = "[[{\"as1\":[\"per\",\"paal\"],\"l1\":1122334455667788997,\"d1\":87.790001,\"i1\":7,\"al1\":[11223344556677881,11223344556677883],\"s1\":\"string\\n" + "espa\u00F1a\\n" + "wssf1.s1[0]\"},10]," @@ -44,7 +44,7 @@ public class JSONStringTestCase { + " <item>paal</item>\n" + " </struct-field>\n", " <struct-field name=\"s1\">string\n" + "españa\n" - + "wssf1.s1[0]</struct-field>\n" }; + + "wssf1.s1[0]</struct-field>\n"}; String o2 = " <item weight=\"20\">\n"; String[] o2Fields = { " <struct-field name=\"l1\">1122334455667788998</struct-field>\n", @@ -59,7 +59,7 @@ public class JSONStringTestCase { + " <item>paal</item>\n" + " </struct-field>\n", " <struct-field name=\"s1\">string\n" - + "españa wssf1.s1[1]</struct-field>\n" }; + + "españa wssf1.s1[1]</struct-field>\n"}; String rendered = js.toString(); int o1Offset = rendered.indexOf(o1); assertTrue(-1 < o1Offset); @@ -72,88 +72,88 @@ public class JSONStringTestCase { } @Test - public void testWeightedSetFromInspector() { + void testWeightedSetFromInspector() { Value.ArrayValue top = new Value.ArrayValue(); top.add(new Value.ArrayValue() .add(new Value.ObjectValue() - .put("d1", new Value.DoubleValue(87.790001)) - .put("s1", new Value.StringValue("string\n" + "espa\u00F1a\n" + "wssf1.s1[0]")) - .put("al1", new Value.ArrayValue() - .add(new Value.LongValue(11223344556677881L)) - .add(new Value.LongValue(11223344556677883L))) - .put("l1", new Value.LongValue(1122334455667788997L)) - .put("as1", new Value.ArrayValue() - .add(new Value.StringValue("per")) - .add(new Value.StringValue("paal"))) - .put("i1", new Value.LongValue(7))) + .put("d1", new Value.DoubleValue(87.790001)) + .put("s1", new Value.StringValue("string\n" + "espa\u00F1a\n" + "wssf1.s1[0]")) + .put("al1", new Value.ArrayValue() + .add(new Value.LongValue(11223344556677881L)) + .add(new Value.LongValue(11223344556677883L))) + .put("l1", new Value.LongValue(1122334455667788997L)) + .put("as1", new Value.ArrayValue() + .add(new Value.StringValue("per")) + .add(new Value.StringValue("paal"))) + .put("i1", new Value.LongValue(7))) .add(new Value.LongValue(10))) - .add(new Value.ArrayValue() - .add(new Value.ObjectValue() - .put("d1", new Value.DoubleValue(88.790001)) - .put("s1", new Value.StringValue("string\n" + "espa\u00F1a wssf1.s1[1]")) - .put("al1", new Value.ArrayValue() - .add(new Value.LongValue(11223344556677881L)) - .add(new Value.LongValue(11223344556677883L))) - .put("l1", new Value.LongValue(1122334455667788998L)) - .put("as1", new Value.ArrayValue() - .add(new Value.StringValue("per")) - .add(new Value.StringValue("paal"))) - .put("i1", new Value.LongValue(8))) - .add(new Value.LongValue(20))); + .add(new Value.ArrayValue() + .add(new Value.ObjectValue() + .put("d1", new Value.DoubleValue(88.790001)) + .put("s1", new Value.StringValue("string\n" + "espa\u00F1a wssf1.s1[1]")) + .put("al1", new Value.ArrayValue() + .add(new Value.LongValue(11223344556677881L)) + .add(new Value.LongValue(11223344556677883L))) + .put("l1", new Value.LongValue(1122334455667788998L)) + .put("as1", new Value.ArrayValue() + .add(new Value.StringValue("per")) + .add(new Value.StringValue("paal"))) + .put("i1", new Value.LongValue(8))) + .add(new Value.LongValue(20))); JSONString js = new JSONString(top); String correct = "\n" - + " <item weight=\"10\">\n" - + " <struct-field name=\"d1\">87.790001</struct-field>\n" - + " <struct-field name=\"s1\">string\n" - + "espa\u00F1a\n" - + "wssf1.s1[0]</struct-field>\n" - + " <struct-field name=\"al1\">\n" - + " <item>11223344556677881</item>\n" - + " <item>11223344556677883</item>\n" - + " </struct-field>\n" - + " <struct-field name=\"l1\">1122334455667788997</struct-field>\n" - + " <struct-field name=\"as1\">\n" - + " <item>per</item>\n" - + " <item>paal</item>\n" - + " </struct-field>\n" - + " <struct-field name=\"i1\">7</struct-field>\n" - + " </item>\n" - + " <item weight=\"20\">\n" - + " <struct-field name=\"d1\">88.790001</struct-field>\n" - + " <struct-field name=\"s1\">string\n" - + "espa\u00F1a wssf1.s1[1]</struct-field>\n" - + " <struct-field name=\"al1\">\n" - + " <item>11223344556677881</item>\n" - + " <item>11223344556677883</item>\n" - + " </struct-field>\n" - + " <struct-field name=\"l1\">1122334455667788998</struct-field>\n" - + " <struct-field name=\"as1\">\n" - + " <item>per</item>\n" - + " <item>paal</item>\n" - + " </struct-field>\n" - + " <struct-field name=\"i1\">8</struct-field>\n" - + " </item>\n" - + " "; + + " <item weight=\"10\">\n" + + " <struct-field name=\"d1\">87.790001</struct-field>\n" + + " <struct-field name=\"s1\">string\n" + + "espa\u00F1a\n" + + "wssf1.s1[0]</struct-field>\n" + + " <struct-field name=\"al1\">\n" + + " <item>11223344556677881</item>\n" + + " <item>11223344556677883</item>\n" + + " </struct-field>\n" + + " <struct-field name=\"l1\">1122334455667788997</struct-field>\n" + + " <struct-field name=\"as1\">\n" + + " <item>per</item>\n" + + " <item>paal</item>\n" + + " </struct-field>\n" + + " <struct-field name=\"i1\">7</struct-field>\n" + + " </item>\n" + + " <item weight=\"20\">\n" + + " <struct-field name=\"d1\">88.790001</struct-field>\n" + + " <struct-field name=\"s1\">string\n" + + "espa\u00F1a wssf1.s1[1]</struct-field>\n" + + " <struct-field name=\"al1\">\n" + + " <item>11223344556677881</item>\n" + + " <item>11223344556677883</item>\n" + + " </struct-field>\n" + + " <struct-field name=\"l1\">1122334455667788998</struct-field>\n" + + " <struct-field name=\"as1\">\n" + + " <item>per</item>\n" + + " <item>paal</item>\n" + + " </struct-field>\n" + + " <struct-field name=\"i1\">8</struct-field>\n" + + " </item>\n" + + " "; assertEquals(correct, js.renderFromInspector()); top = new Value.ArrayValue(); top.add(new Value.ArrayValue() .add(new Value.StringValue("s1")) .add(new Value.LongValue(10))) - .add(new Value.ArrayValue() - .add(new Value.StringValue("s2")) - .add(new Value.LongValue(20))); + .add(new Value.ArrayValue() + .add(new Value.StringValue("s2")) + .add(new Value.LongValue(20))); js = new JSONString(top); correct = "\n" + - " <item weight=\"10\">s1</item>\n" + - " <item weight=\"20\">s2</item>\n" + - " "; + " <item weight=\"10\">s1</item>\n" + + " <item weight=\"20\">s2</item>\n" + + " "; assertEquals(correct, js.renderFromInspector()); } @Test - public void testStruct() { + void testStruct() { { Value.ObjectValue top = new Value.ObjectValue(); top.put("d1", new Value.DoubleValue(81.790001)) @@ -184,7 +184,7 @@ public class JSONStringTestCase { + " <item>per</item>\n" + " <item>paal</item>\n" + " </struct-field>\n", - " <struct-field name=\"i1\">1</struct-field>\n" }; + " <struct-field name=\"i1\">1</struct-field>\n"}; String rendered = js.renderFromInspector(); checkSubstrings(renderedFields, rendered); @@ -213,7 +213,7 @@ public class JSONStringTestCase { + " <item>per</item>\n" + " <item>paal</item>\n" + " </struct-field>\n", - " <struct-field name=\"i1\">4</struct-field>\n " }; + " <struct-field name=\"i1\">4</struct-field>\n "}; String rendered = js.renderFromInspector(); checkSubstrings(renderedFields, rendered); @@ -299,7 +299,7 @@ public class JSONStringTestCase { String[] renderedFields = { " <struct-field name=\"nss1\">\n", " <struct-field name=\"s2\">string españa\n" - + "ssf8.s2</struct-field>\n " }; + + "ssf8.s2</struct-field>\n "}; String nss1Fields[] = { " <struct-field name=\"al1\">\n" + " <item>11223344556677881</item>\n" @@ -310,7 +310,7 @@ public class JSONStringTestCase { " <struct-field name=\"as1\">\n" + " <item>per</item>\n" + " <item>paal</item>\n" - + " </struct-field>\n" }; + + " </struct-field>\n"}; checkSubstrings(renderedFields, rendered); int nss1Offset = rendered.indexOf(renderedFields[0]) @@ -321,58 +321,58 @@ public class JSONStringTestCase { } @Test - public void testMap() { + void testMap() { String json = "[{\"key\":\"k1\",\"value\":\"v1\"},{\"key\":\"k2\",\"value\":\"v2\"}]"; JSONString js = new JSONString(json); String correct = "\n" - + " <item><key>k1</key><value>v1</value></item>\n" - + " <item><key>k2</key><value>v2</value></item>\n "; - assertEquals(correct,js.toString()); + + " <item><key>k1</key><value>v1</value></item>\n" + + " <item><key>k2</key><value>v2</value></item>\n "; + assertEquals(correct, js.toString()); Inspector top = new Value.ArrayValue() - .add(new Value.ObjectValue() - .put("key", "k1") - .put("value", "v1")) - .add(new Value.ObjectValue() - .put("key", "k2") - .put("value", "v2")); + .add(new Value.ObjectValue() + .put("key", "k1") + .put("value", "v1")) + .add(new Value.ObjectValue() + .put("key", "k2") + .put("value", "v2")); js = new JSONString(top); assertEquals(correct, js.renderFromInspector()); } @Test - public void testWithData() { - byte[] d1 = { (byte)0x41, (byte)0x42, (byte)0x43 }; - byte[] d2 = { (byte)0x00, (byte)0x01, (byte)0x00, (byte)0x02 }; - byte[] d3 = { (byte)0x12, (byte)0x34 }; - byte[] d4 = { (byte)0xff, (byte)0x80, (byte)0x7f }; + void testWithData() { + byte[] d1 = {(byte) 0x41, (byte) 0x42, (byte) 0x43}; + byte[] d2 = {(byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02}; + byte[] d3 = {(byte) 0x12, (byte) 0x34}; + byte[] d4 = {(byte) 0xff, (byte) 0x80, (byte) 0x7f}; Inspector top = new Value.ObjectValue() - .put("simple", new Value.DataValue(d1)) - .put("array", new Value.ArrayValue() - .add(new Value.DataValue(d2)) - .add(new Value.DataValue(d3)) - .add(new Value.DataValue(d4))); + .put("simple", new Value.DataValue(d1)) + .put("array", new Value.ArrayValue() + .add(new Value.DataValue(d2)) + .add(new Value.DataValue(d3)) + .add(new Value.DataValue(d4))); JSONString js = new JSONString(top); String correct = "\n" - + " <struct-field name=\"simple\">" - + "<data length=\"3\" encoding=\"hex\">414243</data>" - + "</struct-field>\n" - + " <struct-field name=\"array\">\n" - + " <item>" - + "<data length=\"4\" encoding=\"hex\">00010002</data>" - + "</item>\n" - + " <item>" - + "<data length=\"2\" encoding=\"hex\">1234</data>" - + "</item>\n" - + " <item>" - + "<data length=\"3\" encoding=\"hex\">FF807F</data>" - + "</item>\n" - + " </struct-field>\n "; + + " <struct-field name=\"simple\">" + + "<data length=\"3\" encoding=\"hex\">414243</data>" + + "</struct-field>\n" + + " <struct-field name=\"array\">\n" + + " <item>" + + "<data length=\"4\" encoding=\"hex\">00010002</data>" + + "</item>\n" + + " <item>" + + "<data length=\"2\" encoding=\"hex\">1234</data>" + + "</item>\n" + + " <item>" + + "<data length=\"3\" encoding=\"hex\">FF807F</data>" + + "</item>\n" + + " </struct-field>\n "; assertEquals(correct, js.renderFromInspector()); } @Test - public void testArrayOfArray() { + void testArrayOfArray() { String json = "[[\"c1\", 0], [\"c2\", 2, 3], [\"c3\", 3, 4, 5], [\"c4\", 4,5,6,7]]"; JSONString js = new JSONString(json); Inspector outer = js.inspect(); @@ -402,48 +402,48 @@ public class JSONStringTestCase { } @Test - public void testSimpleArrays() { + void testSimpleArrays() { String json = "[1, 2, 3]"; JSONString js = new JSONString(json); String correct = "\n" - + " <item>1</item>\n" - + " <item>2</item>\n" - + " <item>3</item>\n "; + + " <item>1</item>\n" + + " <item>2</item>\n" + + " <item>3</item>\n "; assertEquals(correct, js.toString()); Inspector top = new Value.ArrayValue() - .add(1).add(2).add(3); + .add(1).add(2).add(3); js = new JSONString(top); assertEquals(correct, js.renderFromInspector()); json = "[1.0, 2.0, 3.0]"; js = new JSONString(json); correct = "\n" - + " <item>1.0</item>\n" - + " <item>2.0</item>\n" - + " <item>3.0</item>\n "; + + " <item>1.0</item>\n" + + " <item>2.0</item>\n" + + " <item>3.0</item>\n "; assertEquals(correct, js.toString()); top = new Value.ArrayValue() - .add(1.0).add(2.0).add(3.0); + .add(1.0).add(2.0).add(3.0); js = new JSONString(top); assertEquals(correct, js.renderFromInspector()); json = "[\"a\", \"b\", \"c\"]"; correct = "\n" - + " <item>a</item>\n" - + " <item>b</item>\n" - + " <item>c</item>\n "; + + " <item>a</item>\n" + + " <item>b</item>\n" + + " <item>c</item>\n "; js = new JSONString(json); assertEquals(correct, js.toString()); top = new Value.ArrayValue() - .add("a").add("b").add("c"); + .add("a").add("b").add("c"); js = new JSONString(top); assertEquals(correct, js.renderFromInspector()); } @Test - public void testArrayOfStruct() { + void testArrayOfStruct() { String json = "[{\"as1\":[\"per\",\"paal\"]," + "\"l1\":1122334455667788994,\"d1\":74.790001," + "\"i1\":14,\"al1\":[11223344556677881,11223344556677883],\"s1\":\"string\\n" @@ -465,7 +465,7 @@ public class JSONStringTestCase { + " <item>paal</item>\n" + " </struct-field>\n", " <struct-field name=\"s1\">string\n" + "españa\n" - + "asf1[0].s1</struct-field>\n" }; + + "asf1[0].s1</struct-field>\n"}; String separator = " </item>\n" + " <item>\n"; String[] o2Fields = { " <struct-field name=\"l1\">1122334455667788995</struct-field>\n", @@ -480,7 +480,7 @@ public class JSONStringTestCase { + " <item>paal</item>\n" + " </struct-field>\n", " <struct-field name=\"s1\">string\n" - + "españa asf1[1].s1</struct-field>\n" }; + + "españa asf1[1].s1</struct-field>\n"}; String rendered = js.toString(); int o2Offset = rendered.indexOf(separator); @@ -535,153 +535,153 @@ public class JSONStringTestCase { } } -/*** here is some json for you - - [{"asf":"here is 1st simple string field", - "map":[{"key":"one key string","value":["one value string","embedded array"]}, - {"key":"two key string","value":["two value string","embedded array"]}], - "sf2":"here is 2nd simple string field"}, - {"asf":"here is 3rd simple string field", - "map":[{"key":"three key string","value":["three value string","embedded array"]}, - {"key":"four key string","value":["four value string","embedded array"]}], - "sf2":"here is 4th simple string field"}, - ] - -***/ - -/*** and here is some corresponding XML - - <item> - <struct-field name="asf">here is 1st simple string field</struct-field> - <struct-field name="map"> - <item><key>one key string</key><value> - <item>one value string</item> - <item>embedded array</item> - </value></item> - <item><key>two key string</key><value> - <item>two value string</item> - <item>embedded array</item> - </value></item> - </struct-field> - <struct-field name="sf2">here is 2nd simple string field</struct-field> - </item> - <item> - <struct-field name="asf">here is 3rd simple string field</struct-field> - <struct-field name="map"> - <item><key>three key string</key><value> - <item>three value string</item> - <item>embedded array</item> - </value></item> - <item><key>four key string</key><value> - <item>four value string</item> - <item>embedded array</item> - </value></item> - </struct-field> - <struct-field name="sf2">here is 4th simple string field</struct-field> - </item> - -***/ + /*** here is some json for you + + [{"asf":"here is 1st simple string field", + "map":[{"key":"one key string","value":["one value string","embedded array"]}, + {"key":"two key string","value":["two value string","embedded array"]}], + "sf2":"here is 2nd simple string field"}, + {"asf":"here is 3rd simple string field", + "map":[{"key":"three key string","value":["three value string","embedded array"]}, + {"key":"four key string","value":["four value string","embedded array"]}], + "sf2":"here is 4th simple string field"}, + ] + + ***/ + + /*** and here is some corresponding XML + + <item> + <struct-field name="asf">here is 1st simple string field</struct-field> + <struct-field name="map"> + <item><key>one key string</key><value> + <item>one value string</item> + <item>embedded array</item> + </value></item> + <item><key>two key string</key><value> + <item>two value string</item> + <item>embedded array</item> + </value></item> + </struct-field> + <struct-field name="sf2">here is 2nd simple string field</struct-field> + </item> + <item> + <struct-field name="asf">here is 3rd simple string field</struct-field> + <struct-field name="map"> + <item><key>three key string</key><value> + <item>three value string</item> + <item>embedded array</item> + </value></item> + <item><key>four key string</key><value> + <item>four value string</item> + <item>embedded array</item> + </value></item> + </struct-field> + <struct-field name="sf2">here is 4th simple string field</struct-field> + </item> + + ***/ @Test - public void testArrayOfStructWithMap() { + void testArrayOfStructWithMap() { String json = "[{\"asf\":\"here is 1st simple string field\",\"map\":[{\"key\":\"one key string\",\"value\":[\"one value string\",\"embedded array\"]},{\"key\":\"two key string\",\"value\":[\"two value string\",\"embedded array\"]}],\"sf2\":\"here is 2nd simple string field\"},{\"asf\":\"here is 3rd simple string field\",\"map\":[{\"key\":\"three key string\",\"value\":[\"three value string\",\"embedded array\"]},{\"key\":\"four key string\",\"value\":[\"four value string\",\"embedded array\"]}],\"sf2\":\"here is 4th simple string field\"}]"; JSONString js = new JSONString(json); String correct = "\n" - + " <item>\n" - + " <struct-field name=\"asf\">here is 1st simple string field</struct-field>\n" - + " <struct-field name=\"map\">\n" - + " <item><key>one key string</key><value>\n" - + " <item>one value string</item>\n" - + " <item>embedded array</item>\n" - + " </value></item>\n" - + " <item><key>two key string</key><value>\n" - + " <item>two value string</item>\n" - + " <item>embedded array</item>\n" - + " </value></item>\n" - + " </struct-field>\n" - + " <struct-field name=\"sf2\">here is 2nd simple string field</struct-field>\n" - + " </item>\n" - + " <item>\n" - + " <struct-field name=\"asf\">here is 3rd simple string field</struct-field>\n" - + " <struct-field name=\"map\">\n" - + " <item><key>three key string</key><value>\n" - + " <item>three value string</item>\n" - + " <item>embedded array</item>\n" - + " </value></item>\n" - + " <item><key>four key string</key><value>\n" - + " <item>four value string</item>\n" - + " <item>embedded array</item>\n" - + " </value></item>\n" - + " </struct-field>\n" - + " <struct-field name=\"sf2\">here is 4th simple string field</struct-field>\n" - + " </item>\n" - + " "; + + " <item>\n" + + " <struct-field name=\"asf\">here is 1st simple string field</struct-field>\n" + + " <struct-field name=\"map\">\n" + + " <item><key>one key string</key><value>\n" + + " <item>one value string</item>\n" + + " <item>embedded array</item>\n" + + " </value></item>\n" + + " <item><key>two key string</key><value>\n" + + " <item>two value string</item>\n" + + " <item>embedded array</item>\n" + + " </value></item>\n" + + " </struct-field>\n" + + " <struct-field name=\"sf2\">here is 2nd simple string field</struct-field>\n" + + " </item>\n" + + " <item>\n" + + " <struct-field name=\"asf\">here is 3rd simple string field</struct-field>\n" + + " <struct-field name=\"map\">\n" + + " <item><key>three key string</key><value>\n" + + " <item>three value string</item>\n" + + " <item>embedded array</item>\n" + + " </value></item>\n" + + " <item><key>four key string</key><value>\n" + + " <item>four value string</item>\n" + + " <item>embedded array</item>\n" + + " </value></item>\n" + + " </struct-field>\n" + + " <struct-field name=\"sf2\">here is 4th simple string field</struct-field>\n" + + " </item>\n" + + " "; assertEquals(correct, js.toString()); Inspector top = new Value.ArrayValue() - .add(new Value.ObjectValue() - .put("asf", "here is 1st simple string field") - .put("map", new Value.ArrayValue() - .add(new Value.ObjectValue() - .put("key", "one key string") - .put("value", new Value.ArrayValue() - .add("one value string") - .add("embedded array"))) - .add(new Value.ObjectValue() - .put("key", "two key string") - .put("value", new Value.ArrayValue() - .add("two value string") - .add("embedded array")))) - .put("sf2", "here is 2nd simple string field")) - .add(new Value.ObjectValue() - .put("asf", "here is 3rd simple string field") - .put("map", new Value.ArrayValue() - .add(new Value.ObjectValue() - .put("key", "three key string") - .put("value", new Value.ArrayValue() - .add("three value string") - .add("embedded array"))) - .add(new Value.ObjectValue() - .put("key", "four key string") - .put("value", new Value.ArrayValue() - .add("four value string") - .add("embedded array")))) - .put("sf2", "here is 4th simple string field")); + .add(new Value.ObjectValue() + .put("asf", "here is 1st simple string field") + .put("map", new Value.ArrayValue() + .add(new Value.ObjectValue() + .put("key", "one key string") + .put("value", new Value.ArrayValue() + .add("one value string") + .add("embedded array"))) + .add(new Value.ObjectValue() + .put("key", "two key string") + .put("value", new Value.ArrayValue() + .add("two value string") + .add("embedded array")))) + .put("sf2", "here is 2nd simple string field")) + .add(new Value.ObjectValue() + .put("asf", "here is 3rd simple string field") + .put("map", new Value.ArrayValue() + .add(new Value.ObjectValue() + .put("key", "three key string") + .put("value", new Value.ArrayValue() + .add("three value string") + .add("embedded array"))) + .add(new Value.ObjectValue() + .put("key", "four key string") + .put("value", new Value.ArrayValue() + .add("four value string") + .add("embedded array")))) + .put("sf2", "here is 4th simple string field")); js = new JSONString(top); assertEquals(correct, js.renderFromInspector()); } @Test - public void testArrayOfStructWithEmptyMap() { + void testArrayOfStructWithEmptyMap() { String json = "[{\"asf\":\"here is 1st simple string field\",\"map\":[],\"sf2\":\"here is 2nd simple string field\"},{\"asf\":\"here is 3rd simple string field\",\"map\":[],\"sf2\":\"here is 4th simple string field\"}]"; JSONString js = new JSONString(json); String correct = "\n" - + " <item>\n" - + " <struct-field name=\"asf\">here is 1st simple string field</struct-field>\n" - + " <struct-field name=\"map\"></struct-field>\n" - + " <struct-field name=\"sf2\">here is 2nd simple string field</struct-field>\n" - + " </item>\n" - + " <item>\n" - + " <struct-field name=\"asf\">here is 3rd simple string field</struct-field>\n" - + " <struct-field name=\"map\"></struct-field>\n" - + " <struct-field name=\"sf2\">here is 4th simple string field</struct-field>\n" - + " </item>\n" - + " "; + + " <item>\n" + + " <struct-field name=\"asf\">here is 1st simple string field</struct-field>\n" + + " <struct-field name=\"map\"></struct-field>\n" + + " <struct-field name=\"sf2\">here is 2nd simple string field</struct-field>\n" + + " </item>\n" + + " <item>\n" + + " <struct-field name=\"asf\">here is 3rd simple string field</struct-field>\n" + + " <struct-field name=\"map\"></struct-field>\n" + + " <struct-field name=\"sf2\">here is 4th simple string field</struct-field>\n" + + " </item>\n" + + " "; assertEquals(correct, js.toString()); Inspector top = new Value.ArrayValue() - .add(new Value.ObjectValue() - .put("asf", "here is 1st simple string field") - .put("map", new Value.ArrayValue()) - .put("sf2", "here is 2nd simple string field")) - .add(new Value.ObjectValue() - .put("asf", "here is 3rd simple string field") - .put("map", new Value.ArrayValue()) - .put("sf2", "here is 4th simple string field")); + .add(new Value.ObjectValue() + .put("asf", "here is 1st simple string field") + .put("map", new Value.ArrayValue()) + .put("sf2", "here is 2nd simple string field")) + .add(new Value.ObjectValue() + .put("asf", "here is 3rd simple string field") + .put("map", new Value.ArrayValue()) + .put("sf2", "here is 4th simple string field")); js = new JSONString(top); assertEquals(correct, js.renderFromInspector()); @@ -718,7 +718,7 @@ public class JSONStringTestCase { } @Test - public void testInspectorToContentMapping() { + void testInspectorToContentMapping() { String content1 = new JSONString(getSlime1()).getContent(); String content2 = new JSONString(getSlime2()).getContent(); String content3 = new JSONString(getSlime3()).getContent(); @@ -732,7 +732,7 @@ public class JSONStringTestCase { } @Test - public void testContentToInspectorMapping() { + void testContentToInspectorMapping() { Inspector value1 = new JSONString("").inspect(); Inspector value2 = new JSONString("foo").inspect(); Inspector value3 = new JSONString("\"foo\"").inspect(); diff --git a/container-search/src/test/java/com/yahoo/prelude/hitfield/test/TokenFieldIteratorTestCase.java b/container-search/src/test/java/com/yahoo/prelude/hitfield/test/TokenFieldIteratorTestCase.java index 4b59a31785a..1e689d95cee 100644 --- a/container-search/src/test/java/com/yahoo/prelude/hitfield/test/TokenFieldIteratorTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/hitfield/test/TokenFieldIteratorTestCase.java @@ -4,11 +4,11 @@ package com.yahoo.prelude.hitfield.test; import java.util.ListIterator; import com.yahoo.prelude.hitfield.FieldPart; + +import static org.junit.jupiter.api.Assertions.assertEquals; import com.yahoo.prelude.hitfield.HitField; import com.yahoo.prelude.hitfield.StringFieldPart; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; /** * Tests the FieldTokenIterator class @@ -18,35 +18,35 @@ import static org.junit.Assert.assertEquals; public class TokenFieldIteratorTestCase { @Test - public void testTokenIteratorNext() { + void testTokenIteratorNext() { HitField hf = new HitField("boo", "hei paa deg"); assertEquals(3, hf.getTokenizedContent().size()); ListIterator<?> l = hf.tokenIterator(); - FieldPart p = (FieldPart)l.next(); + FieldPart p = (FieldPart) l.next(); assertEquals("hei", p.getContent()); - p = (FieldPart)l.next(); + p = (FieldPart) l.next(); assertEquals("paa", p.getContent()); - p = (FieldPart)l.next(); + p = (FieldPart) l.next(); assertEquals("deg", p.getContent()); assertEquals(false, l.hasNext()); } @Test - public void testTokenIteratorPrevious() { + void testTokenIteratorPrevious() { HitField hf = new HitField("boo", "hei paa"); ListIterator<?> l = hf.tokenIterator(); - FieldPart p = (FieldPart)l.next(); + FieldPart p = (FieldPart) l.next(); assertEquals("hei", p.getContent()); - p = (FieldPart)l.next(); + p = (FieldPart) l.next(); assertEquals("paa", p.getContent()); - p = (FieldPart)l.previous(); + p = (FieldPart) l.previous(); assertEquals("paa", p.getContent()); - p = (FieldPart)l.previous(); + p = (FieldPart) l.previous(); assertEquals("hei", p.getContent()); } @Test - public void testTokenIteratorSet() { + void testTokenIteratorSet() { HitField hf = new HitField("boo", "hei paa deg"); assertEquals(3, hf.getTokenizedContent().size()); ListIterator<FieldPart> l = hf.tokenIterator(); @@ -61,7 +61,7 @@ public class TokenFieldIteratorTestCase { } @Test - public void testTokenIteratorAdd() { + void testTokenIteratorAdd() { HitField hf = new HitField("boo", "hei paa deg"); assertEquals(3, hf.getTokenizedContent().size()); ListIterator<FieldPart> l = hf.tokenIterator(); @@ -76,7 +76,7 @@ public class TokenFieldIteratorTestCase { } @Test - public void testTokenIteratorRemove() { + void testTokenIteratorRemove() { HitField hf = new HitField("boo", "hei paa deg"); ListIterator<FieldPart> l = hf.tokenIterator(); l.next(); diff --git a/container-search/src/test/java/com/yahoo/prelude/query/ItemHelperTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/ItemHelperTestCase.java index 657d7fb30bc..dccf471fb04 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/ItemHelperTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/ItemHelperTestCase.java @@ -1,7 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.query; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -9,8 +10,7 @@ import java.util.ArrayList; import java.util.List; import com.yahoo.search.test.QueryTestCase; -import org.junit.Test; - +import org.junit.jupiter.api.Test; import com.yahoo.search.Query; @@ -23,14 +23,14 @@ import com.yahoo.search.Query; public class ItemHelperTestCase { @Test - public final void testGetNumTerms() { + final void testGetNumTerms() { ItemHelper helper = new ItemHelper(); Query q = new Query("/?query=" + enc("a b c")); assertEquals(3, helper.getNumTerms(q.getModel().getQueryTree().getRoot())); } @Test - public final void testGetPositiveTerms() { + final void testGetPositiveTerms() { ItemHelper helper = new ItemHelper(); Query q = new Query("/?query=" + enc("a b c \"d e\" -f")); List<IndexedItem> l = new ArrayList<>(); @@ -52,7 +52,7 @@ public class ItemHelperTestCase { c = true; } } - assertFalse("An item is missing.", (a & b & c & d) == false); + assertNotNull(false); } private String enc(String s) { diff --git a/container-search/src/test/java/com/yahoo/prelude/query/ItemLabelTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/ItemLabelTestCase.java index 06808d2c8d5..17a4ce400ff 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/ItemLabelTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/ItemLabelTestCase.java @@ -3,9 +3,9 @@ package com.yahoo.prelude.query; import java.lang.reflect.Modifier; -import static org.junit.Assert.*; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; import com.yahoo.search.Query; import com.yahoo.prelude.query.textualrepresentation.Discloser; @@ -27,13 +27,13 @@ public class ItemLabelTestCase { } @Test - public final void testLabelVisibility() throws Exception { + final void testLabelVisibility() throws Exception { assertTrue(Modifier.isPublic(Item.class.getMethod("setLabel", String.class).getModifiers())); assertTrue(Modifier.isPublic(Item.class.getMethod("getLabel").getModifiers())); } @Test - public final void testLabelAccess() { + final void testLabelAccess() { Item item = new WordItem("word"); assertFalse(item.hasUniqueID()); assertNull(item.getLabel()); @@ -43,7 +43,7 @@ public class ItemLabelTestCase { } @Test - public final void testLabelDisclose() { + final void testLabelDisclose() { LabelCatcher catcher = new LabelCatcher(); Item item = new WordItem("word"); item.disclose(catcher); @@ -54,7 +54,7 @@ public class ItemLabelTestCase { } @Test - public final void testLabelEncode() { + final void testLabelEncode() { Item w1 = new WordItem("w1"); Item w2 = new WordItem("w2"); Item w3 = new WordItem("w3"); diff --git a/container-search/src/test/java/com/yahoo/prelude/query/ItemsCommonStuffTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/ItemsCommonStuffTestCase.java index 418d7121769..f25c858a6a4 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/ItemsCommonStuffTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/ItemsCommonStuffTestCase.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.prelude.query; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.nio.ByteBuffer; import java.util.Arrays; @@ -9,8 +9,7 @@ import java.util.ListIterator; import java.util.NoSuchElementException; import java.util.regex.PatternSyntaxException; -import org.junit.Test; - +import org.junit.jupiter.api.Test; import com.yahoo.prelude.query.Item.ItemType; /** @@ -21,7 +20,7 @@ import com.yahoo.prelude.query.Item.ItemType; public class ItemsCommonStuffTestCase { @Test - public void testLoops() { + void testLoops() { AndSegmentItem as = new AndSegmentItem("farmyards", false, false); boolean caught = false; try { @@ -58,7 +57,7 @@ public class ItemsCommonStuffTestCase { } @Test - public void testIndexName() { + void testIndexName() { WordItem w = new WordItem("nalle"); AndItem a = new AndItem(); a.addItem(w); @@ -68,7 +67,7 @@ public class ItemsCommonStuffTestCase { } @Test - public void testBoundaries() { + void testBoundaries() { WordItem w = new WordItem("nalle"); AndItem a = new AndItem(); boolean caught = false; @@ -102,7 +101,7 @@ public class ItemsCommonStuffTestCase { } @Test - public void testRemoving() { + void testRemoving() { AndItem other = new AndItem(); WordItem w = new WordItem("nalle"); AndItem a = new AndItem(); @@ -117,7 +116,7 @@ public class ItemsCommonStuffTestCase { } @Test - public void testGeneralMutability() { + void testGeneralMutability() { AndItem a = new AndItem(); assertFalse(a.isLocked()); a.lock(); @@ -125,7 +124,7 @@ public class ItemsCommonStuffTestCase { } @Test - public void testCounting() { + void testCounting() { WordItem w = new WordItem("nalle"); AndItem a = new AndItem(); WordItem v = new WordItem("bamse"); @@ -139,7 +138,7 @@ public class ItemsCommonStuffTestCase { } @Test - public void testIteratorJuggling() { + void testIteratorJuggling() { AndItem a = new AndItem(); WordItem w0 = new WordItem("nalle"); WordItem w1 = new WordItem("bamse"); @@ -168,7 +167,7 @@ public class ItemsCommonStuffTestCase { } @Test - public void testIdStuff() { + void testIdStuff() { Item i; String expected = "i"; i = new ExactStringItem(expected); @@ -187,7 +186,7 @@ public class ItemsCommonStuffTestCase { i = new WeightedSetItem("nalle"); assertEquals(ItemType.WEIGHTEDSET, i.getItemType()); assertEquals("WEIGHTEDSET", i.getName()); - i = new AndSegmentItem("",false, false); + i = new AndSegmentItem("", false, false); assertEquals(ItemType.AND, i.getItemType()); assertEquals("SAND", i.getName()); i = new WeakAndItem(); @@ -196,7 +195,7 @@ public class ItemsCommonStuffTestCase { } @Test - public void testEquivBuilding() { + void testEquivBuilding() { WordItem w = new WordItem("nalle"); WordItem v = new WordItem("bamse"); w.setConnectivity(v, 1.0); @@ -206,7 +205,7 @@ public class ItemsCommonStuffTestCase { } @Test - public final void testEquivBuildingFromCollection() { + final void testEquivBuildingFromCollection() { WordItem w = new WordItem("nalle"); WordItem v = new WordItem("bamse"); w.setConnectivity(v, 1.0); @@ -220,7 +219,7 @@ public class ItemsCommonStuffTestCase { } @Test - public void testSegment() { + void testSegment() { AndSegmentItem as = new AndSegmentItem("farmyards", false, false); assertFalse(as.isLocked()); WordItem firstItem = new WordItem("nalle"); @@ -253,20 +252,20 @@ public class ItemsCommonStuffTestCase { } @Test - public void testMarkersVsWords() { + void testMarkersVsWords() { WordItem mw0 = MarkerWordItem.createEndOfHost(); WordItem mw1 = MarkerWordItem.createStartOfHost(); WordItem w0 = new WordItem("$"); WordItem w1 = new WordItem("^"); assertEquals(w0.getWord(), mw0.getWord()); assertEquals(w1.getWord(), mw1.getWord()); - assertFalse(mw0.equals(w0)); - assertTrue(mw0.equals(MarkerWordItem.createEndOfHost())); - assertFalse(w1.hashCode() == mw1.hashCode()); + assertNotEquals(mw0, w0); + assertEquals(mw0, MarkerWordItem.createEndOfHost()); + assertNotNull(mw1.hashCode()); } @Test - public void testNumberBasics() { + void testNumberBasics() { String expected = "12"; IntItem i = new IntItem(expected, "num"); assertEquals(expected, i.stringValue()); @@ -279,12 +278,12 @@ public class ItemsCommonStuffTestCase { assertTrue(i.isStemmed()); assertFalse(i.isWords()); assertEquals(1, i.getNumWords()); - assertFalse(i.equals(new IntItem(expected3))); - assertTrue(i.equals(new IntItem(expected3, "num"))); + assertNotEquals(i, new IntItem(expected3)); + assertEquals(i, new IntItem(expected3, "num")); } @Test - public void testNullItemFailsProperly() { + void testNullItemFailsProperly() { NullItem n = new NullItem(); n.setIndexName("nalle"); boolean caught = false; @@ -311,7 +310,7 @@ public class ItemsCommonStuffTestCase { } @Test - public void testNearisNotAnd() { + void testNearisNotAnd() { AndItem a = new AndItem(); NearItem n = new NearItem(); n.setDistance(2); @@ -323,14 +322,14 @@ public class ItemsCommonStuffTestCase { fill(n); fill(n2); fill(n3); - assertFalse(a.hashCode() == n.hashCode()); - assertFalse(n.equals(a)); - assertTrue(n.equals(n2)); - assertFalse(n.equals(n3)); + assertNotNull(n.hashCode()); + assertNotEquals(n, a); + assertEquals(n, n2); + assertNotEquals(n, n3); } @Test - public void testPhraseSegmentBasics() { + void testPhraseSegmentBasics() { AndSegmentItem a = new AndSegmentItem("gnurk", "gurk", false, false); fill(a); a.lock(); @@ -352,7 +351,7 @@ public class ItemsCommonStuffTestCase { } @Test - public void testPhraseConnectivity() { + void testPhraseConnectivity() { WordItem w = new WordItem("a"); PhraseItem p = new PhraseItem(); fill(p); @@ -362,7 +361,7 @@ public class ItemsCommonStuffTestCase { } @Test - public void testBaseClassPhraseSegments() { + void testBaseClassPhraseSegments() { PhraseSegmentItem p = new PhraseSegmentItem("g", false, true); fill(p); assertEquals(4, p.encode(ByteBuffer.allocate(5000))); @@ -373,18 +372,18 @@ public class ItemsCommonStuffTestCase { } @Test - public void testTermTypeBasic() { - assertFalse(TermType.AND.equals(TermType.DEFAULT)); - assertFalse(TermType.AND.equals(Integer.valueOf(10))); - assertTrue(TermType.AND.equals(TermType.AND)); + void testTermTypeBasic() { + assertNotEquals(TermType.AND, TermType.DEFAULT); + assertNotEquals(TermType.AND, Integer.valueOf(10)); + assertEquals(TermType.AND, TermType.AND); assertSame(AndItem.class, TermType.DEFAULT.createItemClass().getClass()); assertSame(CompositeItem.class, TermType.DEFAULT.getItemClass()); - assertFalse(TermType.AND.hashCode() == TermType.PHRASE.hashCode()); + assertNotNull(TermType.PHRASE.hashCode()); assertEquals("term type 'not'", TermType.NOT.toString()); } @Test - public void testRegexp() { + void testRegexp() { RegExpItem empty = new RegExpItem("a", true, ""); assertTrue(empty.isFromQuery()); assertTrue(empty.isStemmed()); diff --git a/container-search/src/test/java/com/yahoo/prelude/query/TaggableItemsTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/TaggableItemsTestCase.java index 3d16859a79d..ec2a69fb9b0 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/TaggableItemsTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/TaggableItemsTestCase.java @@ -1,18 +1,15 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.query; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import java.lang.reflect.Method; import java.util.HashSet; import java.util.Set; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Keep CompositeTaggableItem, SimpleTaggableItem and TaggableSegmentItem in @@ -22,11 +19,11 @@ import org.junit.Test; */ public class TaggableItemsTestCase { - @Before + @BeforeEach public void setUp() throws Exception { } - @After + @AfterEach public void tearDown() throws Exception { } @@ -97,7 +94,7 @@ public class TaggableItemsTestCase { } @Test - public void requireSimilarAPIs() { + void requireSimilarAPIs() { final Method[] composite = CompositeTaggableItem.class .getDeclaredMethods(); final Method[] simple = SimpleTaggableItem.class.getDeclaredMethods(); @@ -123,7 +120,7 @@ public class TaggableItemsTestCase { } @Test - public final void testSetUniqueID() { + final void testSetUniqueID() { final PhraseSegmentItem p = new PhraseSegmentItem("farmyards", false, false); assertFalse(p.hasUniqueID()); @@ -133,7 +130,7 @@ public class TaggableItemsTestCase { } @Test - public final void testSetConnectivity() { + final void testSetConnectivity() { final PhraseSegmentItem p = new PhraseSegmentItem("farmyards", false, false); assertEquals(0.0d, p.getConnectivity(), 1e-9); @@ -145,7 +142,7 @@ public class TaggableItemsTestCase { } @Test - public final void testSetSignificance() { + final void testSetSignificance() { final PhraseSegmentItem p = new PhraseSegmentItem("farmyards", false, false); // unset diff --git a/container-search/src/test/java/com/yahoo/prelude/query/WordAlternativesItemTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/WordAlternativesItemTestCase.java index 4f39e07f6d3..c246abb14da 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/WordAlternativesItemTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/WordAlternativesItemTestCase.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.prelude.query; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.List; -import org.junit.Test; - +import org.junit.jupiter.api.Test; import com.yahoo.prelude.query.WordAlternativesItem.Alternative; /** @@ -18,7 +18,7 @@ import com.yahoo.prelude.query.WordAlternativesItem.Alternative; public class WordAlternativesItemTestCase { @Test - public final void testWordAlternativesItem() { + final void testWordAlternativesItem() { List<Alternative> terms = new ArrayList<>(); List<Alternative> expected; terms.add(new Alternative("1", 1.0)); @@ -35,7 +35,7 @@ public class WordAlternativesItemTestCase { } @Test - public final void testSetAlternatives() { + final void testSetAlternatives() { List<Alternative> terms = new ArrayList<>(); terms.add(new Alternative("1", 1.0)); terms.add(new Alternative("2", 1.0)); @@ -43,19 +43,19 @@ public class WordAlternativesItemTestCase { terms.add(new Alternative("1", 1.5)); terms.add(new Alternative("2", 0.5)); w.setAlternatives(terms); - assertTrue("Could not overwrite alternative", - w.getAlternatives().stream().anyMatch((a) -> a.word.equals("1") && a.exactness == 1.5)); - assertTrue("Old alternative unexpectedly removed", - w.getAlternatives().stream().anyMatch((a) -> a.word.equals("2") && a.exactness == 1.0)); + assertTrue(w.getAlternatives().stream().anyMatch((a) -> a.word.equals("1") && a.exactness == 1.5), + "Could not overwrite alternative"); + assertTrue(w.getAlternatives().stream().anyMatch((a) -> a.word.equals("2") && a.exactness == 1.0), + "Old alternative unexpectedly removed"); assertEquals(2, w.getAlternatives().size()); terms.add(new Alternative("3", 0.5)); w.setAlternatives(terms); - assertTrue("Could not add new term", - w.getAlternatives().stream().anyMatch((a) -> a.word.equals("3") && a.exactness == 0.5)); + assertTrue(w.getAlternatives().stream().anyMatch((a) -> a.word.equals("3") && a.exactness == 0.5), + "Could not add new term"); } @Test - public final void testAddTerm() { + final void testAddTerm() { List<Alternative> terms = new ArrayList<>(); terms.add(new Alternative("1", 1.0)); terms.add(new Alternative("2", 1.0)); @@ -63,12 +63,12 @@ public class WordAlternativesItemTestCase { w.addTerm("1", 0.1); assertEquals(terms, w.getAlternatives()); w.addTerm("1", 2.0); - assertTrue("Could not add new alternative", - w.getAlternatives().stream().anyMatch((a) -> a.word.equals("1") && a.exactness == 2.0)); + assertTrue(w.getAlternatives().stream().anyMatch((a) -> a.word.equals("1") && a.exactness == 2.0), + "Could not add new alternative"); assertEquals(2, w.getAlternatives().size()); w.addTerm("3", 0.5); - assertTrue("Could not add new term", - w.getAlternatives().stream().anyMatch((a) -> a.word.equals("3") && a.exactness == 0.5)); + assertTrue(w.getAlternatives().stream().anyMatch((a) -> a.word.equals("3") && a.exactness == 0.5), + "Could not add new term"); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/query/parser/UnicodePropertyDumpTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/parser/UnicodePropertyDumpTestCase.java index 5e19f2e2ae6..40911fd6e11 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/parser/UnicodePropertyDumpTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/parser/UnicodePropertyDumpTestCase.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.prelude.query.parser; -import static org.junit.Assert.assertEquals; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Test UnicodePropertyDump gives expected data. @@ -17,7 +17,7 @@ import org.junit.Test; public class UnicodePropertyDumpTestCase { @Test - public final void testMain() throws IOException { + final void testMain() throws IOException { ByteArrayOutputStream toCheck; PrintStream out; toCheck = new ByteArrayOutputStream(); diff --git a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ExactMatchAndDefaultIndexTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ExactMatchAndDefaultIndexTestCase.java index a662afcd51c..cda966f714f 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ExactMatchAndDefaultIndexTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ExactMatchAndDefaultIndexTestCase.java @@ -7,14 +7,14 @@ import com.yahoo.prelude.IndexModel; import com.yahoo.prelude.SearchDefinition; import com.yahoo.search.Query; import com.yahoo.search.searchchain.Execution; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.Collections; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Check default index propagates correctly to the tokenizer. @@ -24,7 +24,7 @@ import static org.junit.Assert.assertEquals; public class ExactMatchAndDefaultIndexTestCase { @Test - public void testExactMatchTokenization() { + void testExactMatchTokenization() { SearchDefinition sd = new SearchDefinition("testsd"); Index index = new Index("testexact"); index.setExact(true, null); @@ -39,7 +39,7 @@ public class ExactMatchAndDefaultIndexTestCase { } @Test - public void testDefaultIndexSpecialChars() { + void testDefaultIndexSpecialChars() { Query q = new Query("?query=" + enc("dog & cat") + "&default-index=textsearch"); assertEquals("WEAKAND(100) textsearch:dog textsearch:cat", q.getModel().getQueryTree().getRoot().toString()); } diff --git a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParseTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParseTestCase.java index 77d8b2b973e..bd6b2f1f21d 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParseTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParseTestCase.java @@ -24,14 +24,11 @@ import com.yahoo.prelude.query.WordItem; import com.yahoo.language.process.SpecialTokens; import com.yahoo.prelude.query.parser.TestLinguistics; import com.yahoo.search.Query; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Iterator; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Tests query parsing. @@ -41,562 +38,562 @@ import static org.junit.Assert.assertTrue; public class ParseTestCase { private final ParsingTester tester = new ParsingTester(); - + @Test - public void testSimpleTermQuery() { + void testSimpleTermQuery() { tester.assertParsed("foobar", "foobar", Query.Type.ANY); } @Test - public void testTermWithIndexPrefix() { + void testTermWithIndexPrefix() { tester.assertParsed("url:foobar", - "url:foobar", - Query.Type.ANY); + "url:foobar", + Query.Type.ANY); } @Test - public void testTermWithCatalogAndIndexPrefix() { + void testTermWithCatalogAndIndexPrefix() { tester.assertParsed("normal.title:foobar", "normal.title:foobar", Query.Type.ANY); } @Test - public void testMultipleTermsWithUTF8EncodingOred() { + void testMultipleTermsWithUTF8EncodingOred() { tester.assertParsed("OR l\u00e5gen delta M\u00dcNICH M\u00fcnchen", - "l\u00e5gen delta M\u00dcNICH M\u00fcnchen", - Query.Type.ANY); + "l\u00e5gen delta M\u00dcNICH M\u00fcnchen", + Query.Type.ANY); } @Test - public void testMultipleTermsWithMultiplePrefixes() { + void testMultipleTermsWithMultiplePrefixes() { tester.assertParsed("RANK (+bar -normal.title:foo -baz) url:foobar", - "url:foobar +bar -normal.title:foo -baz", Query.Type.ANY); + "url:foobar +bar -normal.title:foo -baz", Query.Type.ANY); } @Test - public void testSimpleQueryDefaultOr() { + void testSimpleQueryDefaultOr() { tester.assertParsed("OR foobar foo bar baz", "foobar foo bar baz", Query.Type.ANY); } @Test - public void testOrAndNot() { + void testOrAndNot() { tester.assertParsed("RANK (+(AND baz bar) -xyzzy -foobaz) foobar foo", - "foobar +baz foo -xyzzy -foobaz +bar", Query.Type.ANY); + "foobar +baz foo -xyzzy -foobaz +bar", Query.Type.ANY); } @Test - public void testSimpleOrNestedAnd() { + void testSimpleOrNestedAnd() { tester.assertParsed("RANK (OR foo bar baz) foobar xyzzy", - "foobar +(foo bar baz) xyzzy", Query.Type.ANY); + "foobar +(foo bar baz) xyzzy", Query.Type.ANY); } @Test - public void testSimpleOrNestedNot() { + void testSimpleOrNestedNot() { tester.assertParsed("+(OR foobar xyzzy) -(AND foo bar baz)", - "foobar -(foo bar baz) xyzzy", Query.Type.ANY); + "foobar -(foo bar baz) xyzzy", Query.Type.ANY); } @Test - public void testOrNotNestedAnd() { + void testOrNotNestedAnd() { tester.assertParsed("RANK (+(AND baz (OR foo bar baz) bar) -xyzzy -foobaz) foobar foo", - "foobar +baz foo -xyzzy +(foo bar baz) -foobaz +bar", - Query.Type.ANY); + "foobar +baz foo -xyzzy +(foo bar baz) -foobaz +bar", + Query.Type.ANY); } @Test - public void testOrAndNotNestedNot() { + void testOrAndNotNestedNot() { tester.assertParsed("RANK (+(AND baz bar) -xyzzy -(AND foo bar baz) -foobaz) foobar foo", - "foobar +baz foo -xyzzy -(foo bar baz) -foobaz +bar", - Query.Type.ANY); + "foobar +baz foo -xyzzy -(foo bar baz) -foobaz +bar", + Query.Type.ANY); } @Test - public void testOrMultipleNestedAnd() { + void testOrMultipleNestedAnd() { tester.assertParsed("RANK (AND (OR fo ba foba) (OR foz baraz)) foobar foo bar baz", - "foobar +(fo ba foba) foo bar +(foz baraz) baz", - Query.Type.ANY); + "foobar +(fo ba foba) foo bar +(foz baraz) baz", + Query.Type.ANY); } @Test - public void testOrMultipleNestedNot() { + void testOrMultipleNestedNot() { tester.assertParsed("+(OR foobar foo bar baz) -(AND fo ba foba) -(AND foz baraz)", - "foobar -(fo ba foba) foo bar -(foz baraz) baz", - Query.Type.ANY); + "foobar -(fo ba foba) foo bar -(foz baraz) baz", + Query.Type.ANY); } @Test - public void testOrAndNotMultipleNestedAnd() { + void testOrAndNotMultipleNestedAnd() { tester.assertParsed("RANK (+(AND baz (OR foo bar baz) (OR foz bazaz) bar) -xyzzy -foobaz) foobar foo", - "foobar +baz foo -xyzzy +(foo bar baz) -foobaz +(foz bazaz) +bar", - Query.Type.ANY); + "foobar +baz foo -xyzzy +(foo bar baz) -foobaz +(foz bazaz) +bar", + Query.Type.ANY); } @Test - public void testOrAndNotMultipleNestedNot() { + void testOrAndNotMultipleNestedNot() { tester.assertParsed("RANK (+(AND baz bar) -xyzzy -(AND foo bar baz) -foobaz -(AND foz bazaz)) foobar foo", - "foobar +baz foo -xyzzy -(foo bar baz) -foobaz -(foz bazaz) +bar", - Query.Type.ANY); + "foobar +baz foo -xyzzy -(foo bar baz) -foobaz -(foz bazaz) +bar", + Query.Type.ANY); } @Test - public void testOrMultipleNestedAndNot() { + void testOrMultipleNestedAndNot() { tester.assertParsed("RANK (+(AND (OR ffoooo bbaarr) (OR oof rab raboof)) -(AND fo ba foba) -(AND foz baraz)) foobar foo bar baz", - "foobar -(fo ba foba) foo +(ffoooo bbaarr) bar +(oof rab raboof) -(foz baraz) baz", - Query.Type.ANY); + "foobar -(fo ba foba) foo +(ffoooo bbaarr) bar +(oof rab raboof) -(foz baraz) baz", + Query.Type.ANY); } @Test - public void testOrAndNotMultipleNestedAndNot() { + void testOrAndNotMultipleNestedAndNot() { tester.assertParsed("RANK (+(AND (OR ffoooo bbaarr) (OR oof rab raboof) baz xyxyzzy) -(AND fo ba foba) -foo -bar -(AND foz baraz)) foobar", - "foobar -(fo ba foba) -foo +(ffoooo bbaarr) -bar +(oof rab raboof) -(foz baraz) +baz +xyxyzzy", - Query.Type.ANY); + "foobar -(fo ba foba) -foo +(ffoooo bbaarr) -bar +(oof rab raboof) -(foz baraz) +baz +xyxyzzy", + Query.Type.ANY); } @Test - public void testExplicitPhrase() { + void testExplicitPhrase() { Item root = tester.assertParsed("\"foo bar foobar\"", "\"foo bar foobar\"", Query.Type.ANY); assertTrue(root instanceof PhraseItem); - assertTrue(((PhraseItem)root).isExplicit()); + assertTrue(((PhraseItem) root).isExplicit()); } @Test - public void testPhraseWithIndex() { + void testPhraseWithIndex() { tester.assertParsed("normal.title:\"foo bar foobar\"", - "normal.title:\"foo bar foobar\"", Query.Type.ANY); + "normal.title:\"foo bar foobar\"", Query.Type.ANY); } @Test - public void testPhrasesAndTerms() { + void testPhrasesAndTerms() { tester.assertParsed("OR \"foo bar foobar\" xyzzy \"baz gaz faz\"", - "\"foo bar foobar\" xyzzy \"baz gaz faz\"", Query.Type.ANY); + "\"foo bar foobar\" xyzzy \"baz gaz faz\"", Query.Type.ANY); } @Test - public void testPhrasesAndTermsWithOperators() { + void testPhrasesAndTermsWithOperators() { tester.assertParsed("RANK (+(AND \"baz gaz faz\" bazar) -\"foo bar foobar\") foofoo xyzzy", - "foofoo -\"foo bar foobar\" xyzzy +\"baz gaz faz\" +bazar", - Query.Type.ANY); + "foofoo -\"foo bar foobar\" xyzzy +\"baz gaz faz\" +bazar", + Query.Type.ANY); } @Test - public void testSimpleTermQueryDefaultAnd() { + void testSimpleTermQueryDefaultAnd() { tester.assertParsed("foobar", "foobar", Query.Type.ALL); } @Test - public void testTermWithCatalogAndIndexPrefixDefaultAnd() { + void testTermWithCatalogAndIndexPrefixDefaultAnd() { tester.assertParsed("normal.title:foobar", "normal.title:foobar", Query.Type.ALL); } @Test - public void testMultipleTermsWithMultiplePrefixesDefaultAnd() { + void testMultipleTermsWithMultiplePrefixesDefaultAnd() { tester.assertParsed("+(AND url:foobar bar) -normal.title:foo -baz", - "url:foobar +bar -normal.title:foo -baz", - Query.Type.ALL); + "url:foobar +bar -normal.title:foo -baz", + Query.Type.ALL); } @Test - public void testSimpleQueryDefaultAnd() { + void testSimpleQueryDefaultAnd() { tester.assertParsed("AND foobar foo bar baz", "foobar foo bar baz", Query.Type.ALL); } @Test - public void testNotDefaultAnd() { + void testNotDefaultAnd() { tester.assertParsed("+(AND foobar (OR foo bar baz) xyzzy) -(AND foz baraz bazar)", - "foobar +(foo bar baz) xyzzy -(foz baraz bazar)", - Query.Type.ALL); + "foobar +(foo bar baz) xyzzy -(foz baraz bazar)", + Query.Type.ALL); } @Test - public void testSimpleTermQueryDefaultPhrase() { + void testSimpleTermQueryDefaultPhrase() { tester.assertParsed("foobar", - "foobar", - Query.Type.PHRASE); + "foobar", + Query.Type.PHRASE); } @Test - public void testSimpleQueryDefaultPhrase() { + void testSimpleQueryDefaultPhrase() { Item root = tester.assertParsed("\"foobar foo bar baz\"", - "foobar foo bar baz", - Query.Type.PHRASE); + "foobar foo bar baz", + Query.Type.PHRASE); assertTrue(root instanceof PhraseItem); - assertFalse(((PhraseItem)root).isExplicit()); + assertFalse(((PhraseItem) root).isExplicit()); } @Test - public void testMultipleTermsWithMultiplePrefixesDefaultPhrase() { + void testMultipleTermsWithMultiplePrefixesDefaultPhrase() { tester.assertParsed("\"url foobar bar normal title foo baz\"", - "url:foobar +bar -normal.title:foo -baz", - Query.Type.PHRASE); + "url:foobar +bar -normal.title:foo -baz", + Query.Type.PHRASE); } @Test - public void testOdd1() { + void testOdd1() { tester.assertParsed("AND window print error", "+window.print() +error", - Query.Type.ALL); + Query.Type.ALL); } @Test - public void testOdd2() { + void testOdd2() { tester.assertParsed("normal.title:kaboom", "normal.title:\"kaboom\"", - Query.Type.ALL); + Query.Type.ALL); } @Test - public void testOdd2Uppercase() { + void testOdd2Uppercase() { tester.assertParsed("normal.title:KABOOM", "NORMAL.TITLE:\"KABOOM\"", Query.Type.ALL); } @Test - public void testOdd3() { + void testOdd3() { tester.assertParsed("AND foo (OR size.all:[200;300] date.all:512)", "foo +(size.all:[200;300] date.all:512)", Query.Type.ALL); } @Test - public void testNullQuery() { + void testNullQuery() { tester.assertParsed(null, null, Query.Type.ALL); } @Test - public void testEmptyQuery() { + void testEmptyQuery() { tester.assertParsed(null, "", Query.Type.ALL); } @Test - public void testNotOnly() { + void testNotOnly() { tester.assertParsed(null, "-foobar", Query.Type.ALL); } @Test - public void testMultipleNotsOnlt() { + void testMultipleNotsOnlt() { tester.assertParsed(null, "-foo -bar -foobar", Query.Type.ALL); } @Test - public void testOnlyNotComposite() { + void testOnlyNotComposite() { tester.assertParsed(null, "-(foo bar baz)", Query.Type.ALL); } @Test - public void testNestedCompositesDefaultOr() { + void testNestedCompositesDefaultOr() { tester.assertParsed("RANK (OR foobar bar baz) foo xyzzy", - "foo +(foobar +(bar baz)) xyzzy", Query.Type.ANY); + "foo +(foobar +(bar baz)) xyzzy", Query.Type.ANY); } @Test - public void testNestedCompositesDefaultAnd() { + void testNestedCompositesDefaultAnd() { tester.assertParsed("AND foo (OR foobar bar baz) xyzzy", - "foo +(foobar +(bar baz)) xyzzy", Query.Type.ALL); + "foo +(foobar +(bar baz)) xyzzy", Query.Type.ALL); } @Test - public void testNestedCompositesPhraseDefault() { + void testNestedCompositesPhraseDefault() { tester.assertParsed("\"foo foobar bar baz xyzzy\"", - "foo +(foobar +(bar baz)) xyzzy", Query.Type.PHRASE); + "foo +(foobar +(bar baz)) xyzzy", Query.Type.PHRASE); } @Test - public void testNumeric() { + void testNumeric() { tester.assertParsed("34", "34", Query.Type.ANY); } @Test - public void testGreaterNumeric() { + void testGreaterNumeric() { tester.assertParsed("<454", "<454", Query.Type.ANY); } @Test - public void testGreaterNumericWithIndex() { - IntItem item = (IntItem)tester.assertParsed("score:<454", "score:<454", Query.Type.ANY); + void testGreaterNumericWithIndex() { + IntItem item = (IntItem) tester.assertParsed("score:<454", "score:<454", Query.Type.ANY); assertEquals("score", item.getIndexName()); assertEquals(454L, item.getToLimit().number()); assertFalse(item.getToLimit().isInclusive()); } @Test - public void testSmallerNumeric() { + void testSmallerNumeric() { tester.assertParsed(">454", ">454", Query.Type.ANY); } @Test - public void testSmallerNumericWithIndex() { - IntItem item = (IntItem)tester.assertParsed("score:>454", "score:>454", Query.Type.ANY); + void testSmallerNumericWithIndex() { + IntItem item = (IntItem) tester.assertParsed("score:>454", "score:>454", Query.Type.ANY); assertEquals("score", item.getIndexName()); assertEquals(454L, item.getFromLimit().number()); assertFalse(item.getFromLimit().isInclusive()); } @Test - public void testFullRange() { + void testFullRange() { tester.assertParsed("[34;454]", "[34;454]", Query.Type.ANY); } @Test - public void testFullRangeLimit() { + void testFullRangeLimit() { tester.assertParsed("[34;454;7]", "[34;454;7]", Query.Type.ANY); tester.assertParsed("[34;454;-7]", "[34;454;-7]", Query.Type.ANY); } @Test - public void testLowOpenRange() { + void testLowOpenRange() { tester.assertParsed("[;454]", "[;454]", Query.Type.ANY); } @Test - public void testHiOpenRange() { + void testHiOpenRange() { tester.assertParsed("[34;]", "[34;]", Query.Type.ANY); } @Test - public void testNumericWithIndex() { + void testNumericWithIndex() { tester.assertParsed("document.size:[34;454]", "document.size:[34;454]", Query.Type.ANY); } @Test - public void testMultipleNumeric() { + void testMultipleNumeric() { tester.assertParsed("OR [34;454] <34", "[34;454] <34", Query.Type.ANY); } @Test - public void testMultipleIntegerWithIndex() { + void testMultipleIntegerWithIndex() { tester.assertParsed("OR document.size:[34;454] date:>1234567890", - "document.size:[34;454] date:>1234567890", Query.Type.ANY); + "document.size:[34;454] date:>1234567890", Query.Type.ANY); } @Test - public void testMixedNumericAndOtherTerms() { + void testMixedNumericAndOtherTerms() { tester.assertParsed("RANK (AND document.size:<1024 xyzzy) foo date:>123456890", - "foo +document.size:<1024 +xyzzy date:>123456890", - Query.Type.ANY); + "foo +document.size:<1024 +xyzzy date:>123456890", + Query.Type.ANY); } @Test - public void testEmptyPhrase() { + void testEmptyPhrase() { tester.assertParsed("\"to be or not\"", "\"\"to be or not", Query.Type.ANY); } @Test - public void testItemPhraseEmptyPhrase() { + void testItemPhraseEmptyPhrase() { tester.assertParsed("RANK to \"or not to be\"", "+to\"or not to be\"\"\"", Query.Type.ANY); } @Test - public void testSimpleQuery() { + void testSimpleQuery() { tester.assertParsed("OR if am \"f g 4 2\" maybe", "if am \" f g 4 2\"\" maybe", Query.Type.ANY); } @Test - public void testExcessivePluses() { + void testExcessivePluses() { tester.assertParsed("+(AND other is nothing) -test", - "++other +++++is ++++++nothing -test", Query.Type.ANY); + "++other +++++is ++++++nothing -test", Query.Type.ANY); } @Test - public void testMinusAndPluses() { + void testMinusAndPluses() { tester.assertParsed(null, "--test+-if", Query.Type.ANY); } @Test - public void testPlusesAndMinuses() { + void testPlusesAndMinuses() { tester.assertParsed("AND a b c d d", "a+b+c+d--d", Query.Type.ANY); } @Test - public void testNumbers() { + void testNumbers() { tester.assertParsed("AND 123 2132odfd 934032 32423", "123+2132odfd.934032,,32423", Query.Type.ANY); } @Test - public void testOtherSignsInQuote() { + void testOtherSignsInQuote() { tester.assertParsed("AND 0032 4 320 24329043", "0032+4\\320.24329043", Query.Type.ANY); } @Test - public void testGribberish() { + void testGribberish() { tester.assertParsed("1349832840234l3040roer\u00e6lf12", - ",1349832840234l3040roer\u00e6lf12", - Query.Type.ANY); + ",1349832840234l3040roer\u00e6lf12", + Query.Type.ANY); } @Test - public void testUrl() { + void testUrl() { tester.assertParsed("AND www:www www:hotelaiguablava www:com", - "+www:www.hotelaiguablava:com", - Query.Type.ANY); + "+www:www.hotelaiguablava:com", + Query.Type.ANY); } @Test - public void testUrlGribberish() { + void testUrlGribberish() { tester.assertParsed("OR (AND 3 16) fast.type:lycosoffensive", - "[ 3:16 fast.type:lycosoffensive", - Query.Type.ANY); + "[ 3:16 fast.type:lycosoffensive", + Query.Type.ANY); } @Test - public void testBracedWordAny() { + void testBracedWordAny() { tester.assertParsed("foo", "(foo)", Query.Type.ANY); } @Test - public void testBracedWordAll() { + void testBracedWordAll() { tester.assertParsed("foo", "(foo)", Query.Type.ALL); } @Test - public void testBracedWords() { + void testBracedWords() { tester.assertParsed("OR (OR foo bar) (OR xyzzy foobar)", "(foo bar) (xyzzy foobar)", Query.Type.ANY); } @Test - public void testNullAdvanced() { + void testNullAdvanced() { tester.assertParsed(null, null, Query.Type.ADVANCED); } @Test - public void testEmptyAdvanced() { + void testEmptyAdvanced() { tester.assertParsed(null, "", Query.Type.ADVANCED); } @Test - public void testSimpleAdvanced() { + void testSimpleAdvanced() { tester.assertParsed("foobar", "foobar", Query.Type.ADVANCED); } @Test - public void testPrefixAdvanced() { + void testPrefixAdvanced() { tester.assertParsed("url:foobar", "url:foobar", Query.Type.ADVANCED); } @Test - public void testPrefixWithDotAdvanced() { + void testPrefixWithDotAdvanced() { tester.assertParsed("normal.title:foobar", "normal.title:foobar", Query.Type.ADVANCED); } @Test - public void testUTF8Advanced() { + void testUTF8Advanced() { tester.assertParsed("m\u00fcnchen", "m\u00fcnchen", Query.Type.ADVANCED); } @Test - public void testSimplePhraseAdvanced() { + void testSimplePhraseAdvanced() { tester.assertParsed("\"foo bar foobar\"", "\"foo bar foobar\"", Query.Type.ADVANCED); } @Test - public void testSimplePhraseWithIndexAdvanced() { + void testSimplePhraseWithIndexAdvanced() { tester.assertParsed("normal.title:\"foo bar foobar\"", - "normal.title:\"foo bar foobar\"", - Query.Type.ADVANCED); + "normal.title:\"foo bar foobar\"", + Query.Type.ADVANCED); } @Test - public void testMultiplePhrasesAdvanced() { + void testMultiplePhrasesAdvanced() { tester.assertParsed("AND \"foo bar foobar\" \"baz gaz faz\"", - "\"foo bar foobar\" and \"baz gaz faz\"", - Query.Type.ADVANCED); + "\"foo bar foobar\" and \"baz gaz faz\"", + Query.Type.ADVANCED); } @Test - public void testNumberAdvanced() { + void testNumberAdvanced() { tester.assertParsed("34", "34", Query.Type.ADVANCED); } @Test - public void testLargerNumberAdvanced() { + void testLargerNumberAdvanced() { tester.assertParsed("<454", "<454", Query.Type.ADVANCED); } @Test - public void testLesserNumberAdvanced() { + void testLesserNumberAdvanced() { tester.assertParsed(">454", ">454", Query.Type.ADVANCED); } @Test - public void testRangeAdvanced() { + void testRangeAdvanced() { tester.assertParsed("[34;454]", "[34;454]", Query.Type.ADVANCED); } @Test - public void testLowOpenRangeAdvanced() { + void testLowOpenRangeAdvanced() { tester.assertParsed("[;454]", "[;454]", Query.Type.ADVANCED); } @Test - public void testHighOpenRangeAdvanced() { + void testHighOpenRangeAdvanced() { tester.assertParsed("[34;]", "[34;]", Query.Type.ADVANCED); } @Test - public void testIdexedRangeAdvanced() { + void testIdexedRangeAdvanced() { tester.assertParsed("document.size:[34;454]", "document.size:[34;454]", Query.Type.ADVANCED); } @Test - public void testSimpleAndAdvanced() { + void testSimpleAndAdvanced() { tester.assertParsed("AND foo bar", "foo and bar", Query.Type.ADVANCED); } @Test - public void testSimpleOrAdvanced() { + void testSimpleOrAdvanced() { tester.assertParsed("OR foo bar", "foo or bar", Query.Type.ADVANCED); } @Test - public void testSimpleAndNotAdvanced() { + void testSimpleAndNotAdvanced() { tester.assertParsed("+foo -bar", "foo andnot bar", Query.Type.ADVANCED); } @Test - public void testSimpleRankAdvanced() { + void testSimpleRankAdvanced() { tester.assertParsed("RANK foo bar", "foo rank bar", Query.Type.ADVANCED); } @Test - public void testMultipleAndAdvanced() { + void testMultipleAndAdvanced() { tester.assertParsed("AND foo bar foobar", "foo and bar and foobar", Query.Type.ADVANCED); } @Test - public void testMultipleOrAdvanced() { + void testMultipleOrAdvanced() { tester.assertParsed("OR foo bar foobar", "foo or bar or foobar", Query.Type.ADVANCED); } @Test - public void testMultipleAndnotAdvanced() { + void testMultipleAndnotAdvanced() { tester.assertParsed("+foo -bar -foobar", "foo andnot bar andnot foobar", Query.Type.ADVANCED); } @Test - public void testMultipleRankAdvanced() { + void testMultipleRankAdvanced() { tester.assertParsed("RANK foo bar foobar", "foo rank bar rank foobar", Query.Type.ADVANCED); } @Test - public void testMixedAdvanced() { + void testMixedAdvanced() { tester.assertParsed("OR (AND foo bar) foobar", "foo and bar or foobar", Query.Type.ADVANCED); } @Test - public void testNestedAdvanced() { + void testNestedAdvanced() { tester.assertParsed("AND foo (OR bar foobar)", "foo and (bar or foobar)", Query.Type.ADVANCED); } @Test - public void testMultipleNestedAdvanced() { + void testMultipleNestedAdvanced() { tester.assertParsed("+(AND foo xyzzy) -(OR bar foobar)", - "(foo and xyzzy) andnot (bar or foobar)", Query.Type.ADVANCED); + "(foo and xyzzy) andnot (bar or foobar)", Query.Type.ADVANCED); } @Test - public void testDoubleNestedAdvanced() { + void testDoubleNestedAdvanced() { tester.assertParsed("AND foo (OR bar (OR xyzzy foobar))", - "foo and (bar or (xyzzy or foobar))", Query.Type.ADVANCED); + "foo and (bar or (xyzzy or foobar))", Query.Type.ADVANCED); } @Test - public void testDeeplyAdvanced() { + void testDeeplyAdvanced() { tester.assertParsed( "AND foo (OR bar (OR (AND (AND baz (+(OR bazar zyxxy) -fozbaz)) (OR boz bozor) xyzzy) foobar))", "foo and (bar or ((baz and ((bazar or zyxxy) andnot fozbaz)) and (boz or bozor) and xyzzy or foobar))", @@ -604,7 +601,7 @@ public class ParseTestCase { } @Test - public void testDeeplyAdvancedUppercase() { + void testDeeplyAdvancedUppercase() { tester.assertParsed( "AND FOO (OR BAR (OR (AND (AND BAZ (+(OR BAZAR ZYXXY) -FOZBAZ)) (OR BOZ BOZOR) XYZZY) FOOBAR))", "FOO AND (BAR OR ((BAZ AND ((BAZAR OR ZYXXY) ANDNOT FOZBAZ)) AND (BOZ OR BOZOR) AND XYZZY OR FOOBAR))", @@ -612,230 +609,230 @@ public class ParseTestCase { } @Test - public void testAbortedIntegerRange() { + void testAbortedIntegerRange() { tester.assertParsed("AND audio.audall:744 audio.audall:ph", "+audio.audall:[744 +audio.audall:ph", Query.Type.ANY); } @Test - public void testJunk() { + void testJunk() { tester.assertParsed("+l -fast.type:offensive", ",;'/.<l:>? -fast.type:offensive", Query.Type.ALL); } @Test - public void testOneTermPhraseWithIndex() { + void testOneTermPhraseWithIndex() { tester.assertParsed("normal.title:foo", "normal.title:\"foo\"", Query.Type.ANY); } @Test - public void testOneTermPhraseWithIndexAdvanced() { + void testOneTermPhraseWithIndexAdvanced() { tester.assertParsed("normal.title:foo", "normal.title:\"foo\"", Query.Type.ADVANCED); } @Test - public void testIncorrect1Advanced() { + void testIncorrect1Advanced() { tester.assertParsed("\"to be or not\"", "\"\"to be or not", Query.Type.ADVANCED); } @Test - public void testIncorrect2Advanced() { + void testIncorrect2Advanced() { tester.assertParsed("AND to \"or not to be\"", "+to\"or not to be\"\"\"", Query.Type.ADVANCED); } @Test - public void testIncorrect3Advanced() { + void testIncorrect3Advanced() { tester.assertParsed("AND if am \"f g 4 2\" maybe", "if am \" f g 4 2\"\" maybe", Query.Type.ADVANCED); } @Test - public void testIncorrect4Advanced() { + void testIncorrect4Advanced() { tester.assertParsed("AND other is nothing test", "++other +++++is ++++++nothing -test", Query.Type.ADVANCED); } @Test - public void testImplicitPhrase1Advanced() { + void testImplicitPhrase1Advanced() { tester.assertParsed("AND test if", "--test+-if", Query.Type.ADVANCED); } @Test - public void testImplicitPhrase2Advanced() { + void testImplicitPhrase2Advanced() { tester.assertParsed("AND a b c d d", "a+b+c+d--d", Query.Type.ADVANCED); } @Test - public void testImplicitPhrase3Advanced() { + void testImplicitPhrase3Advanced() { tester.assertParsed("AND 123 2132odfd 934032 32423", "123+2132odfd.934032,,32423", Query.Type.ADVANCED); } @Test - public void testImplicitPhrase4Advanced() { + void testImplicitPhrase4Advanced() { tester.assertParsed("AND 0032 4 320 24329043", "0032+4\\320.24329043", Query.Type.ADVANCED); } @Test - public void testUtf8Advanced() { + void testUtf8Advanced() { tester.assertParsed("1349832840234l3040roer\u00e6lf12", ",1349832840234l3040roer\u00e6lf12", Query.Type.ADVANCED); } @Test - public void testOperatorSearchAdvanced() { + void testOperatorSearchAdvanced() { tester.assertParsed("RANK (OR (AND and and) or andnot) rank", "and and and or or or andnot rank rank", Query.Type.ADVANCED); } @Test - public void testIncorrectParenthesisAdvanced() { + void testIncorrectParenthesisAdvanced() { tester.assertParsed("AND foo bar", "foo and bar )", Query.Type.ADVANCED); } @Test - public void testOpeningParenthesisOnlyAdvanced() { + void testOpeningParenthesisOnlyAdvanced() { tester.assertParsed("AND foo (OR bar (AND foobar xyzzy))", "(foo and (bar or (foobar and xyzzy", Query.Type.ADVANCED); } @Test - public void testSimpleWeight() { + void testSimpleWeight() { tester.assertParsed("foo!150", "foo!", Query.Type.ANY); } @Test - public void testMultipleWeight() { + void testMultipleWeight() { tester.assertParsed("foo!250", "foo!!!", Query.Type.ANY); } @Test - public void testExplicitWeight() { + void testExplicitWeight() { tester.assertParsed("foo!200", "foo!200", Query.Type.ANY); } @Test - public void testExplicitZeroWeight() { + void testExplicitZeroWeight() { tester.assertParsed("foo!0", "foo!0", Query.Type.ANY); } @Test - public void testSimplePhraseWeight() { + void testSimplePhraseWeight() { tester.assertParsed("\"foo bar\"!150", "\"foo bar\"!", Query.Type.ANY); } @Test - public void testSingleHyphen() { + void testSingleHyphen() { tester.assertParsed("AND a b", "a-b", Query.Type.ALL); } @Test - public void testUserCase() { + void testUserCase() { tester.assertParsed("\"a a\"", "\"a- a-*\"", Query.Type.ALL); } @Test - public void testMultiplePhraseWeight() { + void testMultiplePhraseWeight() { tester.assertParsed("\"foo bar\"!250", "\"foo bar\"!!!", Query.Type.ANY); } @Test - public void testExplicitPhraseWeight() { + void testExplicitPhraseWeight() { tester.assertParsed("\"foo bar\"!200", "\"foo bar\"!200", Query.Type.ANY); } @Test - public void testUrlSubmodeHyphen() { + void testUrlSubmodeHyphen() { assertTrue(ParsingTester.createIndexFacts().newSession(new Query()).getIndex("url.all").isUriIndex()); tester.assertParsed("url.all:\"www-microsoft com\"", "url.all:www-microsoft.com", Query.Type.ANY); } @Test - public void testUrlSubmodeUnderscore() { + void testUrlSubmodeUnderscore() { tester.assertParsed("url.all:\"www_microsoft com\"", "url.all:www_microsoft.com", Query.Type.ANY); } @Test - public void testUrlSubmode() { + void testUrlSubmode() { tester.assertParsed("host.all:\"www-microsoft com $\"", "host.all:www-microsoft.com", Query.Type.ANY); } @Test - public void testExplicitHostNameAnchoringHost() { + void testExplicitHostNameAnchoringHost() { tester.assertParsed("host.all:\"^ www-microsoft com $\"", "host.all:^www-microsoft.com$", Query.Type.ANY); } @Test - public void testExplicitHostNameAnchoringSite() { + void testExplicitHostNameAnchoringSite() { tester.assertParsed("site:\"^ www-microsoft com $\"", "site:^www-microsoft.com$", Query.Type.ANY); } @Test - public void testExplicitHostNameAnchoring() { + void testExplicitHostNameAnchoring() { tester.assertParsed("host.all:\"^ http www krangaz-central com index html $\"", "host.all:^http://www.krangaz-central.com/index.html$", Query.Type.ANY); } @Test - public void testExplicitHostAnchoringRemoval() { + void testExplicitHostAnchoringRemoval() { tester.assertParsed("host.all:\"www-microsoft com\"", "host.all:www-microsoft.com*", Query.Type.ANY); } @Test - public void testQuery1Any() { + void testQuery1Any() { tester.assertParsed("RANK (AND fast \"search engine\") kernel", "+fast +\"search engine\" kernel", Query.Type.ANY); } @Test - public void testQuery1Advanced() { + void testQuery1Advanced() { tester.assertParsed("RANK (AND fast \"search engine\") kernel", "+fast and \"search engine\" rank kernel", Query.Type.ADVANCED); } @Test - public void testQuery2Any() { + void testQuery2Any() { tester.assertParsed("+(OR title:car bmw) -z3", "title:car bmw -z3", Query.Type.ANY); } @Test - public void testQuery2Advanced() { + void testQuery2Advanced() { tester.assertParsed("+(OR title:car bmw) -z3", "title:car or bmw andnot z3", Query.Type.ADVANCED); } @Test - public void testQuery3All() { + void testQuery3All() { tester.assertParsed("+(AND FAST search domain:no pagedepth:0) -title:phrase", - "FAST search -title:phrase domain:no Pagedepth:0", - Query.Type.ALL); + "FAST search -title:phrase domain:no Pagedepth:0", + Query.Type.ALL); } @Test - public void testQuery4Advanced() { + void testQuery4Advanced() { tester.assertParsed("AND (+(AND FAST search) -title:phrase) domain:no pagedepth:0", - "FAST and search andnot title:phrase and domain:no and Pagedepth:0", - Query.Type.ADVANCED); + "FAST and search andnot title:phrase and domain:no and Pagedepth:0", + Query.Type.ADVANCED); } @Test - public void testQuery5Any() { + void testQuery5Any() { tester.assertParsed("AND alltheweb fast search", "+alltheweb +fast +search", Query.Type.ANY); } @Test - public void testQuery6Any() { + void testQuery6Any() { tester.assertParsed("RANK (+(AND query language) -sql) search", "+query +language -sql search", Query.Type.ANY); } @Test - public void testQuery7Any() { + void testQuery7Any() { tester.assertParsed( "+(AND alltheweb (OR search engine)) -(OR excite altavista)", "(alltheweb and (search or engine)) andnot (excite or altavista)", @@ -843,7 +840,7 @@ public class ParseTestCase { } @Test - public void testQuery8Advanced() { + void testQuery8Advanced() { tester.assertParsed( "RANK (AND \"search engines\" \"query processing\") \"fast search\"", "(\"search engines\" and \"query processing\") rank \"fast search\"", @@ -851,132 +848,132 @@ public class ParseTestCase { } @Test - public void testPStrangeAdvanced() { + void testPStrangeAdvanced() { tester.assertParsed("AND AND r.s:jnl", "( AND +r.s:jnl) ", Query.Type.ADVANCED); } @Test - public void testEmptyNestAdvanced() { + void testEmptyNestAdvanced() { tester.assertParsed(null, "() ", Query.Type.ADVANCED); } @Test - public void testNestedBeginningAdvanced() { + void testNestedBeginningAdvanced() { tester.assertParsed("AND (OR a b) c", "(a or b) and c", Query.Type.ADVANCED); } @Test - public void testNestedPositiveAny() { + void testNestedPositiveAny() { tester.assertParsed("AND (OR a b) c", "+(a b) +c", Query.Type.ANY); } @Test - public void testParseAdvancedQuery() { + void testParseAdvancedQuery() { tester.assertParsed("AND joplin remediation r.s:jnl", "(joplin and + and remediation and +r.s:jnl)", Query.Type.ADVANCED); } @Test - public void testSimpleDotPhraseAny() { + void testSimpleDotPhraseAny() { tester.assertParsed("OR a (AND b c) d", "a b.c d", Query.Type.ANY); } @Test - public void testSimpleHyphenPhraseAny() { + void testSimpleHyphenPhraseAny() { tester.assertParsed("OR a (AND b c) d", "a b-c d", Query.Type.ANY); } @Test - public void testAnotherSimpleDotPhraseAny() { + void testAnotherSimpleDotPhraseAny() { tester.assertParsed("OR (AND a b) c d", "a.b c d", Query.Type.ANY); } @Test - public void testYetAnotherSimpleDotPhraseAny() { + void testYetAnotherSimpleDotPhraseAny() { tester.assertParsed("OR a b (AND c d)", "a b c.d", Query.Type.ANY); } @Test - public void testVariousSeparatorsPhraseAny() { + void testVariousSeparatorsPhraseAny() { tester.assertParsed("AND a b c d", "a-b.c%d", Query.Type.ANY); } @Test - public void testDoublyMarkedPhraseAny() { + void testDoublyMarkedPhraseAny() { tester.assertParsed("OR a \"b c\" d", "a \"b.c\" d", Query.Type.ANY); } @Test - public void testPartlyDoublyMarkedPhraseAny() { + void testPartlyDoublyMarkedPhraseAny() { tester.assertParsed("OR a \"b c d\"", "a \"b.c d\"", Query.Type.ANY); } @Test - public void testIndexedDottedPhraseAny() { + void testIndexedDottedPhraseAny() { tester.assertParsed("OR a (AND url:b url:c) d", "a url:b.c d", Query.Type.ANY); } @Test - public void testIndexedPlusedPhraseAny() { + void testIndexedPlusedPhraseAny() { tester.assertParsed("OR a (AND normal.title:b normal.title:c) d", "a normal.title:b+c d", Query.Type.ANY); } @Test - public void testNestedNotAny() { + void testNestedNotAny() { tester.assertParsed( "RANK (+(OR normal.title:foobar (AND url:www url:pvv url:org)) -foo) a", "a +(normal.title:foobar url:www.pvv.org) -foo", Query.Type.ANY); } @Test - public void testDottedPhraseAdvanced() { + void testDottedPhraseAdvanced() { tester.assertParsed("OR a (AND b c)", "a or b.c", Query.Type.ADVANCED); } @Test - public void testHyphenPhraseAdvanced() { + void testHyphenPhraseAdvanced() { tester.assertParsed("OR (AND a (AND b c)) d", "a and b-c or d", Query.Type.ADVANCED); } @Test - public void testAnotherDottedPhraseAdvanced() { + void testAnotherDottedPhraseAdvanced() { tester.assertParsed("OR (AND a b) c", "a.b or c", Query.Type.ADVANCED); } @Test - public void testNottedDottedPhraseAdvanced() { + void testNottedDottedPhraseAdvanced() { tester.assertParsed("+a -(AND c d)", "a andnot c.d", Query.Type.ADVANCED); } @Test - public void testVariousSeparatorsPhraseAdvanced() { + void testVariousSeparatorsPhraseAdvanced() { tester.assertParsed("AND a b c d", "a-b.c%d", Query.Type.ADVANCED); } @Test - public void testDoublyPhrasedAdvanced() { + void testDoublyPhrasedAdvanced() { tester.assertParsed("OR (AND a \"b c\") d", "a and \"b.c\" or d", Query.Type.ADVANCED); } @Test - public void testPartlyDoublyPhrasedAdvanced() { + void testPartlyDoublyPhrasedAdvanced() { tester.assertParsed("OR a \"b c d\"", "a or \"b.c d\"", Query.Type.ADVANCED); } @Test - public void testNestedDottedPhraseAdvanced() { + void testNestedDottedPhraseAdvanced() { tester.assertParsed("AND a (OR url:\"b c\" d)", "a and(url:\"b.c\" or d)", Query.Type.ADVANCED); } @Test - public void testNestedPlussedPhraseAdvanced() { + void testNestedPlussedPhraseAdvanced() { tester.assertParsed("AND (OR a (AND normal.title:b normal.title:c)) d", "a or normal.title:b+c and d", Query.Type.ADVANCED); } @Test - public void testNottedNestedDottedPhraseAdvanced() { + void testNottedNestedDottedPhraseAdvanced() { tester.assertParsed( "+(AND a (OR normal.title:foobar (AND url:www url:pvv url:org))) -foo", "a and (normal.title:foobar or url:www.pvv.org) andnot foo", @@ -984,570 +981,570 @@ public class ParseTestCase { } @Test - public void testPlusedThenQuotedPhraseAny() { + void testPlusedThenQuotedPhraseAny() { tester.assertParsed("\"a b c\"", "a+\"b c\"", Query.Type.ANY); } @Test - public void testPlusedTwiceThenQuotedPhraseAny() { + void testPlusedTwiceThenQuotedPhraseAny() { tester.assertParsed("AND a b c d", "a+b+\"c d\"", Query.Type.ANY); } @Test - public void testPlusedThenQuotedPhraseAdvanced() { + void testPlusedThenQuotedPhraseAdvanced() { tester.assertParsed("\"a b c\"", "a+\"b c\"", Query.Type.ADVANCED); } @Test - public void testPhrasesInBraces() { + void testPhrasesInBraces() { tester.assertParsed("AND url.domain:microsoft url.domain:com", "+(url.domain:microsoft.com)", Query.Type.ALL); } @Test - public void testDoublyPhrasedPhrasesInBraces() { + void testDoublyPhrasedPhrasesInBraces() { tester.assertParsed("url.domain:\"microsoft com\"", "+(url.domain:\"microsoft.com\")", Query.Type.ALL); } @Test - public void testSinglePrefixTerm() { + void testSinglePrefixTerm() { Item root = tester.assertParsed("prefix*", "prefix*", Query.Type.ANY); assertTrue(root instanceof PrefixItem); } @Test - public void testSingleSubstringTerm() { + void testSingleSubstringTerm() { Item root = tester.assertParsed("*substring*", "*substring*", Query.Type.ANY); assertTrue(root instanceof SubstringItem); } @Test - public void testSingleSuffixTerm() { + void testSingleSuffixTerm() { Item root = tester.assertParsed("*suffix", "*suffix", Query.Type.ANY); assertTrue(root instanceof SuffixItem); } @Test - public void testPrefixAndWordTerms() { + void testPrefixAndWordTerms() { Item root = tester.assertParsed("OR foo prefix* bar", "foo prefix* bar", Query.Type.ANY); - assertTrue(((OrItem)root).getItem(1) instanceof PrefixItem); + assertTrue(((OrItem) root).getItem(1) instanceof PrefixItem); } @Test - public void testSubstringAndWordTerms() { + void testSubstringAndWordTerms() { Item root = tester.assertParsed("OR foo *substring* bar", "foo *substring* bar", Query.Type.ANY); - assertTrue(((OrItem)root).getItem(1) instanceof SubstringItem); + assertTrue(((OrItem) root).getItem(1) instanceof SubstringItem); } @Test - public void testSuffixAndWordTerms() { + void testSuffixAndWordTerms() { Item root = tester.assertParsed("OR foo *suffix bar", "foo *suffix bar", Query.Type.ANY); - assertTrue(((OrItem)root).getItem(1) instanceof SuffixItem); + assertTrue(((OrItem) root).getItem(1) instanceof SuffixItem); } @Test - public void testPhraseNotPrefix() { + void testPhraseNotPrefix() { tester.assertParsed("OR foo (AND prefix bar)", "foo prefix*bar", Query.Type.ANY); } @Test - public void testPhraseNotSubstring() { + void testPhraseNotSubstring() { tester.assertParsed("OR foo (AND substring bar)", "foo *substring*bar", Query.Type.ANY); } @Test - public void testPhraseNotSuffix() { + void testPhraseNotSuffix() { tester.assertParsed("OR (AND foo suffix) bar", "foo*suffix bar", Query.Type.ANY); } @Test - public void testIndexedPrefix() { + void testIndexedPrefix() { Item root = tester.assertParsed("foo.bar:prefix*", "foo.bar:prefix*", Query.Type.ANY); assertTrue(root instanceof PrefixItem); } @Test - public void testIndexedSubstring() { + void testIndexedSubstring() { Item root = tester.assertParsed("foo.bar:*substring*", "foo.bar:*substring*", Query.Type.ANY); assertTrue(root instanceof SubstringItem); } @Test - public void testIndexedSuffix() { + void testIndexedSuffix() { Item root = tester.assertParsed("foo.bar:*suffix", "foo.bar:*suffix", Query.Type.ANY); assertTrue(root instanceof SuffixItem); } @Test - public void testIndexedPhraseNotPrefix() { + void testIndexedPhraseNotPrefix() { tester.assertParsed("AND foo.bar:prefix foo.bar:xyzzy", "foo.bar:prefix*xyzzy", Query.Type.ANY); } @Test - public void testIndexedPhraseNotSubstring() { + void testIndexedPhraseNotSubstring() { tester.assertParsed("AND foo.bar:substring foo.bar:xyzzy", "foo.bar:*substring*xyzzy", Query.Type.ANY); } @Test - public void testIndexedPhraseNotSuffix() { + void testIndexedPhraseNotSuffix() { tester.assertParsed("AND foo.bar:xyzzy foo.bar:suffix", "foo.bar:xyzzy*suffix", Query.Type.ANY); } @Test - public void testPrefixWithWeight() { + void testPrefixWithWeight() { Item root = tester.assertParsed("prefix*!200", "prefix*!200", Query.Type.ANY); assertTrue(root instanceof PrefixItem); } @Test - public void testSubstringWithWeight() { + void testSubstringWithWeight() { Item root = tester.assertParsed("*substring*!200", "*substring*!200", Query.Type.ANY); assertTrue(root instanceof SubstringItem); } @Test - public void testSuffixWithWeight() { + void testSuffixWithWeight() { Item root = tester.assertParsed("*suffix!200", "*suffix!200", Query.Type.ANY); assertTrue(root instanceof SuffixItem); } /** Non existing index → and **/ @Test - public void testNonIndexPhraseNotPrefix() { + void testNonIndexPhraseNotPrefix() { tester.assertParsed("AND void prefix", "void:prefix*", Query.Type.ANY); } @Test - public void testNonIndexPhraseNotSubstring() { + void testNonIndexPhraseNotSubstring() { tester.assertParsed("AND void substring", "void:*substring*", Query.Type.ANY); } @Test - public void testNonIndexPhraseNotSuffix() { + void testNonIndexPhraseNotSuffix() { tester.assertParsed("AND void suffix", "void:*suffix", Query.Type.ANY); } /** Explicit phrase → remove '*' **/ @Test - public void testExplicitPhraseNotPrefix() { + void testExplicitPhraseNotPrefix() { tester.assertParsed("\"prefix bar\"", "\"prefix* bar\"", Query.Type.ANY); } @Test - public void testExplicitPhraseNotSubstring() { + void testExplicitPhraseNotSubstring() { tester.assertParsed("\"substring bar\"", "\"*substring* bar\"", Query.Type.ANY); } @Test - public void testExplicitPhraseNotSuffix() { + void testExplicitPhraseNotSuffix() { tester.assertParsed("\"suffix bar\"", "\"*suffix bar\"", Query.Type.ANY); } /** Extra star is ignored */ @Test - public void testPrefixExtraStar() { + void testPrefixExtraStar() { Item root = tester.assertParsed("prefix*", "prefix**", Query.Type.ANY); assertTrue(root instanceof PrefixItem); } @Test - public void testSubstringExtraStar() { + void testSubstringExtraStar() { Item root = tester.assertParsed("*substring*", "**substring**", Query.Type.ANY); assertTrue(root instanceof SubstringItem); } @Test - public void testSuffixExtraStar() { + void testSuffixExtraStar() { Item root = tester.assertParsed("*suffix", "**suffix", Query.Type.ANY); assertTrue(root instanceof SuffixItem); } @Test - public void testPrefixExtraSpace() { + void testPrefixExtraSpace() { Item root = tester.assertParsed("prefix", "prefix *", Query.Type.ANY); assertTrue(root instanceof WordItem); } @Test - public void testSubstringExtraSpace() { + void testSubstringExtraSpace() { Item root = tester.assertParsed("*substring*", "* substring*", Query.Type.ANY); assertTrue(root instanceof SubstringItem); } @Test - public void testSubstringExtraSpace2() { + void testSubstringExtraSpace2() { Item root = tester.assertParsed("*substring", "* substring *", Query.Type.ANY); assertTrue(root instanceof SuffixItem); } @Test - public void testSuffixExtraSpace() { + void testSuffixExtraSpace() { Item root = tester.assertParsed("*suffix", "* suffix", Query.Type.ANY); assertTrue(root instanceof SuffixItem); } /** Extra spaces with index **/ @Test - public void testIndexPrefixExtraSpace() { + void testIndexPrefixExtraSpace() { tester.assertParsed("AND foo prefix", "foo:prefix *", Query.Type.ANY); } @Test - public void testIndexSubstringExtraSpace() { + void testIndexSubstringExtraSpace() { Item root = tester.assertParsed("OR foo substring*", "foo:* substring*", Query.Type.ANY); - assertTrue(((OrItem)root).getItem(0) instanceof WordItem); - assertTrue(((OrItem)root).getItem(1) instanceof PrefixItem); + assertTrue(((OrItem) root).getItem(0) instanceof WordItem); + assertTrue(((OrItem) root).getItem(1) instanceof PrefixItem); } @Test - public void testIndexSubstringExtraSpace2() { + void testIndexSubstringExtraSpace2() { Item root = tester.assertParsed("OR foo substring", "foo:* substring *", Query.Type.ANY); - assertTrue(((OrItem)root).getItem(0) instanceof WordItem); - assertTrue(((OrItem)root).getItem(1) instanceof WordItem); + assertTrue(((OrItem) root).getItem(0) instanceof WordItem); + assertTrue(((OrItem) root).getItem(1) instanceof WordItem); } @Test - public void testIndexSuffixExtraSpace() { + void testIndexSuffixExtraSpace() { Item root = tester.assertParsed("OR foo suffix", "foo:* suffix", Query.Type.ANY); - assertTrue(((OrItem)root).getItem(0) instanceof WordItem); - assertTrue(((OrItem)root).getItem(1) instanceof WordItem); + assertTrue(((OrItem) root).getItem(0) instanceof WordItem); + assertTrue(((OrItem) root).getItem(1) instanceof WordItem); } /** Various tests for prefix, substring, and suffix terms **/ @Test - public void testTermsWithStarsAndSpaces() { + void testTermsWithStarsAndSpaces() { tester.assertParsed("OR foo *bar", "foo * bar", Query.Type.ANY); } @Test - public void testTermsWithStarsAndSpaces2() { + void testTermsWithStarsAndSpaces2() { tester.assertParsed("OR foo *bar *baz", "foo * * bar * * baz", Query.Type.ANY); } @Test - public void testTermsWithStarsAndPlussAndMinus() { + void testTermsWithStarsAndPlussAndMinus() { tester.assertParsed("+(AND *bar baz*) -*foo*", "+*bar -*foo* +baz*", Query.Type.ANY); } @Test - public void testTermsWithStarsAndPlussAndMinus2() { + void testTermsWithStarsAndPlussAndMinus2() { tester.assertParsed("OR *bar *foo baz", "+ * bar - * foo * + baz *", Query.Type.ANY); } @Test - public void testTermsWithStarsAndExclamation() { + void testTermsWithStarsAndExclamation() { tester.assertParsed("OR foo* 200 *bar* 200 *baz 200", "foo* !200 *bar* !200 *baz !200", Query.Type.ANY); } @Test - public void testTermsWithStarsAndExclamation2() { + void testTermsWithStarsAndExclamation2() { tester.assertParsed("OR foo 200 *bar 200", "foo *!200 *bar *!200", Query.Type.ANY); } @Test - public void testTermsWithStarsAndParenthesis() { + void testTermsWithStarsAndParenthesis() { tester.assertParsed("RANK *baz *bar* foo*", "(foo*) (*bar*) (*baz)", Query.Type.ANY); } @Test - public void testTermsWithStarsAndParenthesis2() { + void testTermsWithStarsAndParenthesis2() { tester.assertParsed("RANK baz bar foo", "(foo)* *(bar)* *(baz)", Query.Type.ANY); } @Test - public void testSimpleAndFilter() { + void testSimpleAndFilter() { tester.assertParsed("AND bar |foo", "bar", "+foo", Query.Type.ANY); } @Test - public void testSimpleRankFilter() { + void testSimpleRankFilter() { tester.assertParsed("RANK bar |foo", "bar", "foo", Query.Type.ANY); } @Test - public void testSimpleNotFilter() { + void testSimpleNotFilter() { tester.assertParsed("+bar -|foo", "bar", "-foo", Query.Type.ANY); } @Test - public void testSimpleCompoundFilter1() { + void testSimpleCompoundFilter1() { tester.assertParsed("RANK (AND bar |foo1) |foo2", "bar", "+foo1 foo2", Query.Type.ANY); } @Test - public void testSimpleCompoundFilter2() { + void testSimpleCompoundFilter2() { tester.assertParsed("+(AND bar |foo1) -|foo3", "bar", "+foo1 -foo3", Query.Type.ANY); } @Test - public void testSimpleCompoundFilter3() { + void testSimpleCompoundFilter3() { tester.assertParsed("RANK (+bar -|foo3) |foo2", "bar", "foo2 -foo3", Query.Type.ANY); } @Test - public void testSimpleCompoundFilter4() { + void testSimpleCompoundFilter4() { tester.assertParsed("RANK (+(AND bar |foo1) -|foo3) |foo2", "bar", "+foo1 foo2 -foo3", Query.Type.ANY); } @Test - public void testAndFilterEmptyQuery() { + void testAndFilterEmptyQuery() { tester.assertParsed("|foo", "", "+foo", Query.Type.ANY); } @Test - public void testRankFilterEmptyQuery() { + void testRankFilterEmptyQuery() { tester.assertParsed("|foo", "", "foo", Query.Type.ANY); } @Test - public void testNotFilterEmptyQuery() { + void testNotFilterEmptyQuery() { tester.assertParsed(null, "", "-foo", Query.Type.ANY); } @Test - public void testCompoundFilter1EmptyQuery() { + void testCompoundFilter1EmptyQuery() { tester.assertParsed("RANK |foo1 |foo2", "", "+foo1 foo2", Query.Type.ANY); } @Test - public void testCompoundFilter2EmptyQuery() { + void testCompoundFilter2EmptyQuery() { tester.assertParsed("+|foo1 -|foo3", "", "+foo1 -foo3", Query.Type.ANY); } @Test - public void testCompoundFilter3EmptyQuery() { + void testCompoundFilter3EmptyQuery() { tester.assertParsed("+|foo2 -|foo3", "", "foo2 -foo3", Query.Type.ANY); } @Test - public void testCompoundFilter4EmptyQuery() { + void testCompoundFilter4EmptyQuery() { tester.assertParsed("RANK (+|foo1 -|foo3) |foo2", "", "+foo1 foo2 -foo3", Query.Type.ANY); } @Test - public void testMultitermAndFilter() { + void testMultitermAndFilter() { tester.assertParsed("AND bar |foo |foz", "bar", "+foo +foz", Query.Type.ANY); } @Test - public void testMultitermRankFilter() { + void testMultitermRankFilter() { tester.assertParsed("RANK bar |foo |foz", "bar", "foo foz", Query.Type.ANY); } @Test - public void testMultitermNotFilter() { + void testMultitermNotFilter() { tester.assertParsed("+bar -|foo -|foz", "bar", "-foo -foz", Query.Type.ANY); } @Test - public void testMultitermCompoundFilter1() { + void testMultitermCompoundFilter1() { tester.assertParsed("RANK (AND bar |foo1 |foz1) |foo2 |foz2", "bar", "+foo1 +foz1 foo2 foz2", Query.Type.ANY); } @Test - public void testMultitermCompoundFilter2() { + void testMultitermCompoundFilter2() { tester.assertParsed("+(AND bar |foo1 |foz1) -|foo3 -|foz3", "bar", "+foo1 +foz1 -foo3 -foz3", Query.Type.ANY); } @Test - public void testMultitermCompoundFilter3() { + void testMultitermCompoundFilter3() { tester.assertParsed("RANK (+bar -|foo3 -|foz3) |foo2 |foz2", "bar", "foo2 foz2 -foo3 -foz3", Query.Type.ANY); } @Test - public void testMultitermCompoundFilter4() { + void testMultitermCompoundFilter4() { tester.assertParsed("RANK (+(AND bar |foo1 |foz1) -|foo3 -|foz3) |foo2 |foz2", "bar", "+foo1 +foz1 foo2 foz2 -foo3 -foz3", Query.Type.ANY); } @Test - public void testMultitermAndFilterEmptyQuery() { + void testMultitermAndFilterEmptyQuery() { tester.assertParsed("AND |foo |foz", "", "+foo +foz", Query.Type.ANY); } @Test - public void testMultitermRankFilterEmptyQuery() { + void testMultitermRankFilterEmptyQuery() { tester.assertParsed("OR |foo |foz", "", "foo foz", Query.Type.ANY); } @Test - public void testMultitermNotFilterEmptyQuery() { + void testMultitermNotFilterEmptyQuery() { tester.assertParsed(null, "", "-foo -foz", Query.Type.ANY); } @Test - public void testMultitermCompoundFilter1EmptyQuery() { + void testMultitermCompoundFilter1EmptyQuery() { tester.assertParsed("RANK (AND |foo1 |foz1) |foo2 |foz2", "", "+foo1 +foz1 foo2 foz2", Query.Type.ANY); } @Test - public void testMultitermCompoundFilter2EmptyQuery() { + void testMultitermCompoundFilter2EmptyQuery() { tester.assertParsed("+(AND |foo1 |foz1) -|foo3 -|foz3", "", "+foo1 +foz1 -foo3 -foz3", Query.Type.ANY); } @Test - public void testMultitermCompoundFilter3EmptyQuery() { + void testMultitermCompoundFilter3EmptyQuery() { tester.assertParsed("+(OR |foo2 |foz2) -|foo3 -|foz3", "", "foo2 foz2 -foo3 -foz3", Query.Type.ANY); } @Test - public void testMultitermCompoundFilter4EmptyQuery() { + void testMultitermCompoundFilter4EmptyQuery() { tester.assertParsed("RANK (+(AND |foo1 |foz1) -|foo3 -|foz3) |foo2 |foz2", "", "+foo1 +foz1 foo2 foz2 -foo3 -foz3", Query.Type.ANY); } @Test - public void testMultipleDifferentPhraseSeparators() { + void testMultipleDifferentPhraseSeparators() { tester.assertParsed("AND foo bar", "foo.-.bar", Query.Type.ANY); } @Test - public void testNoisyFilter() { + void testNoisyFilter() { tester.assertParsed("RANK (+(AND foobar kanoo) -|foo) |bar", "foobar and kanoo", "-foo ;+;bar", Query.Type.ADVANCED); } @Test - public void testReallyNoisyQuery1() { + void testReallyNoisyQuery1() { tester.assertParsed("AND word another", "&word\"()/&#)(/&another!\"", Query.Type.ALL); } @Test - public void testReallyNoisyQuery2() { + void testReallyNoisyQuery2() { tester.assertParsed("AND \u03bc\u03bc hei", "&&&`\u00b5\u00b5=@hei", Query.Type.ALL); } @Test - public void testReallyNoisyQuery3() { + void testReallyNoisyQuery3() { tester.assertParsed("AND hei hallo du der", "hei-hallo;du;der", Query.Type.ALL); } @Test - public void testNumberParsing() { + void testNumberParsing() { Item root = tester.parseQuery("normal:400", null, Language.UNKNOWN, Query.Type.ANY, TestLinguistics.INSTANCE); assertEquals(root.getCode(), 5); } @Test - public void testRangeParsing() { + void testRangeParsing() { Item root = tester.parseQuery("normal:[5;400]", null, Language.UNKNOWN, Query.Type.ANY, TestLinguistics.INSTANCE); assertEquals(root.toString(), "normal:[5;400]"); assertEquals(root.getCode(), 5); } @Test - public void testNumberAsPrefix() { + void testNumberAsPrefix() { Item root = tester.assertParsed("89*", "89*", Query.Type.ANY); assertTrue(root instanceof PrefixItem); } @Test - public void testNumberAsSubstring() { + void testNumberAsSubstring() { Item root = tester.assertParsed("*89*", "*89*", Query.Type.ANY); assertTrue(root instanceof SubstringItem); } @Test - public void testNumberAsSuffix() { + void testNumberAsSuffix() { Item root = tester.assertParsed("*89", "*89", Query.Type.ANY); assertTrue(root instanceof SuffixItem); } @Test - public void testTheStupidSymbolsWhichAreNowWordCharactersInUnicode() { + void testTheStupidSymbolsWhichAreNowWordCharactersInUnicode() { tester.assertParsed("AND yz a", "yz\u00A8\u00AA\u00AF", Query.Type.ANY); } @Test - public void testTWoWords() { + void testTWoWords() { tester.assertParsed("\"hei h\u00e5\"", "\"hei h\u00e5\"", Query.Type.ANY); } @Test - public void testLoneStar() { + void testLoneStar() { assertNull(tester.parseQuery("*", null, Language.UNKNOWN, Query.Type.ANY, TestLinguistics.INSTANCE)); } @Test - public void testLoneStarWithFilter() { + void testLoneStarWithFilter() { tester.assertParsed("|a", "*", "+a", Query.Type.ANY); } @Test - public void testImplicitPhrasingWithIndex() { + void testImplicitPhrasingWithIndex() { tester.assertParsed("AND a:b a:c", "a:/b/c", Query.Type.ANY); } @Test - public void testSingleNoisyTermWithIndex() { + void testSingleNoisyTermWithIndex() { tester.assertParsed("a:b", "a:/b", Query.Type.ANY); } @Test - public void testSingleNoisyPhraseWithIndex() { + void testSingleNoisyPhraseWithIndex() { tester.assertParsed("AND mail:yahoo mail:com", "mail:@yahoo.com", Query.Type.ANY); } @Test - public void testPhraseWithWeightAndIndex() { + void testPhraseWithWeightAndIndex() { tester.assertParsed("to:\"a b\"!150", "to:\"a b\"!150", Query.Type.ANY); } @Test - public void testTermWithWeightAndIndex() { + void testTermWithWeightAndIndex() { tester.assertParsed("to:a!150", "to:a!150", Query.Type.ANY); } @Test - public void testPhrasingWithIndexAndQuerySyntax() { + void testPhrasingWithIndexAndQuerySyntax() { tester.assertParsed("to:\"a b c\"", "to:\"a (b c)\"", Query.Type.ANY); } @Test - public void testPhrasingWithIndexAndHalfBrokenQuerySyntax() { + void testPhrasingWithIndexAndHalfBrokenQuerySyntax() { tester.assertParsed("to:\"a b c\"", "to:\"a +b c)\"", Query.Type.ANY); } @Test - public void testURLHostQueryOneTerm1() { + void testURLHostQueryOneTerm1() { tester.assertParsed("site:\"com $\"", "site:com", Query.Type.ANY); } @Test - public void testURLHostQueryOneTerm2() { + void testURLHostQueryOneTerm2() { tester.assertParsed("site:com", "site:com*", Query.Type.ANY); } @Test - public void testURLHostQueryOneTerm3() { + void testURLHostQueryOneTerm3() { tester.assertParsed("site:\"com $\"", "site:.com", Query.Type.ANY); } @Test - public void testURLHostQueryOneTerm4() { + void testURLHostQueryOneTerm4() { tester.assertParsed("site:\"^ com $\"", "site:^com", Query.Type.ANY); } @Test - public void testURLHostQueryOneTerm5() { + void testURLHostQueryOneTerm5() { tester.assertParsed("site:\"^ com\"", "site:^com*", Query.Type.ANY); } @Test - public void testFullURLQuery() { + void testFullURLQuery() { tester.assertParsed( "url.all:\"http shopping yahoo-inc com 1080 this is a path shop d hab id 1804905709 frag1\"", "url.all:http://shopping.yahoo-inc.com:1080/this/is/a/path/shop?d=hab&id=1804905709#frag1", @@ -1555,7 +1552,7 @@ public class ParseTestCase { } @Test - public void testURLQueryHyphen() { + void testURLQueryHyphen() { tester.assertParsed( "url.all:\"http news bbc co uk go rss test - sport1 hi tennis 4112866 stm\"", "url.all:http://news.bbc.co.uk/go/rss/test/-/sport1/hi/tennis/4112866.stm", @@ -1563,7 +1560,7 @@ public class ParseTestCase { } @Test - public void testURLQueryUnderScoreNumber() { + void testURLQueryUnderScoreNumber() { tester.assertParsed( "url.all:\"ap 20050621 45_ap_on_re_la_am_ca aruba_missing_teen_5\"", "url.all:/ap/20050621/45_ap_on_re_la_am_ca/aruba_missing_teen_5", @@ -1571,7 +1568,7 @@ public class ParseTestCase { } @Test - public void testOtherComplexUrls() { + void testOtherComplexUrls() { tester.assertParsed( "url.all:\"http redir folha com br redir online dinheiro rss091 http www1 folha uol com br folha dinheiro ult91u96593 shtml\"", "url.all:http://redir.folha.com.br/redir/online/dinheiro/rss091/*http://www1.folha.uol.com.br/folha/dinheiro/ult91u96593.shtml", @@ -1595,33 +1592,33 @@ public class ParseTestCase { } @Test - public void testTooGreedyUrlParsing() { + void testTooGreedyUrlParsing() { tester.assertParsed("AND site:\"nypost com $\" about", "site:nypost.com about", Query.Type.ALL); } @Test - public void testTooGreedyUrlParsing2() { + void testTooGreedyUrlParsing2() { tester.assertParsed("AND site:\"nypost com $\" about foo", "site:nypost.com about foo", Query.Type.ALL); } @Test - public void testSimplerDurbin() { + void testSimplerDurbin() { tester.assertParsed("+(OR language:en \"Durbin said\" a) -newstype:rssexclude", "( a (\"Durbin said\" ) -newstype:rssexclude (language:en )", Query.Type.ALL); } @Test - public void testSimplerDurbin2() { + void testSimplerDurbin2() { tester.assertParsed("+(AND \"Durbin said\" language:en) -newstype:rssexclude", "( , (\"Durbin said\" ) -newstype:rssexclude (language:en )", Query.Type.ALL); } @Test - public void testDurbin() { + void testDurbin() { tester.assertParsed( "AND \"Richard Durbin\" Welfare (+(OR language:en \"Durbin said\" \"Durbin says\" \"Durbin added\" \"Durbin agreed\" \"Durbin questioned\" date:>1109664000) -newstype:rssexclude)", "(\"Richard Durbin\" ) \"Welfare\" ((\"Durbin said\" \"Durbin says\" \"Durbin added\" \"Durbin agreed\" \"Durbin questioned\" ) -newstype:rssexclude date:>1109664000 (language:en )", @@ -1629,35 +1626,35 @@ public class ParseTestCase { } @Test - public void testTooLongQueryTerms() { + void testTooLongQueryTerms() { tester.assertParsed("AND 545558598787gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggcfffffffffffffffffffffffffffffffffffffffffffccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccclllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyytttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrreeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeewwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqlkjhcxxdfffxdzzaqwwsxedcrfvtgbyhnujmikkiloolpppof filter ew 545558598787gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggcfffffffffffffffffffffffffffffffffffffffffffccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccclllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyytttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrreeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeewwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqlkjhcxxdfffxdzzaqwwsxedcrfvtgbyhnujmikkiloolpppof 2b 2f 545558598787gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggcfffffffffffffffffffffffffffffffffffffffffffccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccclllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyytttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrreeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeewwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqlkjhcxxdfffxdzzaqwwsxedcrfvtgbyhnujmikkiloolpppof", "+/545558598787gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggcfffffffffffffffffffffffffffffffffffffffffffccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccclllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyytttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrreeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeewwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqlkjhcxxdfffxdzzaqwwsxedcrfvtgbyhnujmikkiloolpppof&filter=ew:545558598787gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggcfffffffffffffffffffffffffffffffffffffffffffccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccclllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyytttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrreeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeewwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqlkjhcxxdfffxdzzaqwwsxedcrfvtgbyhnujmikkiloolpppof!1000 =.2b..2f.545558598787gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggcfffffffffffffffffffffffffffffffffffffffffffccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccclllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyytttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrreeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeewwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqlkjhcxxdfffxdzzaqwwsxedcrfvtgbyhnujmikkiloolpppof", Query.Type.ALL); } @Test - public void testNonSpecialTokenParsing() { + void testNonSpecialTokenParsing() { ParsingTester customTester = new ParsingTester(SpecialTokens.empty()); customTester.assertParsed("OR c or c with (AND tcp ip)", "c# or c++ with tcp/ip", Query.Type.ANY); } @Test - public void testNonIndexWithColons1() { + void testNonIndexWithColons1() { tester.assertParsed("OR this is (AND notan iindex)", "this is notan:iindex", Query.Type.ANY); } @Test - public void testNonIndexWithColons2() { + void testNonIndexWithColons2() { tester.assertParsed("OR this is (AND notan iindex either)", "this is notan:iindex:either", Query.Type.ANY); } @Test - public void testIndexThenUnderscoreTermBecomesIndex() { + void testIndexThenUnderscoreTermBecomesIndex() { tester.assertParsed("AND name:batch name:article", "name:batch_article", Query.Type.ANY); } @Test - public void testFakeCJKSegmenting() { + void testFakeCJKSegmenting() { // "first" "second" and "third" are segments in the test language Item item = tester.parseQuery("name:firstsecondthird", null, Language.CHINESE_SIMPLIFIED, Query.Type.ANY, TestLinguistics.INSTANCE); @@ -1675,7 +1672,7 @@ public class ParseTestCase { } @Test - public void testFakeCJKSegmentingOfPhrase() { + void testFakeCJKSegmentingOfPhrase() { // "first" "second" and "third" are segments in the test language Item item = tester.parseQuery("name:\"firstsecondthird\"", null, Language.CHINESE_SIMPLIFIED, Query.Type.ANY, TestLinguistics.INSTANCE); @@ -1689,23 +1686,23 @@ public class ParseTestCase { assertEquals("name", ((WordItem) segment.getItem(0)).getIndexName()); assertEquals("name", ((WordItem) segment.getItem(1)).getIndexName()); - assertEquals("name", ((WordItem)segment.getItem(2)).getIndexName()); + assertEquals("name", ((WordItem) segment.getItem(2)).getIndexName()); } @Test - public void testAndItemAndImplicitPhrase() { + void testAndItemAndImplicitPhrase() { tester.assertParsed("AND \u00d8 \u00d8 \u00d8 \u00d9", - "\u00d8\u00b9\u00d8\u00b1\u00d8\u00a8\u00d9", "", - Query.Type.ALL, Language.CHINESE_SIMPLIFIED); + "\u00d8\u00b9\u00d8\u00b1\u00d8\u00a8\u00d9", "", + Query.Type.ALL, Language.CHINESE_SIMPLIFIED); } @Test - public void testAvoidMultiLevelAndForLongCJKQueries() { + void testAvoidMultiLevelAndForLongCJKQueries() { Item root = tester.parseQuery( "\u30d7\u30ed\u91ce\u7403\u962a\u795e\u306e\u672c\u62e0\u5730\u3001\u7532\u5b50\u5712\u7403\u5834\uff08\u5175\u5eab\u770c\u897f\u5bae\u5e02\uff09\u306f\uff11\u65e5\u3001\uff11\uff19\uff12\uff14\u5e74\u30d7\u30ed\u91ce\u7403\u962a\u795e\u306e\u672c\u62e0\u5730\u3001\u7532\u5b50\u5712\u7403\u5834\uff08\u5175\u5eab\u770c\u897f\u5bae\u5e02\uff09\u306f\uff11\u65e5\u3001\uff11\uff19\uff12\uff14\u5e74\u30d7\u30ed\u91ce\u7403\u962a\u795e\u306e\u672c\u62e0\u5730\u3001\u7532\u5b50\u5712\u7403\u5834\uff08\u5175\u5eab\u770c\u897f\u5bae\u5e02\uff09\u306f\uff11\u65e5\u3001\uff11\uff19\uff12\uff14\u5e74\u30d7\u30ed\u91ce\u7403\u962a\u795e\u306e\u672c\u62e0\u5730\u3001\u7532\u5b50\u5712\u7403\u5834\uff08\u5175\u5eab\u770c\u897f\u5bae\u5e02\uff09\u306f\uff11\u65e5\u3001\uff11\uff19\uff12\uff14\u5e74\u30d7\u30ed\u91ce\u7403\u962a\u795e\u306e\u672c\u62e0\u5730\u3001\u7532\u5b50\u5712\u7403\u5834\uff08\u5175\u5eab\u770c\u897f\u5bae\u5e02\uff09\u306f\uff11\u65e5\u3001\uff11\uff19\uff12\uff14\u5e74\u30d7\u30ed\u91ce\u7403\u962a\u795e\u306e\u672c\u62e0\u5730\u3001\u7532\u5b50\u5712\u7403\u5834\uff08\u5175\u5eab\u770c\u897f\u5bae\u5e02\uff09\u306f\uff11\u65e5\u3001\uff11\uff19\uff12\uff14\u5e74", "", Language.UNKNOWN, Query.Type.ALL, TestLinguistics.INSTANCE); - assertTrue("Query tree too deep when parsing CJK queries.", 4 > stackDepth(0, root)); + assertTrue(4 > stackDepth(0, root), "Query tree too deep when parsing CJK queries."); } private int stackDepth(int i, Item root) { @@ -1724,151 +1721,151 @@ public class ParseTestCase { } @Test - public void testFakeCJKSegmentingOfMultiplePhrases() { + void testFakeCJKSegmentingOfMultiplePhrases() { Item item = tester.parseQuery("name:firstsecond.s", null, Language.CHINESE_SIMPLIFIED, Query.Type.ANY, TestLinguistics.INSTANCE); assertEquals("AND (SAND name:first name:second) name:s", item.toString()); } @Test - public void testOrFilter() { + void testOrFilter() { tester.assertParsed("AND d (OR |a |b)", "d", "+(a b)", Query.Type.ALL); } @Test - public void testOrFilterWithTypeAdv() { + void testOrFilterWithTypeAdv() { tester.assertParsed("AND d (OR |a |b)", "d", "+(a b)", Query.Type.ADVANCED); } @Test - public void testPhraseFilter() { + void testPhraseFilter() { tester.assertParsed("AND d |\"a b\"", "d", "+\"a b\"", Query.Type.ALL); } @Test - public void testMinusAndFilter() { + void testMinusAndFilter() { tester.assertParsed("+d -(AND |a |b)", "d", "-(a b)", Query.Type.ALL); } @Test - public void testOrAndSomeTermsFilter() { + void testOrAndSomeTermsFilter() { tester.assertParsed("RANK d |c |a |b |e", "d", "c (a b) e", Query.Type.ALL); } // This is an ugly parse tree, but it's at least reasonable @Test - public void testOrAndSomeTermsFilterAndAnAnd() { - AndItem root=(AndItem)tester.assertParsed("AND (RANK d |c |a |b |e) (OR |e |f)", "d", "c (a b) e +(e f)", Query.Type.ALL); + void testOrAndSomeTermsFilterAndAnAnd() { + AndItem root = (AndItem) tester.assertParsed("AND (RANK d |c |a |b |e) (OR |e |f)", "d", "c (a b) e +(e f)", Query.Type.ALL); assertFalse(root.isFilter()); // AND assertFalse(root.getItem(0).isFilter()); // RANK - assertFalse(((RankItem)root.getItem(0)).getItem(0).isFilter()); // d - assertTrue(((RankItem)root.getItem(0)).getItem(1).isFilter()); // c - assertTrue(((RankItem)root.getItem(0)).getItem(2).isFilter()); // a - assertTrue(((RankItem)root.getItem(0)).getItem(3).isFilter()); // b - assertTrue(((RankItem)root.getItem(0)).getItem(4).isFilter()); // e + assertFalse(((RankItem) root.getItem(0)).getItem(0).isFilter()); // d + assertTrue(((RankItem) root.getItem(0)).getItem(1).isFilter()); // c + assertTrue(((RankItem) root.getItem(0)).getItem(2).isFilter()); // a + assertTrue(((RankItem) root.getItem(0)).getItem(3).isFilter()); // b + assertTrue(((RankItem) root.getItem(0)).getItem(4).isFilter()); // e assertFalse(root.getItem(1).isFilter()); // OR - assertTrue(((OrItem)root.getItem(1)).getItem(0).isFilter()); // e - assertTrue(((OrItem)root.getItem(1)).getItem(1).isFilter()); // f + assertTrue(((OrItem) root.getItem(1)).getItem(0).isFilter()); // e + assertTrue(((OrItem) root.getItem(1)).getItem(1).isFilter()); // f } @Test - public void testUrlNotConsumingBrace() { + void testUrlNotConsumingBrace() { tester.assertParsed("AND A (OR url.all:B url.all:C) D E", "A (url.all:B url.all:C) D E", Query.Type.ALL); } // Really a syntax error on part of the user, but it's part of // the logic where balanced braces are allowed in URLs @Test - public void testUrlNotConsumingBrace2() { + void testUrlNotConsumingBrace2() { tester.assertParsed("AND A (OR url.all:B url.all:C) D E", "A (url.all:B url.all:C)D E", Query.Type.ALL); } @Test - public void testSiteNotConsumingBrace() { + void testSiteNotConsumingBrace() { tester.assertParsed("AND A (OR site:\"B $\" site:\"C $\") D E", "A (site:B site:C) D E", Query.Type.ALL); } @Test - public void testCommaOnlyLeadsToImplicitPhrasing() { + void testCommaOnlyLeadsToImplicitPhrasing() { tester.assertParsed("AND A B C", "A,B,C", Query.Type.ALL); } @Test - public void testBangDoesNotBindAcrossSpace() { + void testBangDoesNotBindAcrossSpace() { tester.assertParsed("word", "word !", Query.Type.ALL); } @Test - public void testLotsOfPlusMinus() { + void testLotsOfPlusMinus() { tester.assertParsed("OR word term", "word - + - + - term", Query.Type.ANY); } @Test - public void testLotsOfMinusPlus() { + void testLotsOfMinusPlus() { tester.assertParsed("OR word term", "word - + - + term", Query.Type.ANY); } @Test - public void testMinusDoesNotBindAcrossSpace() { + void testMinusDoesNotBindAcrossSpace() { tester.assertParsed("OR word term", "word - term", Query.Type.ANY); } @Test - public void testPlusDoesNotBindAcrossSpace() { + void testPlusDoesNotBindAcrossSpace() { tester.assertParsed("OR word term", "word + term", Query.Type.ANY); } @Test - public void testMinusDoesNotBindAcrossSpaceAllQuery() { + void testMinusDoesNotBindAcrossSpaceAllQuery() { tester.assertParsed("AND word term", "word - term", Query.Type.ALL); } @Test - public void testPlusDoesNotBindAcrossSpaceAllQuery() { + void testPlusDoesNotBindAcrossSpaceAllQuery() { tester.assertParsed("AND word term", "word + term", Query.Type.ALL); } @Test - public void testNoSpaceInIndexPrefix() { + void testNoSpaceInIndexPrefix() { tester.assertParsed("AND url domain:s url.domain:b", "url. domain:s url.domain:b", Query.Type.ALL); } @Test - public void testNestedParensAndLittleElse() { + void testNestedParensAndLittleElse() { tester.assertParsed("OR a b c d", "((a b) (c d))", Query.Type.ALL); } // This is simply to control it doesn't crash @Test - public void testNestedParensAndLittleElseMoreBroken() { + void testNestedParensAndLittleElseMoreBroken() { tester.assertParsed("AND (OR a b) (OR c d)", "(a b) +(c d))", Query.Type.ALL); } @Test - public void testNestedUnbalancedParensAndLittleElseMoreBroken() { + void testNestedUnbalancedParensAndLittleElseMoreBroken() { tester.assertParsed("OR a b c d", "((a b) +(c d)", Query.Type.ALL); } @Test - public void testUnbalancedParens() { + void testUnbalancedParens() { tester.assertParsed("AND a b (OR c d)", "a b) +(c d))", Query.Type.ALL); } @Test - public void testUnbalancedStartingParens() { + void testUnbalancedStartingParens() { tester.assertParsed("OR a b c d", "((a b) +(c d", Query.Type.ALL); } @Test - public void testJPMobileExceptionQuery() { + void testJPMobileExceptionQuery() { tester.assertParsed("OR concat and (AND make string) 1 47 or", - "(concat \"and\" (make-string 1 47) \"or\")", Query.Type.ALL); + "(concat \"and\" (make-string 1 47) \"or\")", Query.Type.ALL); } @Test - public void testColonDoesNotBindAcrossSpace() { + void testColonDoesNotBindAcrossSpace() { tester.assertParsed("b", "a: b", Query.Type.ALL); tester.assertParsed("AND a b", "a : b", Query.Type.ALL); tester.assertParsed("AND a b", "a :b", Query.Type.ALL); @@ -1877,14 +1874,14 @@ public class ParseTestCase { } @Test - public void testGermanUriDecompounding() { + void testGermanUriDecompounding() { tester.assertParsed("url.all:\"kommunikationsfehler de\"", - "url.all:kommunikationsfehler.de", "", Query.Type.ALL, Language.GERMAN); + "url.all:kommunikationsfehler.de", "", Query.Type.ALL, Language.GERMAN); } // Check the parser doesn't fail on these horrible query strings @Test - public void testTicket443882() { + void testTicket443882() { tester.assertParsed( "AND australian LOTTERY (+(OR language:en IN AFFILIATION WITH THE UK NATIONAL LOTTERY date:>1125475200) -newstype:rssexclude)", "australian LOTTERY (IN AFFILIATION WITH THE UK NATIONAL LOTTERY -newstype:rssexclude date:>1125475200 (language:en )", @@ -1900,7 +1897,7 @@ public class ParseTestCase { } @Test - public void testParensInQuotes() { + void testParensInQuotes() { tester.assertParsed("AND ringtone (OR a:\"Delivery SMAF large max 150kB 063\" a:\"RealMusic Delivery\")", "ringtone AND (a:\"Delivery SMAF large max.150kB (063)\" OR a:\"RealMusic Delivery\" )", Query.Type.ADVANCED); @@ -1914,7 +1911,7 @@ public class ParseTestCase { } @Test - public void testMixedCaseIndexNames() { + void testMixedCaseIndexNames() { tester.assertParsed("AND mixedCase:a mixedCase:b notAnIndex c mixedCase:d", "mixedcase:a MIXEDCASE:b notAnIndex:c mixedCase:d", Query.Type.ALL); @@ -1922,9 +1919,9 @@ public class ParseTestCase { /** CJK special tokens should be recognized also on non-boundaries */ @Test - public void testChineseSpecialTokens() { + void testChineseSpecialTokens() { tester.assertParsed("AND cat tcp/ip zu foo dotnet bar dotnet dotnet c# c++ bar dotnet dotnet wiz", - "cattcp/ipzu foo.netbar.net.netC#c++bar.net.netwiz","", Query.Type.ALL, Language.CHINESE_SIMPLIFIED); + "cattcp/ipzu foo.netbar.net.netC#c++bar.net.netwiz", "", Query.Type.ALL, Language.CHINESE_SIMPLIFIED); } /** @@ -1932,69 +1929,69 @@ public class ParseTestCase { * but right now it is not */ @Test - public void testChineseSpecialTokensWithMultiSegmentReplace() { + void testChineseSpecialTokensWithMultiSegmentReplace() { // special-token-fs is a special token, to be replaced by firstsecond, first and second are segments in test - tester.assertParsed("AND tcp/ip firstsecond dotnet firstsecond (SAND first second)","tcp/ipspecial-token-fs.net special-token-fs firstsecond", - "", Query.Type.ALL, Language.CHINESE_SIMPLIFIED, TestLinguistics.INSTANCE); + tester.assertParsed("AND tcp/ip firstsecond dotnet firstsecond (SAND first second)", "tcp/ipspecial-token-fs.net special-token-fs firstsecond", + "", Query.Type.ALL, Language.CHINESE_SIMPLIFIED, TestLinguistics.INSTANCE); } @Test - public void testSpaceAndTermWeights() { + void testSpaceAndTermWeights() { tester.assertParsed("AND yahoo!360 yahoo 360 yahoo!150 360 yahoo 360 yahoo yahoo!150 yahoo!200", - "yahoo!360 yahoo !360 yahoo! 360 yahoo ! 360 yahoo !!! yahoo! ! yahoo!!", Query.Type.ALL); + "yahoo!360 yahoo !360 yahoo! 360 yahoo ! 360 yahoo !!! yahoo! ! yahoo!!", Query.Type.ALL); } @Test - public void testNumbersAndNot() { + void testNumbersAndNot() { tester.assertParsed("AND a -12", "a -12", Query.Type.ALL); } @Test - public void testNumbersAndDoubleNot() { + void testNumbersAndDoubleNot() { tester.assertParsed("+a --12", "a --12", Query.Type.ALL); } @Test - public void testNegativeNumberWithIndex() { + void testNegativeNumberWithIndex() { tester.assertParsed("normal:-12", "normal:-12", Query.Type.ALL); } @Test - public void testNegativeTermPositiveNumberWithIndex() { + void testNegativeTermPositiveNumberWithIndex() { tester.assertParsed("+a -normal:12", "a -normal:12", Query.Type.ALL); } @Test - public void testNegativeTermNegativeNumberWithIndex() { + void testNegativeTermNegativeNumberWithIndex() { tester.assertParsed("+a -normal:-12", "a -normal:-12", Query.Type.ALL); } @Test - public void testNegativeTermPositiveNumberInParentheses() { + void testNegativeTermPositiveNumberInParentheses() { tester.assertParsed("+a -12", "a -(12)", Query.Type.ALL); tester.assertParsed("+a -(AND 12 15)", "a -(12 15)", Query.Type.ALL); tester.assertParsed("+a -12 -15", "a -(12) -(15)", Query.Type.ALL); } @Test - public void testSingleNegativeNumberLikeTerm() { + void testSingleNegativeNumberLikeTerm() { tester.assertParsed("-12", "-12", Query.Type.ALL); } @Test - public void testNegativeLessThan() { + void testNegativeLessThan() { tester.assertParsed("normal:<-3", "normal:<-3", Query.Type.ALL); tester.assertParsed("<-3", "<-3", Query.Type.ALL); } @Test - public void testNegativeBiggerThan() { + void testNegativeBiggerThan() { tester.assertParsed("normal:>-3", "normal:>-3", Query.Type.ALL); tester.assertParsed(">-3", ">-3", Query.Type.ALL); } @Test - public void testNegativesInRanges() { + void testNegativesInRanges() { tester.assertParsed("normal:[-4;9]", "normal:[-4;9]", Query.Type.ALL); tester.assertParsed("[-4;9]", "[-4;9]", Query.Type.ALL); tester.assertParsed("normal:[-4;-9]", "normal:[-4;-9]", Query.Type.ALL); @@ -2002,51 +1999,51 @@ public class ParseTestCase { } @Test - public void testDecimal() { - Item root=tester.assertParsed("2.2", "2.2", Query.Type.ALL); + void testDecimal() { + Item root = tester.assertParsed("2.2", "2.2", Query.Type.ALL); assertTrue(root instanceof IntItem); tester.assertParsed("normal:2.2", "normal:2.2", Query.Type.ALL); } @Test - public void testVersionNumbers() { + void testVersionNumbers() { tester.assertParsed("AND 1 0 9", "1.0.9", Query.Type.ALL); } @Test - public void testDecimalNumbersAndNot() { + void testDecimalNumbersAndNot() { tester.assertParsed("AND a -12.2", "a -12.2", Query.Type.ALL); } @Test - public void testDecimalNumbersAndDoubleNot() { + void testDecimalNumbersAndDoubleNot() { tester.assertParsed("+a --12.2", "a --12.2", Query.Type.ALL); } @Test - public void testNegativeDecimalNumberWithIndex() { + void testNegativeDecimalNumberWithIndex() { tester.assertParsed("normal:-12.2", "normal:-12.2", Query.Type.ALL); } @Test - public void testSingleNegativeDecimalNumberLikeTerm() { + void testSingleNegativeDecimalNumberLikeTerm() { tester.assertParsed("-12.2", "-12.2", Query.Type.ALL); } @Test - public void testNegativeDecimalLessThan() { + void testNegativeDecimalLessThan() { tester.assertParsed("normal:<-3.14", "normal:<-3.14", Query.Type.ALL); tester.assertParsed("<-3.14", "<-3.14", Query.Type.ALL); } @Test - public void testNegativeDecimalBiggerThan() { + void testNegativeDecimalBiggerThan() { tester.assertParsed("normal:>-3.14", "normal:>-3.14", Query.Type.ALL); tester.assertParsed(">-3.14", ">-3.14", Query.Type.ALL); } @Test - public void testNegativesDecimalInRanges() { + void testNegativesDecimalInRanges() { tester.assertParsed("normal:[-4.16;9.2]", "normal:[-4.16;9.2]", Query.Type.ALL); tester.assertParsed("[-4.16;9.2]", "[-4.16;9.2]", Query.Type.ALL); tester.assertParsed("normal:[-4.16;-9.2]", "normal:[-4.16;-9.2]", Query.Type.ALL); @@ -2054,12 +2051,12 @@ public class ParseTestCase { } @Test - public void testRangesAndNoise() { + void testRangesAndNoise() { tester.assertParsed("[2;3]", "[2;3]]", Query.Type.ALL); } @Test - public void testIndexNoise() { + void testIndexNoise() { tester.assertParsed("AND normal:a notanindex", "normal:a normal: notanindex:", Query.Type.ALL); tester.assertParsed(null, "normal:", Query.Type.ALL); tester.assertParsed(null, "normal:!", Query.Type.ALL); @@ -2070,13 +2067,13 @@ public class ParseTestCase { } @Test - public void testIndexNoiseAndExplicitPhrases() { + void testIndexNoiseAndExplicitPhrases() { tester.assertParsed("normal:\"a b\"", "normal:\" a b\"", Query.Type.ALL); tester.assertParsed("normal:\"a b\"", "normal:\"a b\"", Query.Type.ALL); } @Test - public void testExactMatchParsing1() { + void testExactMatchParsing1() { SearchDefinition sd = new SearchDefinition("testsd"); Index index1 = new Index("testexact1"); @@ -2092,13 +2089,13 @@ public class ParseTestCase { customTester.assertParsed("testexact1:/,%&#", "testexact1:/,%&#", Query.Type.ALL); customTester.assertParsed("testexact2:/,%&#!!", "testexact2:/,%&#!!()/aa*::*&", Query.Type.ALL); - customTester.assertParsed("AND word1 (OR testexact1:word2 testexact1:word3)","word1 AND (testexact1:word2 OR testexact1:word3 )",Query.Type.ADVANCED); - customTester.assertParsed("AND word (OR testexact1:AND testexact1:OR)","word AND (testexact1: AND OR testexact1: OR )",Query.Type.ADVANCED); + customTester.assertParsed("AND word1 (OR testexact1:word2 testexact1:word3)", "word1 AND (testexact1:word2 OR testexact1:word3 )", Query.Type.ADVANCED); + customTester.assertParsed("AND word (OR testexact1:AND testexact1:OR)", "word AND (testexact1: AND OR testexact1: OR )", Query.Type.ADVANCED); } /** Testing terminators containing control characters in conjunction with those control characters */ @Test - public void testExactMatchParsing2() { + void testExactMatchParsing2() { SearchDefinition sd = new SearchDefinition("testsd"); Index index1 = new Index("testexact1"); @@ -2108,12 +2105,12 @@ public class ParseTestCase { IndexFacts indexFacts = new IndexFacts(new IndexModel(sd)); ParsingTester customTester = new ParsingTester(indexFacts); - customTester.assertParsed("testexact1:_-_*!200","testexact1:_-_*!**!!",Query.Type.ALL); + customTester.assertParsed("testexact1:_-_*!200", "testexact1:_-_*!**!!", Query.Type.ALL); } /** Testing terminators containing control characters in conjunction with those control characters */ @Test - public void testExactMatchParsing3() { + void testExactMatchParsing3() { SearchDefinition sd = new SearchDefinition("testsd"); Index index1 = new Index("testexact1"); @@ -2123,48 +2120,48 @@ public class ParseTestCase { IndexFacts indexFacts = new IndexFacts(new IndexModel(sd)); ParsingTester customTester = new ParsingTester(indexFacts); - customTester.assertParsed("testexact1:_-_*!200","testexact1:_-_**!!",Query.Type.ALL); + customTester.assertParsed("testexact1:_-_*!200", "testexact1:_-_**!!", Query.Type.ALL); } // bug 1393139 @Test - public void testMinimalBritneyFilter() { + void testMinimalBritneyFilter() { tester.assertParsed("RANK (+a -|c) b", "a RANK b", "-c", Query.Type.ADVANCED); } @Test - public void testBritneyFilter() { + void testBritneyFilter() { tester.assertParsed("RANK (+(AND performernameall:britney performernameall:spears songnameall:toxic |SongConsumable:1 |country:us |collapsedrecord:1 |doctype:song) -|collapsecount:0) (AND metadata:britney metadata:spears metadata:toxic)", - "((performernameall:britney AND performernameall:spears AND songnameall:toxic) RANK (metadata:britney AND metadata:spears AND metadata:toxic))", - "+SongConsumable:1 +country:us +collapsedrecord:1 -collapsecount:0 +doctype:song", - Query.Type.ADVANCED); + "((performernameall:britney AND performernameall:spears AND songnameall:toxic) RANK (metadata:britney AND metadata:spears AND metadata:toxic))", + "+SongConsumable:1 +country:us +collapsedrecord:1 -collapsecount:0 +doctype:song", + Query.Type.ADVANCED); tester.assertParsed("AND (+(AND (RANK (OR (AND performernameall:britney performernameall:spears songnameall:toxic) (AND performernameall:britney performernameall:spears songnameall:toxic)) (AND metadata:britney metadata:spears metadata:toxic)) |SongConsumable:1 |country:us |collapsedrecord:1) -|collapsecount:0) |doctype:song", - "(((performernameall:britney AND performernameall:spears AND songnameall:toxic) OR (performernameall:britney AND performernameall:spears AND songnameall:toxic)) RANK (metadata:britney AND metadata:spears AND metadata:toxic)))", - "+SongConsumable:1 +country:us +collapsedrecord:1 -collapsecount:0 +doctype:song", - Query.Type.ADVANCED); + "(((performernameall:britney AND performernameall:spears AND songnameall:toxic) OR (performernameall:britney AND performernameall:spears AND songnameall:toxic)) RANK (metadata:britney AND metadata:spears AND metadata:toxic)))", + "+SongConsumable:1 +country:us +collapsedrecord:1 -collapsecount:0 +doctype:song", + Query.Type.ADVANCED); } // bug 1412840 @Test - public void testGreedyPhrases() { + void testGreedyPhrases() { tester.assertParsed("AND title:why title:\"1 2\"", "title:\"why\" title:\"&\" title:\"1/2\"", Query.Type.ALL); } // bug 1509347 @Test - public void testUnderscoreInFieldNames() { + void testUnderscoreInFieldNames() { tester.assertParsed("AND title:why score_under:what score_under:>5000", - "title:why score_under:what score_under:>5000", - Query.Type.ALL); + "title:why score_under:what score_under:>5000", + Query.Type.ALL); } // bug 1509347 @Test - public void testLeadingUnderscoreInFieldNames() { + void testLeadingUnderscoreInFieldNames() { tester.assertParsed("AND title:why _under_score_:what _under_score_:>5000", - "title:why _under_score_:what _under_score_:>5000", - Query.Type.ALL); + "title:why _under_score_:what _under_score_:>5000", + Query.Type.ALL); } // Re-add if underscore should be a word character @@ -2185,7 +2182,7 @@ public class ParseTestCase { // bug 524918 @Test - public void testAdvancedSyntaxParensAndQuotes() { + void testAdvancedSyntaxParensAndQuotes() { tester.assertParsed("OR a (AND \"b c d\" e)", "a OR (\"b (c) d\" AND e)", Query.Type.ADVANCED); @@ -2195,7 +2192,7 @@ public class ParseTestCase { // this needs to become series of tests where the tokenizer // and parser will step on each other's toes. @Test - public void testStarFirstInAttributes() { + void testStarFirstInAttributes() { tester.assertParsed("exactindex:*test", "exactindex:*test", Query.Type.ALL); @@ -2203,162 +2200,162 @@ public class ParseTestCase { } @Test - public void testOneWordWebParsing() { - tester.assertParsed("a","a",Query.Type.WEB); + void testOneWordWebParsing() { + tester.assertParsed("a", "a", Query.Type.WEB); } @Test - public void testTwoWordWebParsing() { - tester.assertParsed("AND a b","a b",Query.Type.WEB); + void testTwoWordWebParsing() { + tester.assertParsed("AND a b", "a b", Query.Type.WEB); } @Test - public void testPlusWordWebParsing1() { - Item root=tester.assertParsed("AND a b","+a b",Query.Type.WEB); - assertTrue(((AndItem)root).getItem(0).isProtected()); - assertFalse(((AndItem)root).getItem(1).isProtected()); + void testPlusWordWebParsing1() { + Item root = tester.assertParsed("AND a b", "+a b", Query.Type.WEB); + assertTrue(((AndItem) root).getItem(0).isProtected()); + assertFalse(((AndItem) root).getItem(1).isProtected()); } @Test - public void testPlusWordWebParsing2() { - Item root=tester.assertParsed("AND a b","+a +b",Query.Type.WEB); - assertTrue(((AndItem)root).getItem(0).isProtected()); - assertTrue(((AndItem)root).getItem(1).isProtected()); + void testPlusWordWebParsing2() { + Item root = tester.assertParsed("AND a b", "+a +b", Query.Type.WEB); + assertTrue(((AndItem) root).getItem(0).isProtected()); + assertTrue(((AndItem) root).getItem(1).isProtected()); } @Test - public void testNegativeWordsParsing1() { - Item root=tester.assertParsed("+a -b","a -b",Query.Type.WEB); - assertFalse(((NotItem)root).getItem(0).isProtected()); - assertTrue(((NotItem)root).getItem(1).isProtected()); + void testNegativeWordsParsing1() { + Item root = tester.assertParsed("+a -b", "a -b", Query.Type.WEB); + assertFalse(((NotItem) root).getItem(0).isProtected()); + assertTrue(((NotItem) root).getItem(1).isProtected()); } @Test - public void testNegativeWordsParsing2() { - Item root=tester.assertParsed("+a -b","+a -b",Query.Type.WEB); - assertTrue(((NotItem)root).getItem(0).isProtected()); - assertTrue(((NotItem)root).getItem(1).isProtected()); + void testNegativeWordsParsing2() { + Item root = tester.assertParsed("+a -b", "+a -b", Query.Type.WEB); + assertTrue(((NotItem) root).getItem(0).isProtected()); + assertTrue(((NotItem) root).getItem(1).isProtected()); } @Test - public void testNegativeWordsParsing3() { - tester.assertParsed("+a -b","-b a",Query.Type.WEB); + void testNegativeWordsParsing3() { + tester.assertParsed("+a -b", "-b a", Query.Type.WEB); } @Test - public void testNegativeWordsParsing4() { - tester.assertParsed("+(AND a b) -c -d","a b -c -d",Query.Type.WEB); + void testNegativeWordsParsing4() { + tester.assertParsed("+(AND a b) -c -d", "a b -c -d", Query.Type.WEB); } @Test - public void testNegativeWordsParsing5() { - tester.assertParsed("+(AND a \"b c\" d) -e -f","a -e \"b c\" d -f",Query.Type.WEB); + void testNegativeWordsParsing5() { + tester.assertParsed("+(AND a \"b c\" d) -e -f", "a -e \"b c\" d -f", Query.Type.WEB); } @Test - public void testPhraseWebParsing() { - tester.assertParsed("\"a b\"","\"a b\"",Query.Type.WEB); + void testPhraseWebParsing() { + tester.assertParsed("\"a b\"", "\"a b\"", Query.Type.WEB); } @Test - public void testPhraseAndExtraTermWebParsing() { - tester.assertParsed("AND \"a b\" c","\"a b\" c",Query.Type.WEB); + void testPhraseAndExtraTermWebParsing() { + tester.assertParsed("AND \"a b\" c", "\"a b\" c", Query.Type.WEB); } @Test - public void testNotOrWebParsing() { - tester.assertParsed("AND a or b","a or b",Query.Type.WEB); + void testNotOrWebParsing() { + tester.assertParsed("AND a or b", "a or b", Query.Type.WEB); } @Test - public void testNotOrALLParsing() { - tester.assertParsed("AND a OR b","a OR b",Query.Type.ALL); + void testNotOrALLParsing() { + tester.assertParsed("AND a OR b", "a OR b", Query.Type.ALL); } @Test - public void testOrParsing1() { - tester.assertParsed("OR a b","a OR b",Query.Type.WEB); + void testOrParsing1() { + tester.assertParsed("OR a b", "a OR b", Query.Type.WEB); } @Test - public void testOrParsing2() { - tester.assertParsed("OR a b c","a OR b OR c",Query.Type.WEB); + void testOrParsing2() { + tester.assertParsed("OR a b c", "a OR b OR c", Query.Type.WEB); } @Test - public void testOrParsing3() { - tester.assertParsed("OR a (AND b c) \"d e\"","a OR b c OR \"d e\"",Query.Type.WEB); + void testOrParsing3() { + tester.assertParsed("OR a (AND b c) \"d e\"", "a OR b c OR \"d e\"", Query.Type.WEB); } @Test - public void testOrParsing4() { - tester.assertParsed("OR (AND or1 a) or2","or1 a OR or2",Query.Type.WEB); + void testOrParsing4() { + tester.assertParsed("OR (AND or1 a) or2", "or1 a OR or2", Query.Type.WEB); } @Test - public void testOrCornerCase1() { - tester.assertParsed("AND OR a","OR a",Query.Type.WEB); + void testOrCornerCase1() { + tester.assertParsed("AND OR a", "OR a", Query.Type.WEB); } @Test - public void testOrCornerCase2() { - tester.assertParsed("AND OR a","OR a OR",Query.Type.WEB); // Don't care + void testOrCornerCase2() { + tester.assertParsed("AND OR a", "OR a OR", Query.Type.WEB); // Don't care } @Test - public void testOrCornerCase3() { - tester.assertParsed("AND OR a","OR a OR OR",Query.Type.WEB); // Don't care + void testOrCornerCase3() { + tester.assertParsed("AND OR a", "OR a OR OR", Query.Type.WEB); // Don't care } @Test - public void testOrCornerCase4() { - tester.assertParsed("+(OR (AND a b) (AND d c) (AND g h)) -e -f","a b OR d c -e -f OR g h",Query.Type.WEB); + void testOrCornerCase4() { + tester.assertParsed("+(OR (AND a b) (AND d c) (AND g h)) -e -f", "a b OR d c -e -f OR g h", Query.Type.WEB); } @Test - public void testOdd1Web() { - tester.assertParsed("AND window print error", "+window.print() +error",Query.Type.WEB); + void testOdd1Web() { + tester.assertParsed("AND window print error", "+window.print() +error", Query.Type.WEB); } @Test - public void testNotOnlyWeb() { + void testNotOnlyWeb() { tester.assertParsed(null, "-foobar", Query.Type.WEB); } @Test - public void testMultipleNotsOnltWeb() { + void testMultipleNotsOnltWeb() { tester.assertParsed(null, "-foo -bar -foobar", Query.Type.WEB); } @Test - public void testOnlyNotCompositeWeb() { + void testOnlyNotCompositeWeb() { tester.assertParsed(null, "-(foo bar baz)", Query.Type.WEB); } @Test - public void testSingleNegativeNumberLikeTermWeb() { + void testSingleNegativeNumberLikeTermWeb() { tester.assertParsed("-12", "-12", Query.Type.WEB); } @Test - public void testSingleNegativeDecimalNumberLikeTermWeb() { + void testSingleNegativeDecimalNumberLikeTermWeb() { tester.assertParsed("-12.2", "-12.2", Query.Type.WEB); } @Test - public void testDefaultWebIndices() { - tester.assertParsed("AND notanindex b","notanindex:b", Query.Type.WEB); - tester.assertParsed("site:\"b $\"","site:b", Query.Type.WEB); - tester.assertParsed("hostname:b","hostname:b", Query.Type.WEB); - tester.assertParsed("link:b","link:b", Query.Type.WEB); - tester.assertParsed("url:b","url:b", Query.Type.WEB); - tester.assertParsed("inurl:b","inurl:b", Query.Type.WEB); - tester.assertParsed("intitle:b","intitle:b", Query.Type.WEB); + void testDefaultWebIndices() { + tester.assertParsed("AND notanindex b", "notanindex:b", Query.Type.WEB); + tester.assertParsed("site:\"b $\"", "site:b", Query.Type.WEB); + tester.assertParsed("hostname:b", "hostname:b", Query.Type.WEB); + tester.assertParsed("link:b", "link:b", Query.Type.WEB); + tester.assertParsed("url:b", "url:b", Query.Type.WEB); + tester.assertParsed("inurl:b", "inurl:b", Query.Type.WEB); + tester.assertParsed("intitle:b", "intitle:b", Query.Type.WEB); } @Test - public void testHTMLWeb() { - tester.assertParsed("AND h2 Title h2","<h2>Title</h2>",Query.Type.WEB); + void testHTMLWeb() { + tester.assertParsed("AND h2 Title h2", "<h2>Title</h2>", Query.Type.WEB); } /** @@ -2366,82 +2363,82 @@ public class ParseTestCase { * The information about added bangs is available from the origin as shown (do not use the weight to find this) */ @Test - public void testShortcutsWeb() { - tester.assertParsed("AND map new york","map new york",Query.Type.WEB); + void testShortcutsWeb() { + tester.assertParsed("AND map new york", "map new york", Query.Type.WEB); - AndItem root=(AndItem)tester.assertParsed("AND map!150 new york","map! new york",Query.Type.WEB); - assertEquals('!',((WordItem)root.getItem(0)).getOrigin().charAfter(0)); + AndItem root = (AndItem) tester.assertParsed("AND map!150 new york", "map! new york", Query.Type.WEB); + assertEquals('!', ((WordItem) root.getItem(0)).getOrigin().charAfter(0)); - root=(AndItem)tester.assertParsed("AND barack obama news!150","barack obama news!",Query.Type.WEB); - assertEquals('!',((WordItem)root.getItem(2)).getOrigin().charAfter(0)); + root = (AndItem) tester.assertParsed("AND barack obama news!150", "barack obama news!", Query.Type.WEB); + assertEquals('!', ((WordItem) root.getItem(2)).getOrigin().charAfter(0)); } @Test - public void testZipCodeShortcutWeb() { - tester.assertParsed("12345","12345",Query.Type.WEB); - IntItem root=(IntItem)tester.assertParsed("00012!150","00012!",Query.Type.WEB); - assertEquals('!',root.getOrigin().charAfter(0)); + void testZipCodeShortcutWeb() { + tester.assertParsed("12345", "12345", Query.Type.WEB); + IntItem root = (IntItem) tester.assertParsed("00012!150", "00012!", Query.Type.WEB); + assertEquals('!', root.getOrigin().charAfter(0)); } @Test - public void testDouble() { - Item number=tester.assertParsed("123456789.987654321","123456789.987654321",Query.Type.ALL); + void testDouble() { + Item number = tester.assertParsed("123456789.987654321", "123456789.987654321", Query.Type.ALL); assertTrue(number instanceof IntItem); } @Test - public void testLong() { - Item number=tester.assertParsed("3000000000000","3000000000000",Query.Type.ALL); + void testLong() { + Item number = tester.assertParsed("3000000000000", "3000000000000", Query.Type.ALL); assertTrue(number instanceof IntItem); } @Test - public void testNear1() { - tester.assertParsed("NEAR(2) new york","new NEAR york",Query.Type.ADVANCED); + void testNear1() { + tester.assertParsed("NEAR(2) new york", "new NEAR york", Query.Type.ADVANCED); } @Test - public void testNear2() { - tester.assertParsed("ONEAR(2) new york","new ONEAR york",Query.Type.ADVANCED); + void testNear2() { + tester.assertParsed("ONEAR(2) new york", "new ONEAR york", Query.Type.ADVANCED); } @Test - public void testNear3() { - tester.assertParsed("NEAR(3) new york","new NEAR(3) york",Query.Type.ADVANCED); + void testNear3() { + tester.assertParsed("NEAR(3) new york", "new NEAR(3) york", Query.Type.ADVANCED); } @Test - public void testNear4() { - tester.assertParsed("ONEAR(3) new york","new ONEAR(3) york",Query.Type.ADVANCED); + void testNear4() { + tester.assertParsed("ONEAR(3) new york", "new ONEAR(3) york", Query.Type.ADVANCED); } @Test - public void testNear5() { - tester.assertParsed("NEAR(3) map new york","map NEAR(3) new NEAR(3) york",Query.Type.ADVANCED); + void testNear5() { + tester.assertParsed("NEAR(3) map new york", "map NEAR(3) new NEAR(3) york", Query.Type.ADVANCED); } @Test - public void testNear6() { - tester.assertParsed("ONEAR(3) map new york","map ONEAR(3) new ONEAR(3) york",Query.Type.ADVANCED); + void testNear6() { + tester.assertParsed("ONEAR(3) map new york", "map ONEAR(3) new ONEAR(3) york", Query.Type.ADVANCED); } @Test - public void testNear7() { - tester.assertParsed("NEAR(4) (NEAR(3) map new) york","map NEAR(3) new NEAR(4) york",Query.Type.ADVANCED); + void testNear7() { + tester.assertParsed("NEAR(4) (NEAR(3) map new) york", "map NEAR(3) new NEAR(4) york", Query.Type.ADVANCED); } @Test - public void testNear8() { - tester.assertParsed("ONEAR(4) (ONEAR(3) map new) york","map ONEAR(3) new ONEAR(4) york",Query.Type.ADVANCED); + void testNear8() { + tester.assertParsed("ONEAR(4) (ONEAR(3) map new) york", "map ONEAR(3) new ONEAR(4) york", Query.Type.ADVANCED); } @Test - public void testNearPrefix() { - tester.assertParsed("NEAR(2) a b*","a NEAR b*",Query.Type.ADVANCED); + void testNearPrefix() { + tester.assertParsed("NEAR(2) a b*", "a NEAR b*", Query.Type.ADVANCED); } @Test - public void testNestedBracesAndPhrases() { + void testNestedBracesAndPhrases() { String userQuery = "(\"Secondary Curriculum\" (\"Key Stage 3\" OR KS3) (\"Key Stage 4\" OR KS4)) "; tester.assertParsed( "OR \"Secondary Curriculum\" \"Key Stage 3\" OR KS3 \"Key Stage 4\" OR KS4", @@ -2458,53 +2455,53 @@ public class ParseTestCase { } @Test - public void testYetAnotherCycleQuery() { + void testYetAnotherCycleQuery() { tester.assertParsed("+(OR (+d -f) b) -c", "( b -c ( d -f )", Query.Type.ALL); } @Test - public void testSimpleEquivAdvanced() { + void testSimpleEquivAdvanced() { tester.assertParsed("EQUIV foo bar baz", "foo equiv bar equiv baz", Query.Type.ADVANCED); } @Test - public void testEquivWordIntPhraseAdvanced() { + void testEquivWordIntPhraseAdvanced() { tester.assertParsed("EQUIV foo 5 \"a b\"", "foo equiv 5 equiv \"a b\"", Query.Type.ADVANCED); } @Test - public void testEquivRejectCompositeAdvanced() { + void testEquivRejectCompositeAdvanced() { try { tester.assertParsed("this should not parse", "foo equiv (a or b)", Query.Type.ADVANCED); - } catch(Exception e) { + } catch (Exception e) { // Success } } @Test - public void testSimpleWandAdvanced() { + void testSimpleWandAdvanced() { tester.assertParsed("WEAKAND(100) foo bar baz", "foo wand bar wand baz", Query.Type.ADVANCED); } @Test - public void testSimpleWandAdvancedWithNonDefaultN() { + void testSimpleWandAdvancedWithNonDefaultN() { tester.assertParsed("WEAKAND(32) foo bar baz", "foo weakand(32) bar weakand(32) baz", Query.Type.ADVANCED); } @Test - public void testSimpleWandAdvancedWithNonDefaultNAndWeights() { + void testSimpleWandAdvancedWithNonDefaultNAndWeights() { tester.assertParsed("WEAKAND(32) foo!32 bar!64 baz", "foo!32 weakand(32) bar!64 weakand(32) baz", Query.Type.ADVANCED); } @Test - public void testTwoRanges() { - tester.assertParsed("AND score:[1.25;2.18] age:[25;30]","score:[1.25;2.18] AND age:[25;30]", Query.Type.ADVANCED); + void testTwoRanges() { + tester.assertParsed("AND score:[1.25;2.18] age:[25;30]", "score:[1.25;2.18] AND age:[25;30]", Query.Type.ADVANCED); } @Test - public void testTooLargeTermWeights() { + void testTooLargeTermWeights() { // This behavior is a bit silly: tester.assertParsed("AND a 12345678901234567890", "a!12345678901234567890", Query.Type.ALL); // but in light of @@ -2515,7 +2512,7 @@ public class ParseTestCase { } @Test - public void testAndSegmenting() { + void testAndSegmenting() { Item root = tester.parseQuery("a'b&c'd", Language.ENGLISH, Query.Type.ALL); assertTrue(root instanceof AndItem); AndItem top = (AndItem) root; @@ -2527,59 +2524,59 @@ public class ParseTestCase { Item t2 = seg1.getItem(1); Item t3 = seg2.getItem(0); Item t4 = seg2.getItem(1); - assertTrue(((TaggableItem)t2).hasUniqueID()); - assertTrue(((TaggableItem)t3).hasUniqueID()); - assertTrue(((TaggableItem)t1).getConnectedItem() == t2); - assertTrue(((TaggableItem)t2).getConnectedItem() == t3); - assertTrue(((TaggableItem)t3).getConnectedItem() == t4); + assertTrue(((TaggableItem) t2).hasUniqueID()); + assertTrue(((TaggableItem) t3).hasUniqueID()); + assertEquals(((TaggableItem) t1).getConnectedItem(), t2); + assertEquals(((TaggableItem) t2).getConnectedItem(), t3); + assertEquals(((TaggableItem) t3).getConnectedItem(), t4); } @Test - public void testSiteAndSegmentPhrases() { + void testSiteAndSegmentPhrases() { tester.assertParsed("host.all:\"www abc com x y-z $\"", - "host.all:www.abc.com/x'y-z", "", - Query.Type.ALL, Language.ENGLISH); + "host.all:www.abc.com/x'y-z", "", + Query.Type.ALL, Language.ENGLISH); } @Test - public void testSiteAndSegmentPhrasesFollowedByText() { + void testSiteAndSegmentPhrasesFollowedByText() { tester.assertParsed("AND host.all:\"www abc com x y-z $\" (SAND a b)", - "host.all:www.abc.com/x'y-z a'b", "", - Query.Type.ALL, Language.ENGLISH); + "host.all:www.abc.com/x'y-z a'b", "", + Query.Type.ALL, Language.ENGLISH); } @Test - public void testIntItemFollowedByDot() { - tester.assertParsed("AND Campion Ste 3 When To Her Lute Corinna Sings","Campion Ste: 3. When To Her Lute Corinna Sings", Query.Type.ALL); + void testIntItemFollowedByDot() { + tester.assertParsed("AND Campion Ste 3 When To Her Lute Corinna Sings", "Campion Ste: 3. When To Her Lute Corinna Sings", Query.Type.ALL); } @Test - public void testNotIntItemIfPrecededByHyphen() { - tester.assertParsed("AND Horny Horny '98 Radio Edit","Horny [Horny '98 Radio Edit]]", Query.Type.ALL); + void testNotIntItemIfPrecededByHyphen() { + tester.assertParsed("AND Horny Horny '98 Radio Edit", "Horny [Horny '98 Radio Edit]]", Query.Type.ALL); } @Test - public void testNonAsciiNumber() { + void testNonAsciiNumber() { tester.assertParsed("AND title:199 title:119 title:201 title:149", "title:199.119.201.149", Query.Type.ALL); } @Test - public void testNoGrammar1() { + void testNoGrammar1() { tester.assertParsed("WEAKAND(100) foobar", "foobar", Query.Type.TOKENIZE); } @Test - public void testNoGrammar2() { + void testNoGrammar2() { tester.assertParsed("WEAKAND(100) foobar", "-foobar", Query.Type.TOKENIZE); } @Test - public void testNoGrammar3() { + void testNoGrammar3() { tester.assertParsed("WEAKAND(100) foo bar", "foo -bar", Query.Type.TOKENIZE); } @Test - public void testNoGrammar4() { + void testNoGrammar4() { tester.assertParsed("WEAKAND(100) foo bar baz one two 37", "foo -(bar baz \"one two\" 37)", Query.Type.TOKENIZE); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParsingTester.java b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParsingTester.java index 42bc1c22529..ab314c4c1e7 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParsingTester.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParsingTester.java @@ -23,9 +23,7 @@ import com.yahoo.search.query.parser.ParserFactory; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * A utility for writing parser tests @@ -119,10 +117,10 @@ public class ParsingTester { Language language, Linguistics linguistics) { Item root = parseQuery(toParse, filter, language, mode, linguistics); if (parsed == null) { - assertTrue("root should be null, but was " + root, root == null); + assertNull(root); } else { - assertNotNull("Got null from parsing " + toParse, root); - assertEquals("Parse of '" + toParse + "'", parsed, root.toString()); + assertNotNull(root, "Got null from parsing " + toParse); + assertEquals(parsed, root.toString(), "Parse of '" + toParse + "'"); } return root; } diff --git a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/SubstringTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/SubstringTestCase.java index e7d938e6bd8..129563d1456 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/SubstringTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/SubstringTestCase.java @@ -1,9 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.query.parser.test; -import org.junit.Test; -import static org.junit.Assert.assertEquals; - +import org.junit.jupiter.api.Test; import com.yahoo.prelude.query.CompositeItem; import com.yahoo.prelude.query.WordItem; import com.yahoo.search.Query; @@ -11,6 +9,8 @@ import com.yahoo.search.Query; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * Check Substring in conjunction with query tokenization and parsing behaves properly. * @@ -19,15 +19,15 @@ import java.net.URLEncoder; public class SubstringTestCase { @Test - public final void testTokenLengthAndLowercasing() { + final void testTokenLengthAndLowercasing() { Query q = new Query("/?query=\u0130"); - WordItem root = (WordItem) ((CompositeItem)q.getModel().getQueryTree().getRoot()).getItem(0); + WordItem root = (WordItem) ((CompositeItem) q.getModel().getQueryTree().getRoot()).getItem(0); assertEquals("\u0130", root.getRawWord()); } @Test - public final void testBug5968479() { + final void testBug5968479() { String first = "\u0130\u015EBANKASI"; String second = "GAZ\u0130EM\u0130R"; Query q = new Query("/?query=" + enc(first) + "%20" + enc(second)); diff --git a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/TokenizerTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/TokenizerTestCase.java index 5b660f78429..1ff5574ec03 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/TokenizerTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/TokenizerTestCase.java @@ -10,7 +10,7 @@ import com.yahoo.language.process.SpecialTokenRegistry; import com.yahoo.language.process.SpecialTokens; import com.yahoo.prelude.query.parser.Token; import com.yahoo.prelude.query.parser.Tokenizer; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Collections; @@ -29,9 +29,7 @@ import static com.yahoo.prelude.query.parser.Token.Kind.SPACE; import static com.yahoo.prelude.query.parser.Token.Kind.STAR; import static com.yahoo.prelude.query.parser.Token.Kind.UNDERSCORE; import static com.yahoo.prelude.query.parser.Token.Kind.WORD; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Tests the tokenizer @@ -41,7 +39,7 @@ import static org.junit.Assert.assertTrue; public class TokenizerTestCase { @Test - public void testPlainTokenization() { + void testPlainTokenization() { Tokenizer tokenizer = new Tokenizer(new SimpleLinguistics()); tokenizer.setSpecialTokens(createSpecialTokens().getSpecialTokens("default")); @@ -76,14 +74,14 @@ public class TokenizerTestCase { } @Test - public void testOutsideBMPCodepoints() { + void testOutsideBMPCodepoints() { Tokenizer tokenizer = new Tokenizer(new SimpleLinguistics()); List<?> tokens = tokenizer.tokenize("\ud841\udd47"); assertEquals(new Token(WORD, "\ud841\udd47"), tokens.get(0)); } @Test - public void testOneSpecialToken() { + void testOneSpecialToken() { Tokenizer tokenizer = new Tokenizer(new SimpleLinguistics()); tokenizer.setSpecialTokens(createSpecialTokens().getSpecialTokens("default")); @@ -93,7 +91,7 @@ public class TokenizerTestCase { } @Test - public void testSpecialTokenCombination() { + void testSpecialTokenCombination() { Tokenizer tokenizer = new Tokenizer(new SimpleLinguistics()); tokenizer.setSpecialTokens(createSpecialTokens().getSpecialTokens("default")); @@ -121,7 +119,7 @@ public class TokenizerTestCase { * separated by space, as special token recognition happens before tokenization */ @Test - public void testSpecialTokenCJK() { + void testSpecialTokenCJK() { Tokenizer tokenizer = new Tokenizer(new SimpleLinguistics()); tokenizer.setSubstringSpecialTokens(true); tokenizer.setSpecialTokens(createSpecialTokens().getSpecialTokens("replacing")); @@ -146,7 +144,7 @@ public class TokenizerTestCase { } @Test - public void testSpecialTokenCaseInsensitive() { + void testSpecialTokenCaseInsensitive() { Tokenizer tokenizer = new Tokenizer(new SimpleLinguistics()); tokenizer.setSpecialTokens(createSpecialTokens().getSpecialTokens("default")); @@ -162,7 +160,7 @@ public class TokenizerTestCase { } @Test - public void testSpecialTokenNonMatch() { + void testSpecialTokenNonMatch() { Tokenizer tokenizer = new Tokenizer(new SimpleLinguistics()); tokenizer.setSpecialTokens(createSpecialTokens().getSpecialTokens("default")); @@ -187,7 +185,7 @@ public class TokenizerTestCase { } @Test - public void testSpecialTokenConfigurationDefault() { + void testSpecialTokenConfigurationDefault() { Tokenizer tokenizer = new Tokenizer(new SimpleLinguistics()); tokenizer.setSpecialTokens(createSpecialTokens().getSpecialTokens("default")); @@ -212,7 +210,7 @@ public class TokenizerTestCase { } @Test - public void testSpecialTokenConfigurationOther() { + void testSpecialTokenConfigurationOther() { Tokenizer tokenizer = new Tokenizer(new SimpleLinguistics()); tokenizer.setSpecialTokens(createSpecialTokens().getSpecialTokens("other")); @@ -247,7 +245,7 @@ public class TokenizerTestCase { } @Test - public void testTokenReplacing() { + void testTokenReplacing() { Tokenizer tokenizer = new Tokenizer(new SimpleLinguistics()); tokenizer.setSpecialTokens(createSpecialTokens().getSpecialTokens("replacing")); @@ -273,7 +271,7 @@ public class TokenizerTestCase { } @Test - public void testExactMatchTokenization() { + void testExactMatchTokenization() { SearchDefinition sd = new SearchDefinition("testsd"); Index index1 = new Index("testexact1"); @@ -286,8 +284,8 @@ public class TokenizerTestCase { IndexFacts facts = new IndexFacts(new IndexModel(sd)); IndexFacts.Session session = facts.newSession(Collections.emptySet(), Collections.emptySet()); - Tokenizer tokenizer=new Tokenizer(new SimpleLinguistics()); - List<?> tokens=tokenizer.tokenize("normal a:b (normal testexact1:/,%#%&+-+ ) testexact2:ho_/&%&/()/aa*::*& b:c", "default", session); + Tokenizer tokenizer = new Tokenizer(new SimpleLinguistics()); + List<?> tokens = tokenizer.tokenize("normal a:b (normal testexact1:/,%#%&+-+ ) testexact2:ho_/&%&/()/aa*::*& b:c", "default", session); // tokenizer.print(); assertEquals(new Token(WORD, "normal"), tokens.get(0)); assertEquals(new Token(SPACE, " "), tokens.get(1)); @@ -317,7 +315,7 @@ public class TokenizerTestCase { } @Test - public void testExactMatchTokenizationTerminatorTerminatesQuery() { + void testExactMatchTokenizationTerminatorTerminatesQuery() { SearchDefinition sd = new SearchDefinition("testsd"); Index index1 = new Index("testexact1"); @@ -354,7 +352,7 @@ public class TokenizerTestCase { } @Test - public void testExactMatchTokenizationWithTerminatorTerminatedByEndOfString() { + void testExactMatchTokenizationWithTerminatorTerminatedByEndOfString() { SearchDefinition sd = new SearchDefinition("testsd"); Index index1 = new Index("testexact1"); @@ -391,7 +389,7 @@ public class TokenizerTestCase { } @Test - public void testExactMatchTokenizationEndsByColon() { + void testExactMatchTokenizationEndsByColon() { SearchDefinition sd = new SearchDefinition("testsd"); Index index1 = new Index("testexact1"); @@ -429,7 +427,7 @@ public class TokenizerTestCase { } @Test - public void testExactMatchHeuristics() { + void testExactMatchHeuristics() { SearchDefinition sd = new SearchDefinition("testsd"); Index index1 = new Index("testexact1"); @@ -542,7 +540,7 @@ public class TokenizerTestCase { assertEquals(new Token(WORD, "testexact1"), tokens.get(0)); assertEquals(new Token(COLON, ":"), tokens.get(1)); assertEquals(new Token(STAR, "*"), tokens.get(2)); - assertEquals(new Token(WORD, "foobar*!100"),tokens.get(3)); + assertEquals(new Token(WORD, "foobar*!100"), tokens.get(3)); assertEquals(new Token(EXCLAMATION, "!"), tokens.get(4)); tokens = tokenizer.tokenize("testexact1:foo(bar)", facts); @@ -582,7 +580,7 @@ public class TokenizerTestCase { tokens = tokenizer.tokenize("testexact1:\"news search\" testexact2:resolved", facts); assertEquals(new Token(WORD, "testexact1"), tokens.get(0)); assertEquals(new Token(COLON, ":"), tokens.get(1)); - assertEquals(new Token(WORD, "news search"),tokens.get(2)); + assertEquals(new Token(WORD, "news search"), tokens.get(2)); assertEquals(new Token(SPACE, " "), tokens.get(3)); assertEquals(new Token(WORD, "testexact2"), tokens.get(4)); assertEquals(new Token(COLON, ":"), tokens.get(5)); @@ -592,7 +590,7 @@ public class TokenizerTestCase { assertEquals(new Token(LBRACE, "("), tokens.get(0)); assertEquals(new Token(WORD, "testexact1"), tokens.get(1)); assertEquals(new Token(COLON, ":"), tokens.get(2)); - assertEquals(new Token(WORD, "news search"),tokens.get(3)); + assertEquals(new Token(WORD, "news search"), tokens.get(3)); assertEquals(new Token(SPACE, " "), tokens.get(4)); assertEquals(new Token(WORD, "testexact1"), tokens.get(5)); assertEquals(new Token(COLON, ":"), tokens.get(6)); @@ -614,7 +612,7 @@ public class TokenizerTestCase { tokens = tokenizer.tokenize("testexact1:\"news search\"!200", facts); assertEquals(new Token(WORD, "testexact1"), tokens.get(0)); assertEquals(new Token(COLON, ":"), tokens.get(1)); - assertEquals(new Token(WORD, "news search"),tokens.get(2)); + assertEquals(new Token(WORD, "news search"), tokens.get(2)); assertEquals(new Token(EXCLAMATION, "!"), tokens.get(3)); assertEquals(new Token(NUMBER, "200"), tokens.get(4)); @@ -705,7 +703,7 @@ public class TokenizerTestCase { } @Test - public void testSingleQuoteAsWordCharacter() { + void testSingleQuoteAsWordCharacter() { Tokenizer tokenizer = new Tokenizer(new SimpleLinguistics()); tokenizer.setSpecialTokens(createSpecialTokens().getSpecialTokens("default")); diff --git a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/WashPhrasesTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/WashPhrasesTestCase.java index 061089cd25f..f0b768a010f 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/WashPhrasesTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/WashPhrasesTestCase.java @@ -13,10 +13,10 @@ import com.yahoo.search.query.parser.Parsable; import com.yahoo.search.query.parser.Parser; import com.yahoo.search.query.parser.ParserEnvironment; import com.yahoo.search.query.parser.ParserFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; /** * Tests guards against in single item phrases. @@ -26,7 +26,7 @@ import static org.junit.Assert.assertNull; public class WashPhrasesTestCase { @Test - public void testSimplePositive() { + void testSimplePositive() { PhraseItem root = new PhraseItem(); root.addItem(new WordItem("abc")); @@ -34,7 +34,7 @@ public class WashPhrasesTestCase { } @Test - public void testPositive1() { + void testPositive1() { AndItem root = new AndItem(); root.addItem(new WordItem("a")); @@ -47,7 +47,7 @@ public class WashPhrasesTestCase { } @Test - public void testPositive2() { + void testPositive2() { AndItem root = new AndItem(); root.addItem(new WordItem("a")); @@ -64,22 +64,22 @@ public class WashPhrasesTestCase { } @Test - public void testNoTerms() { + void testNoTerms() { assertNull(transformQuery("\"\"")); } @Test - public void testNegative1() { + void testNegative1() { assertEquals("\"abc def\"", transformQuery("\"abc def\"")); } @Test - public void testNegative2() { + void testNegative2() { assertEquals("AND a \"abc def\" b", transformQuery("a \"abc def\" b")); } - @Test - public void testNegative3() { + @Test + void testNegative3() { AndItem root = new AndItem(); root.addItem(new WordItem("a")); diff --git a/container-search/src/test/java/com/yahoo/prelude/query/test/DotProductItemTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/test/DotProductItemTestCase.java index 1585e58ca5d..2bb8584cba3 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/test/DotProductItemTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/test/DotProductItemTestCase.java @@ -1,28 +1,27 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.query.test; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - +import org.junit.jupiter.api.Test; import com.yahoo.prelude.query.*; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * @author havardpe */ public class DotProductItemTestCase { @Test - public void testDotProductItem() { + void testDotProductItem() { DotProductItem item = new DotProductItem("index_name"); assertEquals("index_name", item.getIndexName()); assertEquals(Item.ItemType.DOTPRODUCT, item.getItemType()); } @Test - public void testDotProductClone() { + void testDotProductClone() { DotProductItem dpOrig = new DotProductItem("myDP"); - dpOrig.addToken("first",11); + dpOrig.addToken("first", 11); dpOrig.getTokens(); DotProductItem dpClone = (DotProductItem) dpOrig.clone(); dpClone.addToken("second", 22); diff --git a/container-search/src/test/java/com/yahoo/prelude/query/test/IntItemTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/test/IntItemTestCase.java index 28cf5008417..3e1abddbdf4 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/test/IntItemTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/test/IntItemTestCase.java @@ -5,9 +5,9 @@ import com.yahoo.prelude.query.AndItem; import com.yahoo.prelude.query.IntItem; import com.yahoo.prelude.query.WeakAndItem; import com.yahoo.search.Query; -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 bratseth @@ -15,7 +15,7 @@ import static org.junit.Assert.assertEquals; public class IntItemTestCase { @Test - public void testEquals() { + void testEquals() { Query q1 = new Query("/?query=123%20456%20789"); Query q2 = new Query("/?query=123%20456"); diff --git a/container-search/src/test/java/com/yahoo/prelude/query/test/ItemEncodingTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/test/ItemEncodingTestCase.java index eb880bab826..c43d7e3b9d5 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/test/ItemEncodingTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/test/ItemEncodingTestCase.java @@ -10,11 +10,11 @@ import com.yahoo.prelude.query.PureWeightedInteger; import com.yahoo.prelude.query.PureWeightedString; import com.yahoo.prelude.query.WeakAndItem; import com.yahoo.prelude.query.WordItem; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.nio.ByteBuffer; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Item encoding tests @@ -25,17 +25,17 @@ public class ItemEncodingTestCase { private void assertType(ByteBuffer buffer, int etype, int features) { byte type = buffer.get(); - assertEquals("Code", etype, type & 0x1f); - assertEquals("Features", features, (type & 0xe0) >> 5); + assertEquals(etype, type & 0x1f, "Code"); + assertEquals(features, (type & 0xe0) >> 5, "Features"); } private void assertWeight(ByteBuffer buffer, int weight) { int w = (weight > (1 << 5)) ? buffer.getShort() & 0x3fff: buffer.get(); - assertEquals("Weight", weight, w); + assertEquals(weight, w, "Weight"); } @Test - public void testWordItemEncoding() { + void testWordItemEncoding() { WordItem word = new WordItem("test"); word.setWeight(150); @@ -44,14 +44,14 @@ public class ItemEncodingTestCase { buffer.flip(); - assertEquals("Serialization count", 1, count); + assertEquals(1, count, "Serialization count"); assertType(buffer, 4, 1); assertWeight(buffer, 150); - assertEquals("Index length", 0, buffer.get()); - assertEquals("Word length", 4, buffer.get()); - assertEquals("Word length", 4, buffer.remaining()); + assertEquals(0, buffer.get(), "Index length"); + assertEquals(4, buffer.get(), "Word length"); + assertEquals(4, buffer.remaining(), "Word length"); assertEquals('t', buffer.get()); assertEquals('e', buffer.get()); assertEquals('s', buffer.get()); @@ -59,20 +59,20 @@ public class ItemEncodingTestCase { } @Test - public void testStartHostMarkerEncoding() { + void testStartHostMarkerEncoding() { WordItem word = MarkerWordItem.createStartOfHost(); ByteBuffer buffer = ByteBuffer.allocate(128); int count = word.encode(buffer); buffer.flip(); - assertEquals("Serialization count", 1, count); + assertEquals(1, count, "Serialization count"); assertType(buffer, 4, 0); - assertEquals("Index length", 0, buffer.get()); - assertEquals("Word length", 9, buffer.get()); - assertEquals("Word length", 9, buffer.remaining()); + assertEquals(0, buffer.get(), "Index length"); + assertEquals(9, buffer.get(), "Word length"); + assertEquals(9, buffer.remaining(), "Word length"); assertEquals('S', buffer.get()); assertEquals('t', buffer.get()); assertEquals('A', buffer.get()); @@ -85,7 +85,7 @@ public class ItemEncodingTestCase { } @Test - public void testEndHostMarkerEncoding() { + void testEndHostMarkerEncoding() { WordItem word = MarkerWordItem.createEndOfHost(); ByteBuffer buffer = ByteBuffer.allocate(128); @@ -93,13 +93,13 @@ public class ItemEncodingTestCase { buffer.flip(); - assertEquals("Serialization count", 1, count); + assertEquals(1, count, "Serialization count"); assertType(buffer, 4, 0); - assertEquals("Index length", 0, buffer.get()); - assertEquals("Word length", 7, buffer.get()); - assertEquals("Word length", 7, buffer.remaining()); + assertEquals(0, buffer.get(), "Index length"); + assertEquals(7, buffer.get(), "Word length"); + assertEquals(7, buffer.remaining(), "Word length"); assertEquals('E', buffer.get()); assertEquals('n', buffer.get()); assertEquals('D', buffer.get()); @@ -110,7 +110,7 @@ public class ItemEncodingTestCase { } @Test - public void testFilterWordItemEncoding() { + void testFilterWordItemEncoding() { WordItem word = new WordItem("test"); word.setFilter(true); @@ -119,14 +119,14 @@ public class ItemEncodingTestCase { buffer.flip(); - assertEquals("Serialization count", 1, count); + assertEquals(1, count, "Serialization count"); assertType(buffer, 4, 4); assertEquals(0x08, buffer.get()); - assertEquals("Index length", 0, buffer.get()); - assertEquals("Word length", 4, buffer.get()); - assertEquals("Word length", 4, buffer.remaining()); + assertEquals(0, buffer.get(), "Index length"); + assertEquals(4, buffer.get(), "Word length"); + assertEquals(4, buffer.remaining(), "Word length"); assertEquals('t', buffer.get()); assertEquals('e', buffer.get()); assertEquals('s', buffer.get()); @@ -134,7 +134,7 @@ public class ItemEncodingTestCase { } @Test - public void testNoRankedNoPositionDataWordItemEncoding() { + void testNoRankedNoPositionDataWordItemEncoding() { WordItem word = new WordItem("test"); word.setRanked(false); word.setPositionData(false); @@ -144,14 +144,14 @@ public class ItemEncodingTestCase { buffer.flip(); - assertEquals("Serialization count", 1, count); + assertEquals(1, count, "Serialization count"); assertType(buffer, 4, 4); assertEquals(0x05, buffer.get()); - assertEquals("Index length", 0, buffer.get()); - assertEquals("Word length", 4, buffer.get()); - assertEquals("Word length", 4, buffer.remaining()); + assertEquals(0, buffer.get(), "Index length"); + assertEquals(4, buffer.get(), "Word length"); + assertEquals(4, buffer.remaining(), "Word length"); assertEquals('t', buffer.get()); assertEquals('e', buffer.get()); assertEquals('s', buffer.get()); @@ -159,10 +159,10 @@ public class ItemEncodingTestCase { } @Test - public void testAndItemEncoding() { + void testAndItemEncoding() { WordItem a = new WordItem("a"); WordItem b = new WordItem("b"); - AndItem and=new AndItem(); + AndItem and = new AndItem(); and.addItem(a); and.addItem(b); @@ -171,21 +171,21 @@ public class ItemEncodingTestCase { buffer.flip(); - assertEquals("Serialization count", 3, count); + assertEquals(3, count, "Serialization count"); assertType(buffer, 1, 0); - assertEquals("And arity", 2, buffer.get()); + assertEquals(2, buffer.get(), "And arity"); - assertWord(buffer,"a"); - assertWord(buffer,"b"); + assertWord(buffer, "a"); + assertWord(buffer, "b"); } @Test - public void testNearItemEncoding() { + void testNearItemEncoding() { WordItem a = new WordItem("a"); WordItem b = new WordItem("b"); - NearItem near=new NearItem(7); + NearItem near = new NearItem(7); near.addItem(a); near.addItem(b); @@ -194,22 +194,22 @@ public class ItemEncodingTestCase { buffer.flip(); - assertEquals("Serialization count", 3, count); + assertEquals(3, count, "Serialization count"); assertType(buffer, 11, 0); - assertEquals("Near arity", 2, buffer.get()); - assertEquals("Limit", 7, buffer.get()); + assertEquals(2, buffer.get(), "Near arity"); + assertEquals(7, buffer.get(), "Limit"); - assertWord(buffer,"a"); - assertWord(buffer,"b"); + assertWord(buffer, "a"); + assertWord(buffer, "b"); } @Test - public void testONearItemEncoding() { + void testONearItemEncoding() { WordItem a = new WordItem("a"); WordItem b = new WordItem("b"); - NearItem onear=new ONearItem(7); + NearItem onear = new ONearItem(7); onear.addItem(a); onear.addItem(b); @@ -218,18 +218,18 @@ public class ItemEncodingTestCase { buffer.flip(); - assertEquals("Serialization count", 3, count); + assertEquals(3, count, "Serialization count"); assertType(buffer, 12, 0); - assertEquals("Near arity", 2, buffer.get()); - assertEquals("Limit", 7, buffer.get()); + assertEquals(2, buffer.get(), "Near arity"); + assertEquals(7, buffer.get(), "Limit"); - assertWord(buffer,"a"); - assertWord(buffer,"b"); + assertWord(buffer, "a"); + assertWord(buffer, "b"); } @Test - public void testEquivItemEncoding() { + void testEquivItemEncoding() { WordItem a = new WordItem("a"); WordItem b = new WordItem("b"); EquivItem equiv = new EquivItem(); @@ -241,17 +241,17 @@ public class ItemEncodingTestCase { buffer.flip(); - assertEquals("Serialization count", 3, count); + assertEquals(3, count, "Serialization count"); assertType(buffer, 14, 0); - assertEquals("Equiv arity", 2, buffer.get()); + assertEquals(2, buffer.get(), "Equiv arity"); assertWord(buffer, "a"); assertWord(buffer, "b"); } @Test - public void testWandItemEncoding() { + void testWandItemEncoding() { WordItem a = new WordItem("a"); WordItem b = new WordItem("b"); WeakAndItem wand = new WeakAndItem(); @@ -263,11 +263,11 @@ public class ItemEncodingTestCase { buffer.flip(); - assertEquals("Serialization count", 3, count); + assertEquals(3, count, "Serialization count"); assertType(buffer, 16, 0); - assertEquals("WeakAnd arity", 2, buffer.get()); - assertEquals("WeakAnd N", 100, buffer.getShort() & 0x3fff); + assertEquals(2, buffer.get(), "WeakAnd arity"); + assertEquals(100, buffer.getShort() & 0x3fff, "WeakAnd N"); assertEquals(0, buffer.get()); assertWord(buffer, "a"); @@ -275,65 +275,66 @@ public class ItemEncodingTestCase { } @Test - public void testPureWeightedStringEncoding() { + void testPureWeightedStringEncoding() { PureWeightedString a = new PureWeightedString("a"); ByteBuffer buffer = ByteBuffer.allocate(128); int count = a.encode(buffer); buffer.flip(); - assertEquals("Serialization size", 3, buffer.remaining()); - assertEquals("Serialization count", 1, count); + assertEquals(3, buffer.remaining(), "Serialization size"); + assertEquals(1, count, "Serialization count"); assertType(buffer, 19, 0); assertString(buffer, a.getString()); } @Test - public void testPureWeightedStringEncodingWithNonDefaultWeight() { + void testPureWeightedStringEncodingWithNonDefaultWeight() { PureWeightedString a = new PureWeightedString("a", 7); ByteBuffer buffer = ByteBuffer.allocate(128); int count = a.encode(buffer); buffer.flip(); - assertEquals("Serialization size", 4, buffer.remaining()); - assertEquals("Serialization count", 1, count); + assertEquals(4, buffer.remaining(), "Serialization size"); + assertEquals(1, count, "Serialization count"); assertType(buffer, 19, 1); assertWeight(buffer, 7); assertString(buffer, a.getString()); } @Test - public void testPureWeightedIntegerEncoding() { + void testPureWeightedIntegerEncoding() { PureWeightedInteger a = new PureWeightedInteger(23432568763534865l); ByteBuffer buffer = ByteBuffer.allocate(128); int count = a.encode(buffer); buffer.flip(); - assertEquals("Serialization size", 9, buffer.remaining()); - assertEquals("Serialization count", 1, count); + assertEquals(9, buffer.remaining(), "Serialization size"); + assertEquals(1, count, "Serialization count"); assertType(buffer, 20, 0); - assertEquals("Value", a.getValue(), buffer.getLong()); + assertEquals(a.getValue(), buffer.getLong(), "Value"); } @Test - public void testPureWeightedLongEncodingWithNonDefaultWeight() { + void testPureWeightedLongEncodingWithNonDefaultWeight() { PureWeightedInteger a = new PureWeightedInteger(23432568763534865l, 7); ByteBuffer buffer = ByteBuffer.allocate(128); int count = a.encode(buffer); buffer.flip(); - assertEquals("Serialization size", 10, buffer.remaining()); - assertEquals("Serialization count", 1, count); + assertEquals(10, buffer.remaining(), "Serialization size"); + assertEquals(1, count, "Serialization count"); assertType(buffer, 20, 1); assertWeight(buffer, 7); - assertEquals("Value", a.getValue(), buffer.getLong());; + assertEquals(a.getValue(), buffer.getLong(), "Value"); + ; } private void assertString(ByteBuffer buffer, String word) { - assertEquals("Word length", word.length(), buffer.get()); + assertEquals(word.length(), buffer.get(), "Word length"); for (int i=0; i<word.length(); i++) { - assertEquals("Character at " + i,word.charAt(i), buffer.get()); + assertEquals(word.charAt(i), buffer.get(), "Character at " + i); } } private void assertWord(ByteBuffer buffer,String word) { assertType(buffer, 4, 0); - assertEquals("Index length", 0, buffer.get()); + assertEquals(0, buffer.get(), "Index length"); assertString(buffer, word); } diff --git a/container-search/src/test/java/com/yahoo/prelude/query/test/PhraseItemTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/test/PhraseItemTestCase.java index bd0bfd3f29a..1e4418f1b73 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/test/PhraseItemTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/test/PhraseItemTestCase.java @@ -4,9 +4,9 @@ package com.yahoo.prelude.query.test; import com.yahoo.prelude.query.PhraseItem; import com.yahoo.prelude.query.PhraseSegmentItem; import com.yahoo.prelude.query.WordItem; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Test methods changing phrase items. @@ -16,7 +16,7 @@ import static org.junit.Assert.assertEquals; public class PhraseItemTestCase { @Test - public void testAddItem() { + void testAddItem() { PhraseItem p = new PhraseItem(); PhraseSegmentItem pp = new PhraseSegmentItem("", false, false); PhraseItem ppp = new PhraseItem(); @@ -32,7 +32,7 @@ public class PhraseItemTestCase { } @Test - public void testAddItemWithIndex() { + void testAddItemWithIndex() { PhraseItem p = new PhraseItem(); PhraseSegmentItem pp = new PhraseSegmentItem("", false, false); PhraseItem ppp = new PhraseItem(); @@ -48,7 +48,7 @@ public class PhraseItemTestCase { } @Test - public void testSetItem() { + void testSetItem() { PhraseItem backup = new PhraseItem(); PhraseSegmentItem segment = new PhraseSegmentItem("", false, false); PhraseItem innerPhrase = new PhraseItem(); diff --git a/container-search/src/test/java/com/yahoo/prelude/query/test/PredicateQueryItemTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/test/PredicateQueryItemTestCase.java index 1fe0ded8d6b..a27a11b8f15 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/test/PredicateQueryItemTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/test/PredicateQueryItemTestCase.java @@ -3,14 +3,14 @@ package com.yahoo.prelude.query.test; import com.yahoo.prelude.query.Item; import com.yahoo.prelude.query.PredicateQueryItem; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Iterator; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Magnar Nedland @@ -18,7 +18,7 @@ import static org.junit.Assert.assertEquals; public class PredicateQueryItemTestCase { @Test - public void requireThatItemConstantsAreSet() { + void requireThatItemConstantsAreSet() { PredicateQueryItem item = new PredicateQueryItem(); assertEquals(Item.ItemType.PREDICATE_QUERY, item.getItemType()); assertEquals("PREDICATE_QUERY_ITEM", item.getName()); @@ -29,7 +29,7 @@ public class PredicateQueryItemTestCase { } @Test - public void requireThatFeaturesCanBeAdded() { + void requireThatFeaturesCanBeAdded() { PredicateQueryItem item = new PredicateQueryItem(); assertEquals(0, item.getFeatures().size()); item.addFeature("foo", "bar"); @@ -45,7 +45,7 @@ public class PredicateQueryItemTestCase { } @Test - public void requireThatRangeFeaturesCanBeAdded() { + void requireThatRangeFeaturesCanBeAdded() { PredicateQueryItem item = new PredicateQueryItem(); assertEquals(0, item.getRangeFeatures().size()); item.addRangeFeature("foo", 23); @@ -61,7 +61,7 @@ public class PredicateQueryItemTestCase { } @Test - public void requireThatToStringWorks() { + void requireThatToStringWorks() { PredicateQueryItem item = new PredicateQueryItem(); assertEquals("PREDICATE_QUERY_ITEM ", item.toString()); item.addFeature("foo", "bar"); @@ -73,7 +73,7 @@ public class PredicateQueryItemTestCase { } @Test - public void requireThatPredicateQueryItemCanBeEncoded() { + void requireThatPredicateQueryItemCanBeEncoded() { PredicateQueryItem item = new PredicateQueryItem(); assertEquals("PREDICATE_QUERY_ITEM ", item.toString()); item.addFeature("foo", "bar"); @@ -84,12 +84,12 @@ public class PredicateQueryItemTestCase { byte[] actual = new byte[buffer.remaining()]; buffer.get(actual); assertArrayEquals(new byte[]{ - 23, // PREDICATE_QUERY code 23 - 9, 'p', 'r', 'e', 'd', 'i', 'c', 'a', 't', 'e', - 2, // 2 features - 3, 'f', 'o', 'o', 3, 'b', 'a', 'r', -1, -1, -1, -1, -1, -1, -1, -1, // key, value, subquery - 3, 'f', 'o', 'o', 3, 'b', 'a', 'z', 0, 0, 0, 0, 0, 0, -1, -1, // key, value, subquery - 0}, // no range features + 23, // PREDICATE_QUERY code 23 + 9, 'p', 'r', 'e', 'd', 'i', 'c', 'a', 't', 'e', + 2, // 2 features + 3, 'f', 'o', 'o', 3, 'b', 'a', 'r', -1, -1, -1, -1, -1, -1, -1, -1, // key, value, subquery + 3, 'f', 'o', 'o', 3, 'b', 'a', 'z', 0, 0, 0, 0, 0, 0, -1, -1, // key, value, subquery + 0}, // no range features actual); item.addRangeFeature("foo", 23); @@ -100,19 +100,19 @@ public class PredicateQueryItemTestCase { actual = new byte[buffer.remaining()]; buffer.get(actual); assertArrayEquals(new byte[]{ - 23, // PREDICATE_QUERY code 23 - 9, 'p', 'r', 'e', 'd', 'i', 'c', 'a', 't', 'e', - 2, // 2 features - 3, 'f', 'o', 'o', 3, 'b', 'a', 'r', -1, -1, -1, -1, -1, -1, -1, -1, // key, value, subquery - 3, 'f', 'o', 'o', 3, 'b', 'a', 'z', 0, 0, 0, 0, 0, 0, -1, -1, // key, value, subquery - 2, // 2 range features - 3, 'f', 'o', 'o', 0, 0, 0, 0, 0, 0, 0, 23, -1, -1, -1, -1, -1, -1, -1, -1, // key, value, subquery - 3, 'f', 'o', 'o', 0, 0, 0, 0, 0, 0, 0, 34, -1, -1, -1, -1, -1, -1, -1, -2}, // key, value, subquery + 23, // PREDICATE_QUERY code 23 + 9, 'p', 'r', 'e', 'd', 'i', 'c', 'a', 't', 'e', + 2, // 2 features + 3, 'f', 'o', 'o', 3, 'b', 'a', 'r', -1, -1, -1, -1, -1, -1, -1, -1, // key, value, subquery + 3, 'f', 'o', 'o', 3, 'b', 'a', 'z', 0, 0, 0, 0, 0, 0, -1, -1, // key, value, subquery + 2, // 2 range features + 3, 'f', 'o', 'o', 0, 0, 0, 0, 0, 0, 0, 23, -1, -1, -1, -1, -1, -1, -1, -1, // key, value, subquery + 3, 'f', 'o', 'o', 0, 0, 0, 0, 0, 0, 0, 34, -1, -1, -1, -1, -1, -1, -1, -2}, // key, value, subquery actual); } @Test - public void requireThatPredicateQueryItemWithManyAttributesCanBeEncoded() { + void requireThatPredicateQueryItemWithManyAttributesCanBeEncoded() { PredicateQueryItem item = new PredicateQueryItem(); assertEquals("PREDICATE_QUERY_ITEM ", item.toString()); for (int i = 0; i < 200; ++i) { @@ -126,11 +126,11 @@ public class PredicateQueryItemTestCase { byte [] expectedPrefix = new byte[]{ 23, // PREDICATE_QUERY code 23 9, 'p', 'r', 'e', 'd', 'i', 'c', 'a', 't', 'e', - (byte)0x80, (byte)0xc8, // 200 features (0x80c8 => 0xc8 == 200) + (byte) 0x80, (byte) 0xc8, // 200 features (0x80c8 => 0xc8 == 200) 3, 'f', 'o', 'o', 3, 'b', 'a', 'r', -1, -1, -1, -1, -1, -1, -1, -1, // key, value, subquery 3, 'f', 'o', 'o', 3, 'b', 'a', 'r', -1, -1, -1, -1, -1, -1, -1, -1, // key, value, subquery 3, 'f', 'o', 'o', 3, 'b', 'a', 'r', -1, -1, -1, -1, -1, -1, -1, -1, // key, value, subquery - }; // ... + }; // ... assertArrayEquals(expectedPrefix, Arrays.copyOfRange(actual, 0, expectedPrefix.length)); } diff --git a/container-search/src/test/java/com/yahoo/prelude/query/test/QueryCanonicalizerTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/test/QueryCanonicalizerTestCase.java index cd8691d9db0..81aa28a5326 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/test/QueryCanonicalizerTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/test/QueryCanonicalizerTestCase.java @@ -4,12 +4,9 @@ package com.yahoo.prelude.query.test; import com.yahoo.prelude.query.*; import com.yahoo.search.Query; import com.yahoo.search.query.QueryTree; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.*; /** * @author bratseth @@ -17,7 +14,7 @@ import static org.junit.Assert.assertFalse; public class QueryCanonicalizerTestCase { @Test - public void testSingleLevelSingleItemComposite() { + void testSingleLevelSingleItemComposite() { CompositeItem root = new AndItem(); root.addItem(new WordItem("word")); @@ -25,7 +22,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testSingleLevelSingleItemNonReducibleComposite() { + void testSingleLevelSingleItemNonReducibleComposite() { CompositeItem root = new WeakAndItem(); root.addItem(new WordItem("word")); @@ -33,7 +30,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testMultilevelSingleItemComposite() { + void testMultilevelSingleItemComposite() { CompositeItem root = new AndItem(); CompositeItem and1 = new AndItem(); CompositeItem and2 = new AndItem(); @@ -45,7 +42,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testMultilevelComposite() { + void testMultilevelComposite() { // AND (RANK (AND a b c)) WAND(25,0.0,1.0) AndItem and = new AndItem(); RankItem rank = new RankItem(); @@ -62,7 +59,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testMultilevelEmptyComposite() { + void testMultilevelEmptyComposite() { CompositeItem root = new AndItem(); CompositeItem and1 = new AndItem(); CompositeItem and2 = new AndItem(); @@ -73,7 +70,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testMultilevelMultiBranchEmptyComposite() { + void testMultilevelMultiBranchEmptyComposite() { CompositeItem root = new AndItem(); CompositeItem and1 = new AndItem(); CompositeItem and21 = new AndItem(); @@ -90,7 +87,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testMultilevelMultiBranchSingleItemComposite() { + void testMultilevelMultiBranchSingleItemComposite() { CompositeItem root = new AndItem(); CompositeItem and1 = new AndItem(); CompositeItem and21 = new AndItem(); @@ -108,7 +105,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testMultilevelWeakAndCollapsing() { + void testMultilevelWeakAndCollapsing() { CompositeItem root = new WeakAndItem(); CompositeItem l1 = new WeakAndItem(); CompositeItem l2 = new WeakAndItem(); @@ -132,7 +129,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testWeakAndCollapsingRequireSameNAndIndex() { + void testWeakAndCollapsingRequireSameNAndIndex() { CompositeItem root = new WeakAndItem(10); CompositeItem l1 = new WeakAndItem(100); CompositeItem l2 = new WeakAndItem(100); @@ -149,12 +146,12 @@ public class QueryCanonicalizerTestCase { } @Test - public void testNullRoot() { + void testNullRoot() { assertCanonicalized(null, "No query", new Query()); } @Test - public void testNestedNull() { + void testNestedNull() { CompositeItem root = new AndItem(); CompositeItem or = new AndItem(); CompositeItem and = new AndItem(); @@ -169,7 +166,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testNestedNullItem() { + void testNestedNullItem() { CompositeItem root = new AndItem(); CompositeItem or = new AndItem(); CompositeItem and = new AndItem(); @@ -186,7 +183,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testNestedNullAndSingle() { + void testNestedNullAndSingle() { CompositeItem root = new AndItem(); CompositeItem or = new OrItem(); @@ -199,7 +196,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testRemovalOfUnnecessaryComposites() { + void testRemovalOfUnnecessaryComposites() { CompositeItem root = new AndItem(); CompositeItem or = new OrItem(); @@ -215,21 +212,21 @@ public class QueryCanonicalizerTestCase { /** Multiple levels of the same AND/OR should collapse */ @Test - public void testMultilevelCollapsing() { + void testMultilevelCollapsing() { CompositeItem root = new AndItem(); CompositeItem l1 = new AndItem(); CompositeItem l2 = new AndItem(); CompositeItem l3 = new AndItem(); - + root.addItem(l1); l1.addItem(new WordItem("l1i1")); l1.addItem(l2); - + l2.addItem(new WordItem("l2i1")); l2.addItem(l3); l2.addItem(new WordItem("l2i2")); - + l3.addItem(new WordItem("l3i1")); l3.addItem(new WordItem("l3i2")); @@ -238,7 +235,7 @@ public class QueryCanonicalizerTestCase { /** Multiple levels of different composites should not collapse */ @Test - public void testMultilevelNonCollapsing() { + void testMultilevelNonCollapsing() { CompositeItem root = new AndItem(); CompositeItem l1 = new AndItem(); CompositeItem l2 = new OrItem(); @@ -259,7 +256,7 @@ public class QueryCanonicalizerTestCase { /** Multiple levels of RANK should collapse */ @Test - public void testMultilevelRankCollapsing() { + void testMultilevelRankCollapsing() { CompositeItem root = new RankItem(); CompositeItem l1 = new RankItem(); CompositeItem l2 = new RankItem(); @@ -283,7 +280,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testNegativeMustHaveNegatives() { + void testNegativeMustHaveNegatives() { CompositeItem root = new NotItem(); root.addItem(new WordItem("positive")); @@ -291,26 +288,26 @@ public class QueryCanonicalizerTestCase { } @Test - public void testNegative() { + void testNegative() { NotItem root = new NotItem(); root.addNegativeItem(new WordItem("negative")); - assertCanonicalized("-negative",null, root); + assertCanonicalized("-negative", null, root); } @Test - public void testNegativeOnly() { + void testNegativeOnly() { CompositeItem root = new AndItem(); NotItem not = new NotItem(); root.addItem(not); root.addItem(new WordItem("word")); not.addNegativeItem(new WordItem("negative")); - assertCanonicalized("AND (-negative) word",null, root); + assertCanonicalized("AND (-negative) word", null, root); } @Test - public void testCollapseFalseItemInAnd() { + void testCollapseFalseItemInAnd() { CompositeItem root = new AndItem(); root.addItem(new WordItem("i1")); root.addItem(new FalseItem()); @@ -318,7 +315,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testRemoveFalseItemInOr() { + void testRemoveFalseItemInOr() { CompositeItem root = new OrItem(); AndItem and = new AndItem(); // this gets collapse to just FALSE, which is then removed root.addItem(and); @@ -329,7 +326,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testCollapseFalseItemInNot() { + void testCollapseFalseItemInNot() { CompositeItem root = new NotItem(); root.addItem(new FalseItem()); // false ANDNOT ... is false root.addItem(new WordItem("i1")); @@ -337,7 +334,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testRemoveFalseItemInNot() { + void testRemoveFalseItemInNot() { CompositeItem root = new NotItem(); root.addItem(new WordItem("i1")); root.addItem(new FalseItem()); // ... ANDNOT false is redundant @@ -345,7 +342,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testCollapseFalseItemInRank() { + void testCollapseFalseItemInRank() { CompositeItem root = new RankItem(); root.addItem(new FalseItem()); // false RANK ... is false root.addItem(new WordItem("i1")); @@ -353,7 +350,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testRemoveFalseItemInRank() { + void testRemoveFalseItemInRank() { CompositeItem root = new RankItem(); root.addItem(new WordItem("i1")); root.addItem(new FalseItem()); // ... RANK false is redundant @@ -365,13 +362,13 @@ public class QueryCanonicalizerTestCase { * (which strictly is an implementation detail which we should rather hide). */ @Test - public void testConnexityAndCloning() { + void testConnexityAndCloning() { Query q = new Query("?query=a%20b"); CompositeItem root = (CompositeItem) q.getModel().getQueryTree().getRoot(); ((WordItem) root.getItem(0)).setConnectivity(root.getItem(1), java.lang.Math.E); q = q.clone(); - assertNull("Not prepared yet", q.getRanking().getProperties().get("vespa.term.1.connexity")); + assertNull(q.getRanking().getProperties().get("vespa.term.1.connexity"), "Not prepared yet"); q.prepare(); assertEquals("2", q.getRanking().getProperties().get("vespa.term.1.connexity").get(0)); assertEquals("2.718281828459045", q.getRanking().getProperties().get("vespa.term.1.connexity").get(1)); @@ -385,7 +382,7 @@ public class QueryCanonicalizerTestCase { * (which strictly is an implementation detail which we should rather hide). */ @Test - public void testSignificance() { + void testSignificance() { Query q = new Query("?query=a%20b"); CompositeItem root = (CompositeItem) q.getModel().getQueryTree().getRoot(); ((WordItem) root.getItem(0)).setSignificance(0.5); @@ -396,7 +393,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testPhraseWeight() { + void testPhraseWeight() { PhraseItem root = new PhraseItem(); root.setWeight(200); root.addItem(new WordItem("a")); @@ -404,7 +401,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testEquivDuplicateRemoval() { + void testEquivDuplicateRemoval() { { EquivItem root = new EquivItem(); root.addItem(new WordItem("a")); @@ -470,7 +467,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void testRankDuplicateCheapification() { + void testRankDuplicateCheapification() { AndItem and = new AndItem(); WordItem shoe = new WordItem("shoe", "prod"); and.addItem(shoe); @@ -491,7 +488,7 @@ public class QueryCanonicalizerTestCase { } @Test - public void queryTreeExceedsAllowedSize() { + void queryTreeExceedsAllowedSize() { Query query = new Query(); QueryTree tree = query.getModel().getQueryTree(); tree.setRoot(new WordItem("A")); @@ -513,7 +510,7 @@ public class QueryCanonicalizerTestCase { assertEquals(expectedError, error); if (canonicalForm == null) { - assertNull(null, query.getModel().getQueryTree().getRoot()); + assertNull(query.getModel().getQueryTree().getRoot()); } else { assertEquals(canonicalForm, query.getModel().getQueryTree().getRoot().toString()); } diff --git a/container-search/src/test/java/com/yahoo/prelude/query/test/QueryLanguageTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/test/QueryLanguageTestCase.java index a43f1a542c3..12d179b489e 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/test/QueryLanguageTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/test/QueryLanguageTestCase.java @@ -6,9 +6,9 @@ import com.yahoo.prelude.query.NotItem; import com.yahoo.prelude.query.PhraseItem; import com.yahoo.prelude.query.WordItem; import com.yahoo.search.Query; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * <p>Tests that the correct query language strings are generated for various @@ -24,14 +24,14 @@ import static org.junit.Assert.assertEquals; public class QueryLanguageTestCase { @Test - public void testWord() { + void testWord() { WordItem w = new WordItem("test"); assertEquals("test", w.toString()); } @Test - public void testWordWithIndex() { + void testWordWithIndex() { WordItem w = new WordItem("test"); w.setIndexName("test.index"); @@ -39,7 +39,7 @@ public class QueryLanguageTestCase { } @Test - public void testPhrase() { + void testPhrase() { PhraseItem p = new PhraseItem(); p.addItem(new WordItem("part")); @@ -49,7 +49,7 @@ public class QueryLanguageTestCase { } @Test - public void testPhraseWithIndex() { + void testPhraseWithIndex() { PhraseItem p = new PhraseItem(); p.addItem(new WordItem("part")); @@ -60,7 +60,7 @@ public class QueryLanguageTestCase { } @Test - public void testNotItem() { + void testNotItem() { NotItem n = new NotItem(); n.addNegativeItem(new WordItem("notthis")); @@ -70,22 +70,22 @@ public class QueryLanguageTestCase { } @Test - public void testLanguagesInQueryParameter() { + void testLanguagesInQueryParameter() { // Right parameter is the parameter given in the query, as language= // Left parameter is the language sent to linguistics // Ancient - assertLanguage(Language.CHINESE_SIMPLIFIED,"zh-cn"); - assertLanguage(Language.CHINESE_SIMPLIFIED,"zh-Hans"); - assertLanguage(Language.CHINESE_SIMPLIFIED,"zh-hans"); - assertLanguage(Language.CHINESE_TRADITIONAL,"zh-tw"); - assertLanguage(Language.CHINESE_TRADITIONAL,"zh-Hant"); - assertLanguage(Language.CHINESE_TRADITIONAL,"zh-hant"); - assertLanguage(Language.CHINESE_TRADITIONAL,"zh"); + assertLanguage(Language.CHINESE_SIMPLIFIED, "zh-cn"); + assertLanguage(Language.CHINESE_SIMPLIFIED, "zh-Hans"); + assertLanguage(Language.CHINESE_SIMPLIFIED, "zh-hans"); + assertLanguage(Language.CHINESE_TRADITIONAL, "zh-tw"); + assertLanguage(Language.CHINESE_TRADITIONAL, "zh-Hant"); + assertLanguage(Language.CHINESE_TRADITIONAL, "zh-hant"); + assertLanguage(Language.CHINESE_TRADITIONAL, "zh"); assertLanguage(Language.ENGLISH, "en"); assertLanguage(Language.GERMAN, "de"); assertLanguage(Language.JAPANESE, "ja"); - assertLanguage(Language.fromLanguageTag("jp") ,"jp"); + assertLanguage(Language.fromLanguageTag("jp"), "jp"); assertLanguage(Language.KOREAN, "ko"); // Since 2.0 diff --git a/container-search/src/test/java/com/yahoo/prelude/query/test/QueryTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/test/QueryTestCase.java index bfdc9ae1552..1abbc2d87dc 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/test/QueryTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/test/QueryTestCase.java @@ -8,12 +8,12 @@ import com.yahoo.search.query.parser.Parsable; import com.yahoo.search.query.parser.Parser; import com.yahoo.search.query.parser.ParserEnvironment; import com.yahoo.search.query.parser.ParserFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Iterator; -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; /** * Tests query trees @@ -24,7 +24,7 @@ public class QueryTestCase { /** Tests that query hash and equality is value dependent only */ @Test - public void testQueryEquality() { + void testQueryEquality() { String query = "RANK (+(AND \"baz gaz faz\" bazar) -\"foo bar foobar\") foofoo xyzzy"; String filter = "foofoo -\"foo bar foobar\" xyzzy +\"baz gaz faz\" +bazar"; @@ -37,11 +37,11 @@ public class QueryTestCase { /** Check copy of query trees is a deep copy */ @Test - public void testDeepCopy() { + void testDeepCopy() { Item root1 = parseQuery("a and b and (c or d) and e rank f andnot g", null, Query.Type.ADVANCED); Item root2 = root1.clone(); - assertTrue("Item.clone() should be a deep copy.",nonIdenticalTrees(root1, root2)); + assertTrue(nonIdenticalTrees(root1, root2), "Item.clone() should be a deep copy."); } private static Item parseQuery(String query, String filter, Query.Type type) { diff --git a/container-search/src/test/java/com/yahoo/prelude/query/test/RangeItemTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/test/RangeItemTestCase.java index 3032a7b625f..a2f5016645b 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/test/RangeItemTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/test/RangeItemTestCase.java @@ -3,16 +3,16 @@ package com.yahoo.prelude.query.test; import com.yahoo.prelude.query.IntItem; import com.yahoo.prelude.query.RangeItem; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.nio.ByteBuffer; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class RangeItemTestCase { @Test - public void testRangeConstruction() { + void testRangeConstruction() { verifyRange(new RangeItem(5, 7, 9, "a", true), 9, true); verifyRange(new RangeItem(5, 7, "a", true), 0, true); verifyRange(new RangeItem(5, 7, "a"), 0, false); diff --git a/container-search/src/test/java/com/yahoo/prelude/query/test/SameElementItemTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/test/SameElementItemTestCase.java index c05d7d48f6b..198ad2b46f9 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/test/SameElementItemTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/test/SameElementItemTestCase.java @@ -9,20 +9,18 @@ import com.yahoo.prelude.query.Substring; import com.yahoo.prelude.query.TermItem; import com.yahoo.prelude.query.WordAlternativesItem; import com.yahoo.prelude.query.WordItem; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.List; import java.util.Optional; -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.*; public class SameElementItemTestCase { @Test - public void testAddItem() { + void testAddItem() { SameElementItem s = new SameElementItem("structa"); s.addItem(new WordItem("b", "f1")); s.addItem(new WordItem("c", "f2")); @@ -31,18 +29,18 @@ public class SameElementItemTestCase { } @Test - public void testClone() { + void testClone() { SameElementItem s = new SameElementItem("structa"); s.addItem(new WordItem("b", "f1")); s.addItem(new WordItem("c", "f2")); s.addItem(new WordItem("d", "f3")); assertEquals("structa:{f1:b f2:c f3:d}", s.toString()); - SameElementItem c = (SameElementItem)s.clone(); + SameElementItem c = (SameElementItem) s.clone(); assertEquals("structa:{f1:b f2:c f3:d}", c.toString()); } @Test - public void requireAllChildrenHaveStructMemberNameSet() { + void requireAllChildrenHaveStructMemberNameSet() { try { SameElementItem s = new SameElementItem("structa"); s.addItem(new WordItem("b", "f1")); @@ -55,7 +53,7 @@ public class SameElementItemTestCase { } @Test - public void requireAllowCommonPrefix() { + void requireAllowCommonPrefix() { SameElementItem s = new SameElementItem("structa"); s.addItem(new WordItem("b", "f1")); s.addItem(new WordItem("c", "structaf2")); @@ -63,7 +61,7 @@ public class SameElementItemTestCase { } @Test - public void requireChildrenCanHavePrefixCommonWithParent() { + void requireChildrenCanHavePrefixCommonWithParent() { SameElementItem s = new SameElementItem("structa"); s.addItem(new WordItem("b", "f1")); s.addItem(new WordItem("c", "structa.f2")); @@ -71,7 +69,7 @@ public class SameElementItemTestCase { } @Test - public void requireAllChildrenHaveNonEmptyTerm() { + void requireAllChildrenHaveNonEmptyTerm() { try { SameElementItem s = new SameElementItem("structa"); s.addItem(new WordItem("", "f2")); @@ -83,7 +81,7 @@ public class SameElementItemTestCase { } @Test - public void requireNoChildrenAreWordAlternatives() { + void requireNoChildrenAreWordAlternatives() { try { SameElementItem s = new SameElementItem("structa"); s.addItem(new AndItem()); @@ -91,12 +89,12 @@ public class SameElementItemTestCase { } catch (IllegalArgumentException e) { // Success assertEquals("Child item (AND ) should be an instance of class com.yahoo.prelude.query.TermItem but is class com.yahoo.prelude.query.AndItem", - e.getMessage()); + e.getMessage()); } } @Test - public void requireAllChildrenAreTermItems() { + void requireAllChildrenAreTermItems() { try { SameElementItem s = new SameElementItem("structa"); s.addItem(new WordAlternativesItem("test", true, new Substring("origin"), List.of(new WordAlternativesItem.Alternative("a", 0.3)))); @@ -118,13 +116,13 @@ public class SameElementItemTestCase { } @Test - public void requireExtractSingleItemToExtractSingles() { + void requireExtractSingleItemToExtractSingles() { verifyExtractSingle(new WordItem("b", "f1")); verifyExtractSingle(new IntItem("7", "f1")); } @Test - public void requireExtractSingleItemToExtractSinglesOnly() { + void requireExtractSingleItemToExtractSinglesOnly() { SameElementItem s = new SameElementItem("structa"); s.addItem(new WordItem("b", "f1")); s.addItem(new WordItem("c", "f2")); diff --git a/container-search/src/test/java/com/yahoo/prelude/query/test/SegmentItemTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/test/SegmentItemTestCase.java index 66653a95dbb..b0271bec896 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/test/SegmentItemTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/test/SegmentItemTestCase.java @@ -1,11 +1,10 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.query.test; -import static org.junit.Assert.*; - -import org.junit.Test; - +import org.junit.jupiter.api.Test; import com.yahoo.prelude.query.PhraseSegmentItem; + +import static org.junit.jupiter.api.Assertions.assertEquals; import com.yahoo.prelude.query.WordItem; /** @@ -16,7 +15,7 @@ import com.yahoo.prelude.query.WordItem; public class SegmentItemTestCase { @Test - public final void test() { + final void test() { PhraseSegmentItem item = new PhraseSegmentItem("a b c", false, true); item.addItem(new WordItem("a")); item.addItem(new WordItem("b")); diff --git a/container-search/src/test/java/com/yahoo/prelude/query/test/WandItemTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/test/WandItemTestCase.java index 6a13ea130bc..40753ee1533 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/test/WandItemTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/test/WandItemTestCase.java @@ -6,14 +6,14 @@ import com.yahoo.prelude.query.PureWeightedString; import com.yahoo.prelude.query.WandItem; import com.yahoo.prelude.query.textualrepresentation.Discloser; import com.yahoo.prelude.query.textualrepresentation.TextualQueryRepresentation; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * Unit tests for WandItem. */ @@ -22,7 +22,7 @@ public class WandItemTestCase { private static final double DELTA = 0.0000001; @Test - public void requireThatWandItemCanBeConstructed() { + void requireThatWandItemCanBeConstructed() { WandItem item = new WandItem("myfield", 10); assertEquals("myfield", item.getIndexName()); assertEquals(10, item.getTargetNumHits()); @@ -32,14 +32,14 @@ public class WandItemTestCase { } @Test - public void requireThatEncodeIsWorking() { + void requireThatEncodeIsWorking() { WandItem item = createSimpleItem(); ByteBuffer actual = ByteBuffer.allocate(128); ByteBuffer expect = ByteBuffer.allocate(128); expect.put((byte) 22).put((byte) 1); Item.putString("myfield", expect); - expect.put((byte)10); // targetNumHits + expect.put((byte) 10); // targetNumHits expect.putDouble(20); // scoreThreshold expect.putDouble(2.0); // thresholdBoostFactor new PureWeightedString("foo", 30).encode(expect); @@ -53,19 +53,24 @@ public class WandItemTestCase { } @Test - public void requireThatToStringIsWorking() { - assertEquals("WAND(10,20.0,2.0) myfield{[30]:\"foo\"}", createSimpleItem().toString()); + void requireThatToStringIsWorking() { + assertEquals("WAND(10,20.0,2.0) myfield{[30]:\"foo\"}", createSimpleItem().toString()); } @Test - public void requireThatDiscloseIsWorking() { + void requireThatDiscloseIsWorking() { class TestDiscloser implements Discloser { public final Map<String, Object> props = new HashMap<>(); + public void addProperty(String key, Object value) { props.put(key, value); } - public void setValue(Object value) {} - public void addChild(Item item) {} + + public void setValue(Object value) { + } + + public void addChild(Item item) { + } } TestDiscloser discloser = new TestDiscloser(); createSimpleItem().disclose(discloser); @@ -76,17 +81,17 @@ public class WandItemTestCase { } @Test - public void testTextualRepresentation() { + void testTextualRepresentation() { WandItem item = new WandItem("myfield", 10); item.addToken("term1", 10); item.setScoreThreshold(20); item.setThresholdBoostFactor(2.0); assertEquals("WAND[index=\"myfield\" scoreThreshold=20.0 targetNumHits=10 thresholdBoostFactor=2.0]{\n" + - " PURE_WEIGHTED_STRING[weight=10]{\n" + - " \"term1\"\n" + - " }\n" + - "}\n", - new TextualQueryRepresentation(item).toString()); + " PURE_WEIGHTED_STRING[weight=10]{\n" + + " \"term1\"\n" + + " }\n" + + "}\n", + new TextualQueryRepresentation(item).toString()); } private static WandItem createSimpleItem() { diff --git a/container-search/src/test/java/com/yahoo/prelude/query/test/WeightedSetItemTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/test/WeightedSetItemTestCase.java index 8a335c9119d..1cd657a1940 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/test/WeightedSetItemTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/test/WeightedSetItemTestCase.java @@ -6,19 +6,16 @@ import com.yahoo.prelude.query.Item; import com.yahoo.prelude.query.PureWeightedString; import com.yahoo.prelude.query.WeightedSetItem; import com.yahoo.prelude.query.WordItem; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.nio.ByteBuffer; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; public class WeightedSetItemTestCase { @Test - public void testTokenAPI() { + void testTokenAPI() { WeightedSetItem ws = new WeightedSetItem("index"); assertEquals(0, ws.getNumTokens()); assertNull(ws.getTokenWeight("bogus")); @@ -55,11 +52,11 @@ public class WeightedSetItemTestCase { } @Test - public void testNegativeWeight() { + void testNegativeWeight() { WeightedSetItem ws = new WeightedSetItem("index"); assertEquals(Integer.valueOf(-10), ws.addToken("bad", -10)); assertEquals(1, ws.getNumTokens()); - assertEquals(Integer.valueOf(-10), ws.getTokenWeight("bad")); + assertEquals(Integer.valueOf(-10), ws.getTokenWeight("bad")); } static class FakeWSItem extends CompositeIndexedItem { @@ -77,7 +74,7 @@ public class WeightedSetItemTestCase { } @Test - public void testEncoding() { + void testEncoding() { WeightedSetItem item = new WeightedSetItem("index"); // need 2 alternative reference encoding, as the encoding // order is kept undefined to improve performance. @@ -94,11 +91,11 @@ public class WeightedSetItemTestCase { ByteBuffer actual = ByteBuffer.allocate(128); ByteBuffer expect1 = ByteBuffer.allocate(128); ByteBuffer expect2 = ByteBuffer.allocate(128); - expect1.put((byte)15).put((byte)2); + expect1.put((byte) 15).put((byte) 2); Item.putString("index", expect1); new PureWeightedString("foo", 10).encode(expect1); new PureWeightedString("bar", 20).encode(expect1); - expect2.put((byte)15).put((byte)2); + expect2.put((byte) 15).put((byte) 2); Item.putString("index", expect2); new PureWeightedString("bar", 20).encode(expect2); new PureWeightedString("foo", 10).encode(expect2); @@ -110,9 +107,9 @@ public class WeightedSetItemTestCase { expect2.flip(); if (actual.equals(expect1)) { - assertFalse(actual.equals(expect2)); + assertNotEquals(actual, expect2); } else { - assertTrue(actual.equals(expect2)); + assertEquals(actual, expect2); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/query/textualrepresentation/test/TextualQueryRepresentationTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/textualrepresentation/test/TextualQueryRepresentationTestCase.java index 213f912c0a5..cf65205fe34 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/textualrepresentation/test/TextualQueryRepresentationTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/textualrepresentation/test/TextualQueryRepresentationTestCase.java @@ -11,11 +11,11 @@ import java.util.HashSet; import java.util.Map; import com.yahoo.prelude.query.Item; + +import static org.junit.jupiter.api.Assertions.assertEquals; import com.yahoo.prelude.query.textualrepresentation.Discloser; import com.yahoo.prelude.query.textualrepresentation.TextualQueryRepresentation; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; /** * Test of TextualQueryRepresentation. @@ -102,14 +102,14 @@ public class TextualQueryRepresentationTestCase { } @Test - public void testBasic() throws Exception { + void testBasic() throws Exception { String basicText = getTextualQueryRepresentation(basic); assertEquals(getCorrect("basic.txt"), basicText); } @Test - public void testComposite() throws Exception { + void testComposite() throws Exception { String compositeText = getTextualQueryRepresentation(composite); assertEquals(getCorrect("composite.txt"), compositeText); } diff --git a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/CJKSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/CJKSearcherTestCase.java index b3b96299b90..0c24da54ec4 100644 --- a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/CJKSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/CJKSearcherTestCase.java @@ -18,10 +18,10 @@ import com.yahoo.search.query.parser.ParserEnvironment; import com.yahoo.search.query.parser.ParserFactory; import com.yahoo.search.searchchain.Execution; -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.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; /** * @author Steinar Knutsen @@ -32,9 +32,9 @@ public class CJKSearcherTestCase { "querytransform/test/cjk-index-info.cfg", null); @Test - public void testTermWeight() { + void testTermWeight() { assertTransformed("efg!10", "SAND e!10 fg!10", - Query.Type.ALL, Language.CHINESE_SIMPLIFIED, Language.CHINESE_TRADITIONAL, TestLinguistics.INSTANCE); + Query.Type.ALL, Language.CHINESE_SIMPLIFIED, Language.CHINESE_TRADITIONAL, TestLinguistics.INSTANCE); } /** @@ -43,14 +43,14 @@ public class CJKSearcherTestCase { * must combine overlapping tokens as PHRASE, not AND to avoid a too high recall because of the token overlap. */ @Test - public void testCjkQueryWithOverlappingTokens() { + void testCjkQueryWithOverlappingTokens() { // The test language segmenter will segment "bcd" into the overlapping tokens "bc" "cd" assertTransformed("bcd", "SAND bc cd", Query.Type.ALL, Language.CHINESE_SIMPLIFIED, Language.CHINESE_TRADITIONAL, - TestLinguistics.INSTANCE); + TestLinguistics.INSTANCE); // While "efg" will be segmented into one of the standard options, "e" "fg" assertTransformed("efg", "SAND e fg", Query.Type.ALL, Language.CHINESE_SIMPLIFIED, Language.CHINESE_TRADITIONAL, - TestLinguistics.INSTANCE); + TestLinguistics.INSTANCE); } private void assertTransformed(String queryString, String expected, Query.Type mode, Language actualLanguage, diff --git a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/CollapsePhraseSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/CollapsePhraseSearcherTestCase.java index 498d6ca2980..3aaf941c6f5 100644 --- a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/CollapsePhraseSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/CollapsePhraseSearcherTestCase.java @@ -9,12 +9,12 @@ import com.yahoo.prelude.query.PhraseItem; import com.yahoo.prelude.query.WordItem; import com.yahoo.prelude.querytransform.CollapsePhraseSearcher; import com.yahoo.search.searchchain.Execution; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Check CollapsePhraseSearcher works and only is triggered when it @@ -25,14 +25,14 @@ import static org.junit.Assert.assertEquals; public class CollapsePhraseSearcherTestCase { @Test - public void testSimplePositive() { + void testSimplePositive() { PhraseItem root = new PhraseItem(); root.addItem(new WordItem("abc")); assertEquals("abc", transformQuery(root)); } @Test - public void testPositive1() { + void testPositive1() { AndItem root = new AndItem(); root.addItem(new WordItem("a")); PhraseItem embedded = new PhraseItem(); @@ -40,11 +40,11 @@ public class CollapsePhraseSearcherTestCase { root.addItem(embedded); root.addItem(new WordItem("e")); assertEquals("AND a bcd e", - transformQuery(root)); + transformQuery(root)); } @Test - public void testPositive2() { + void testPositive2() { AndItem root = new AndItem(); root.addItem(new WordItem("a")); CompositeItem embedded = new AndItem(); @@ -55,21 +55,21 @@ public class CollapsePhraseSearcherTestCase { root.addItem(embedded); root.addItem(new WordItem("e")); assertEquals("AND a (AND bcd def) e", - transformQuery(root)); + transformQuery(root)); } @Test - public void testNoTerms() { + void testNoTerms() { assertEquals("NULL", transformQuery("?query=" + enc("\"\""))); } @Test - public void testNegative1() { + void testNegative1() { assertEquals("WEAKAND(100) \"abc def\"", transformQuery("?query=" + enc("\"abc def\""))); } @Test - public void testNegative2() { + void testNegative2() { assertEquals("WEAKAND(100) a \"abc def\" b", transformQuery("?query=" + enc("a \"abc def\" b"))); } @@ -83,7 +83,7 @@ public class CollapsePhraseSearcherTestCase { } @Test - public void testNegative3() { + void testNegative3() { AndItem root = new AndItem(); root.addItem(new WordItem("a")); CompositeItem embedded = new AndItem(); @@ -95,7 +95,7 @@ public class CollapsePhraseSearcherTestCase { root.addItem(embedded); root.addItem(new WordItem("e")); assertEquals("AND a (AND bcd \"def ghi\") e", - transformQuery(root)); + transformQuery(root)); } private String transformQuery(String rawQuery) { diff --git a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/LiteralBoostSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/LiteralBoostSearcherTestCase.java index a434fbd9949..16e27303fa8 100644 --- a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/LiteralBoostSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/LiteralBoostSearcherTestCase.java @@ -10,11 +10,11 @@ import com.yahoo.search.Query; import com.yahoo.prelude.querytransform.LiteralBoostSearcher; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.test.QueryTestCase; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.*; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests the complete field match query transformer @@ -24,55 +24,55 @@ import static org.junit.Assert.assertEquals; public class LiteralBoostSearcherTestCase { @Test - public void testSimpleQueryWithBoost() { + void testSimpleQueryWithBoost() { assertEquals("RANK (WEAKAND(100) abc) default_literal:abc", - transformQuery("?query=abc&source=cluster1&restrict=type1")); + transformQuery("?query=abc&source=cluster1&restrict=type1")); } @Test - public void testSimpleQueryNoBoost() { + void testSimpleQueryNoBoost() { assertEquals("WEAKAND(100) abc", transformQuery("?query=abc&source=cluster1&restrict=type2")); } @Test - public void testQueryWithExplicitIndex() { + void testQueryWithExplicitIndex() { assertEquals("RANK (WEAKAND(100) absolute:abc) absolute_literal:abc", transformQuery("?query=absolute:abc&source=cluster1&restrict=type1")); } @Test - public void testQueryWithExplicitIndexNoBoost() { + void testQueryWithExplicitIndexNoBoost() { assertEquals("WEAKAND(100) absolute:abc", transformQuery("?query=absolute:abc&source=cluster1&restrict=type2")); } @Test - public void testQueryWithNegativeBranch() { - assertEquals("RANK (+(AND abc def) -ghi) "+ - "default_literal:abc default_literal:def", - transformQuery("?query=abc and def andnot ghi&type=adv&source=cluster1&restrict=type1")); + void testQueryWithNegativeBranch() { + assertEquals("RANK (+(AND abc def) -ghi) " + + "default_literal:abc default_literal:def", + transformQuery("?query=abc and def andnot ghi&type=adv&source=cluster1&restrict=type1")); } @Test - public void testJumbledQuery() { + void testJumbledQuery() { assertEquals - ("RANK (OR (+(OR abc def) -ghi) jkl) " + - "default_literal:abc default_literal:def default_literal:jkl", - transformQuery("?query=abc or def andnot ghi or jkl&type=adv&source=cluster1&restrict=type1")); + ("RANK (OR (+(OR abc def) -ghi) jkl) " + + "default_literal:abc default_literal:def default_literal:jkl", + transformQuery("?query=abc or def andnot ghi or jkl&type=adv&source=cluster1&restrict=type1")); } @Test - public void testTermindexQuery() { - assertEquals("RANK (+(WEAKAND(100) a b d) -c) default_literal:a "+ - "default_literal:b default_literal:d", - transformQuery("?query=a b -c d&source=cluster1&restrict=type1")); + void testTermindexQuery() { + assertEquals("RANK (+(WEAKAND(100) a b d) -c) default_literal:a " + + "default_literal:b default_literal:d", + transformQuery("?query=a b -c d&source=cluster1&restrict=type1")); } @Test - public void testQueryWithoutBoost() { + void testQueryWithoutBoost() { assertEquals("RANK (AND nonexistant a nonexistant b) default_literal:nonexistant default_literal:a default_literal:nonexistant default_literal:b", - transformQuery("?query=nonexistant:a nonexistant:b&source=cluster1&restrict=type1&type=all")); + transformQuery("?query=nonexistant:a nonexistant:b&source=cluster1&restrict=type1&type=all")); } private String transformQuery(String rawQuery) { diff --git a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/NoRankingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/NoRankingSearcherTestCase.java index 107a82f3186..16d6bd40178 100644 --- a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/NoRankingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/NoRankingSearcherTestCase.java @@ -5,41 +5,41 @@ import com.yahoo.search.Query; import com.yahoo.prelude.querytransform.NoRankingSearcher; import com.yahoo.search.Searcher; import com.yahoo.search.searchchain.Execution; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class NoRankingSearcherTestCase { Searcher s = new NoRankingSearcher(); @Test - public void testDoSearch() { + void testDoSearch() { Query q = new Query("?query=a&sorting=%2ba%20-b&ranking=hello"); assertEquals("hello", q.getRanking().getProfile()); new Execution(s, Execution.Context.createContextStub()).search(q); assertEquals("unranked", q.getRanking().getProfile()); - } + } @Test - public void testSortOnRelevanceAscending() { + void testSortOnRelevanceAscending() { Query q = new Query("?query=a&sorting=%2ba%20-b%20-[rank]&ranking=hello"); new Execution(s, Execution.Context.createContextStub()).search(q); assertEquals("hello", q.getRanking().getProfile()); - } + } @Test - public void testSortOnRelevanceDescending() { + void testSortOnRelevanceDescending() { Query q = new Query("?query=a&sorting=%2ba%20-b%20-[rank]&ranking=hello"); new Execution(s, Execution.Context.createContextStub()).search(q); assertEquals("hello", q.getRanking().getProfile()); - } + } @Test - public void testNoSorting() { + void testNoSorting() { Query q = new Query("?query=a"); new Execution(s, Execution.Context.createContextStub()).search(q); assertEquals("default", q.getRanking().getProfile()); - } + } } diff --git a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/NonPhrasingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/NonPhrasingSearcherTestCase.java index 462e57a2b37..5a090a51415 100644 --- a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/NonPhrasingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/NonPhrasingSearcherTestCase.java @@ -7,9 +7,9 @@ import com.yahoo.prelude.query.WordItem; import com.yahoo.prelude.querytransform.NonPhrasingSearcher; import com.yahoo.search.Searcher; import com.yahoo.search.searchchain.Execution; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests non-phrasing @@ -21,58 +21,58 @@ public class NonPhrasingSearcherTestCase { private Searcher searcher; @Test - public void testSingleWordNonPhrasing() { - searcher= - new NonPhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); + void testSingleWordNonPhrasing() { + searcher = + new NonPhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); - Query query=new Query("?query=void+aword+kanoo"); + Query query = new Query("?query=void+aword+kanoo"); new Execution(searcher, Execution.Context.createContextStub()).search(query); assertEquals("WEAKAND(100) void kanoo", query.getModel().getQueryTree().getRoot().toString()); } @Test - public void testMultipleWordNonPhrasing() { - searcher= - new NonPhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); + void testMultipleWordNonPhrasing() { + searcher = + new NonPhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); - Query query=new Query("?query=void+tudor+vidor+kanoo"); + Query query = new Query("?query=void+tudor+vidor+kanoo"); new Execution(searcher, Execution.Context.createContextStub()).search(query); - CompositeItem item=(CompositeItem) query.getModel().getQueryTree().getRoot(); - assertEquals(2,item.getItemCount()); - assertEquals("void",((WordItem)item.getItem(0)).getWord()); - assertEquals("kanoo",((WordItem)item.getItem(1)).getWord()); + CompositeItem item = (CompositeItem) query.getModel().getQueryTree().getRoot(); + assertEquals(2, item.getItemCount()); + assertEquals("void", ((WordItem) item.getItem(0)).getWord()); + assertEquals("kanoo", ((WordItem) item.getItem(1)).getWord()); } @Test - public void testNoNonPhrasingIfNoOtherPhrases() { - searcher= - new NonPhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); + void testNoNonPhrasingIfNoOtherPhrases() { + searcher = + new NonPhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); - Query query=new Query("?query=tudor+vidor"); + Query query = new Query("?query=tudor+vidor"); new Execution(searcher, Execution.Context.createContextStub()).search(query); - CompositeItem item=(CompositeItem) query.getModel().getQueryTree().getRoot(); - assertEquals(2,item.getItemCount()); - assertEquals("tudor",((WordItem)item.getItem(0)).getWord()); - assertEquals("vidor",((WordItem)item.getItem(1)).getWord()); + CompositeItem item = (CompositeItem) query.getModel().getQueryTree().getRoot(); + assertEquals(2, item.getItemCount()); + assertEquals("tudor", ((WordItem) item.getItem(0)).getWord()); + assertEquals("vidor", ((WordItem) item.getItem(1)).getWord()); } @Test - public void testNoNonPhrasingIfSuggestOnly() { - searcher= - new NonPhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); + void testNoNonPhrasingIfSuggestOnly() { + searcher = + new NonPhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); - Query query=new Query("?query=void+tudor+vidor+kanoo&suggestonly=true"); + Query query = new Query("?query=void+tudor+vidor+kanoo&suggestonly=true"); new Execution(searcher, Execution.Context.createContextStub()).search(query); - CompositeItem item=(CompositeItem) query.getModel().getQueryTree().getRoot(); - assertEquals(4,item.getItemCount()); - assertEquals("void",((WordItem)item.getItem(0)).getWord()); - assertEquals("tudor",((WordItem)item.getItem(1)).getWord()); - assertEquals("vidor",((WordItem)item.getItem(2)).getWord()); - assertEquals("kanoo",((WordItem)item.getItem(3)).getWord()); + CompositeItem item = (CompositeItem) query.getModel().getQueryTree().getRoot(); + assertEquals(4, item.getItemCount()); + assertEquals("void", ((WordItem) item.getItem(0)).getWord()); + assertEquals("tudor", ((WordItem) item.getItem(1)).getWord()); + assertEquals("vidor", ((WordItem) item.getItem(2)).getWord()); + assertEquals("kanoo", ((WordItem) item.getItem(3)).getWord()); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/NormalizingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/NormalizingSearcherTestCase.java index 7ab50118c6d..239f4500297 100644 --- a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/NormalizingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/NormalizingSearcherTestCase.java @@ -1,8 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.querytransform.test; -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; import com.google.common.collect.ImmutableList; import com.yahoo.language.Linguistics; @@ -19,7 +19,7 @@ import com.yahoo.prelude.IndexModel; import com.yahoo.prelude.querytransform.NormalizingSearcher; import com.yahoo.search.searchchain.Execution; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -38,35 +38,35 @@ public class NormalizingSearcherTestCase { private static final Linguistics linguistics = new SimpleLinguistics(); @Test - public void testNoNormalizingNecssary() { + void testNoNormalizingNecssary() { Query query = new Query("/search?query=bilen&search=cluster1&restrict=type1"); createExecution().search(query); assertEquals("WEAKAND(100) bilen", query.getModel().getQueryTree().getRoot().toString()); } @Test - public void testAttributeQuery() { + void testAttributeQuery() { Query query = new Query("/search?query=attribute:" + enc("b\u00e9yonc\u00e8 b\u00e9yonc\u00e8") + "&search=cluster1&restrict=type1"); createExecution().search(query); assertEquals("WEAKAND(100) attribute:b\u00e9yonc\u00e8 beyonce", query.getModel().getQueryTree().getRoot().toString()); } @Test - public void testOneTermNormalizing() { + void testOneTermNormalizing() { Query query = new Query("/search?query=b\u00e9yonc\u00e8&search=cluster1&restrict=type1"); createExecution().search(query); assertEquals("WEAKAND(100) beyonce", query.getModel().getQueryTree().getRoot().toString()); } @Test - public void testOneTermNoNormalizingDifferentSearchDef() { + void testOneTermNoNormalizingDifferentSearchDef() { Query query = new Query("/search?query=b\u00e9yonc\u00e8&search=cluster1&restrict=type2"); createExecution().search(query); assertEquals("WEAKAND(100) béyoncè", query.getModel().getQueryTree().getRoot().toString()); } @Test - public void testTwoTermQuery() throws UnsupportedEncodingException { + void testTwoTermQuery() throws UnsupportedEncodingException { Query query = new Query("/search?query=" + enc("b\u00e9yonc\u00e8 beyonc\u00e9") + "&search=cluster1&restrict=type1"); createExecution().search(query); assertEquals("WEAKAND(100) beyonce beyonce", query.getModel().getQueryTree().getRoot().toString()); @@ -82,7 +82,7 @@ public class NormalizingSearcherTestCase { } @Test - public void testPhraseQuery() { + void testPhraseQuery() { Query query = new Query("/search?query=" + enc("\"b\u00e9yonc\u00e8 beyonc\u00e9\"") + "&search=cluster1&restrict=type1"); query.getTrace().setLevel(2); createExecution().search(query); @@ -90,7 +90,7 @@ public class NormalizingSearcherTestCase { } @Test - public void testLiteralBoost() { + void testLiteralBoost() { Query query = new Query("/search?query=nop&search=cluster1&restrict=type1"); List<WordAlternativesItem.Alternative> terms = new ArrayList<>(); Substring origin = new Substring(0, 5, "h\u00F4tels"); @@ -107,12 +107,12 @@ public class NormalizingSearcherTestCase { assertEquals(.7d * .7d, a.exactness, 1e-15); } } - assertTrue("Did not find the expected normalized form \"hotel\".", foundHotel); + assertTrue(foundHotel, "Did not find the expected normalized form \"hotel\"."); } @Test - public void testPhraseSegmentNormalization() { + void testPhraseSegmentNormalization() { Query query = new Query("/search?query=&search=cluster1&restrict=type1"); PhraseSegmentItem phraseSegment = new PhraseSegmentItem("default", false, false); phraseSegment.addItem(new WordItem("net")); diff --git a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/PhraseMatcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/PhraseMatcherTestCase.java index 623c480796c..da7b29272a2 100644 --- a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/PhraseMatcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/PhraseMatcherTestCase.java @@ -5,14 +5,11 @@ import com.yahoo.prelude.query.AndItem; import com.yahoo.prelude.query.IntItem; import com.yahoo.prelude.query.WordItem; import com.yahoo.prelude.querytransform.PhraseMatcher; -import org.junit.Test; +import org.junit.jupiter.api.Test; 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.assertNull; +import static org.junit.jupiter.api.Assertions.*; /** * @author bratseth @@ -20,118 +17,118 @@ import static org.junit.Assert.assertNull; public class PhraseMatcherTestCase { @Test - public void testSingleItemMatching() { - PhraseMatcher matcher=new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); + void testSingleItemMatching() { + PhraseMatcher matcher = new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); matcher.setMatchSingleItems(true); - List<?> matches=matcher.matchPhrases(new WordItem("aword")); + List<?> matches = matcher.matchPhrases(new WordItem("aword")); assertNotNull(matches); - assertEquals(1,matches.size()); - PhraseMatcher.Phrase match=(PhraseMatcher.Phrase)matches.get(0); - assertEquals(1,match.getLength()); - assertEquals("",match.getData()); - assertEquals(null,match.getOwner()); - assertEquals(0,match.getStartIndex()); - PhraseMatcher.Phrase.MatchIterator i=match.itemIterator(); - assertEquals(new WordItem("aword"),i.next()); + assertEquals(1, matches.size()); + PhraseMatcher.Phrase match = (PhraseMatcher.Phrase) matches.get(0); + assertEquals(1, match.getLength()); + assertEquals("", match.getData()); + assertNull(match.getOwner()); + assertEquals(0, match.getStartIndex()); + PhraseMatcher.Phrase.MatchIterator i = match.itemIterator(); + assertEquals(new WordItem("aword"), i.next()); assertNull(i.getReplace()); assertFalse(i.hasNext()); } @Test - public void testSingleItemMatchingCaseInsensitive() { - PhraseMatcher matcher=new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); + void testSingleItemMatchingCaseInsensitive() { + PhraseMatcher matcher = new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); matcher.setMatchSingleItems(true); final String mixedCase = "aWoRD"; - List<?> matches=matcher.matchPhrases(new WordItem(mixedCase)); + List<?> matches = matcher.matchPhrases(new WordItem(mixedCase)); assertNotNull(matches); - assertEquals(1,matches.size()); - PhraseMatcher.Phrase match=(PhraseMatcher.Phrase)matches.get(0); - assertEquals(1,match.getLength()); - assertEquals("",match.getData()); - assertEquals(null,match.getOwner()); - assertEquals(0,match.getStartIndex()); - PhraseMatcher.Phrase.MatchIterator i=match.itemIterator(); - assertEquals(new WordItem(mixedCase),i.next()); + assertEquals(1, matches.size()); + PhraseMatcher.Phrase match = (PhraseMatcher.Phrase) matches.get(0); + assertEquals(1, match.getLength()); + assertEquals("", match.getData()); + assertNull(match.getOwner()); + assertEquals(0, match.getStartIndex()); + PhraseMatcher.Phrase.MatchIterator i = match.itemIterator(); + assertEquals(new WordItem(mixedCase), i.next()); assertNull(i.getReplace()); assertFalse(i.hasNext()); } @Test - public void testSingleItemMatchingWithPluralIgnore() { - PhraseMatcher matcher=new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa",true); + void testSingleItemMatchingWithPluralIgnore() { + PhraseMatcher matcher = new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa", true); matcher.setMatchSingleItems(true); - List<?> matches=matcher.matchPhrases(new WordItem("awords")); + List<?> matches = matcher.matchPhrases(new WordItem("awords")); assertNotNull(matches); - assertEquals(1,matches.size()); - PhraseMatcher.Phrase match=(PhraseMatcher.Phrase)matches.get(0); - assertEquals(1,match.getLength()); - assertEquals("",match.getData()); - assertEquals(null,match.getOwner()); - assertEquals(0,match.getStartIndex()); - PhraseMatcher.Phrase.MatchIterator i=match.itemIterator(); - assertEquals(new WordItem("awords"),i.next()); - assertEquals("aword",i.getReplace()); + assertEquals(1, matches.size()); + PhraseMatcher.Phrase match = (PhraseMatcher.Phrase) matches.get(0); + assertEquals(1, match.getLength()); + assertEquals("", match.getData()); + assertNull(match.getOwner()); + assertEquals(0, match.getStartIndex()); + PhraseMatcher.Phrase.MatchIterator i = match.itemIterator(); + assertEquals(new WordItem("awords"), i.next()); + assertEquals("aword", i.getReplace()); assertFalse(i.hasNext()); } @Test - public void testSingleItemMatchingCaseInsensitiveWithPluralIgnore() { - PhraseMatcher matcher=new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa",true); + void testSingleItemMatchingCaseInsensitiveWithPluralIgnore() { + PhraseMatcher matcher = new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa", true); matcher.setMatchSingleItems(true); final String mixedCase = "aWoRDS"; - List<?> matches=matcher.matchPhrases(new WordItem(mixedCase)); + List<?> matches = matcher.matchPhrases(new WordItem(mixedCase)); assertNotNull(matches); - assertEquals(1,matches.size()); - PhraseMatcher.Phrase match=(PhraseMatcher.Phrase)matches.get(0); - assertEquals(1,match.getLength()); - assertEquals("",match.getData()); - assertEquals(null,match.getOwner()); - assertEquals(0,match.getStartIndex()); - PhraseMatcher.Phrase.MatchIterator i=match.itemIterator(); - assertEquals(new WordItem(mixedCase),i.next()); - assertEquals("aword",i.getReplace()); + assertEquals(1, matches.size()); + PhraseMatcher.Phrase match = (PhraseMatcher.Phrase) matches.get(0); + assertEquals(1, match.getLength()); + assertEquals("", match.getData()); + assertNull(match.getOwner()); + assertEquals(0, match.getStartIndex()); + PhraseMatcher.Phrase.MatchIterator i = match.itemIterator(); + assertEquals(new WordItem(mixedCase), i.next()); + assertEquals("aword", i.getReplace()); assertFalse(i.hasNext()); } @Test - public void testPhraseMatching() { - PhraseMatcher matcher=new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa",true); - AndItem and=new AndItem(); + void testPhraseMatching() { + PhraseMatcher matcher = new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa", true); + AndItem and = new AndItem(); and.addItem(new WordItem("noisebefore")); and.addItem(new WordItem("this")); and.addItem(new WordItem("is")); and.addItem(new WordItem("a")); and.addItem(new WordItem("test")); and.addItem(new WordItem("noiseafter")); - List<?> matches=matcher.matchPhrases(and); + List<?> matches = matcher.matchPhrases(and); assertNotNull(matches); - assertEquals(1,matches.size()); - PhraseMatcher.Phrase match=(PhraseMatcher.Phrase)matches.get(0); - assertEquals(4,match.getLength()); - assertEquals("",match.getData()); - assertEquals(and,match.getOwner()); - assertEquals(1,match.getStartIndex()); - PhraseMatcher.Phrase.MatchIterator i=match.itemIterator(); - assertEquals(new WordItem("this"),i.next()); - assertEquals(null,i.getReplace()); - assertEquals(new WordItem("is"),i.next()); - assertEquals(null,i.getReplace()); - assertEquals(new WordItem("a"),i.next()); - assertEquals(null,i.getReplace()); - assertEquals(new WordItem("test"),i.next()); - assertEquals(null,i.getReplace()); + assertEquals(1, matches.size()); + PhraseMatcher.Phrase match = (PhraseMatcher.Phrase) matches.get(0); + assertEquals(4, match.getLength()); + assertEquals("", match.getData()); + assertEquals(and, match.getOwner()); + assertEquals(1, match.getStartIndex()); + PhraseMatcher.Phrase.MatchIterator i = match.itemIterator(); + assertEquals(new WordItem("this"), i.next()); + assertNull(i.getReplace()); + assertEquals(new WordItem("is"), i.next()); + assertNull(i.getReplace()); + assertEquals(new WordItem("a"), i.next()); + assertNull(i.getReplace()); + assertEquals(new WordItem("test"), i.next()); + assertNull(i.getReplace()); assertFalse(i.hasNext()); } @Test - public void testPhraseMatchingCaseInsensitive() { - PhraseMatcher matcher=new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa",true); - AndItem and=new AndItem(); + void testPhraseMatchingCaseInsensitive() { + PhraseMatcher matcher = new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa", true); + AndItem and = new AndItem(); and.addItem(new WordItem("noisebefore")); final String firstWord = "thIs"; and.addItem(new WordItem(firstWord)); @@ -142,93 +139,93 @@ public class PhraseMatcherTestCase { final String fourthWord = "tEst"; and.addItem(new WordItem(fourthWord)); and.addItem(new WordItem("noiseafter")); - List<?> matches=matcher.matchPhrases(and); + List<?> matches = matcher.matchPhrases(and); assertNotNull(matches); - assertEquals(1,matches.size()); - PhraseMatcher.Phrase match=(PhraseMatcher.Phrase)matches.get(0); - assertEquals(4,match.getLength()); - assertEquals("",match.getData()); - assertEquals(and,match.getOwner()); - assertEquals(1,match.getStartIndex()); - PhraseMatcher.Phrase.MatchIterator i=match.itemIterator(); - assertEquals(new WordItem(firstWord),i.next()); - assertEquals(null,i.getReplace()); - assertEquals(new WordItem(secondWord),i.next()); - assertEquals(null,i.getReplace()); - assertEquals(new WordItem(thirdWord),i.next()); - assertEquals(null,i.getReplace()); - assertEquals(new WordItem(fourthWord),i.next()); - assertEquals(null,i.getReplace()); + assertEquals(1, matches.size()); + PhraseMatcher.Phrase match = (PhraseMatcher.Phrase) matches.get(0); + assertEquals(4, match.getLength()); + assertEquals("", match.getData()); + assertEquals(and, match.getOwner()); + assertEquals(1, match.getStartIndex()); + PhraseMatcher.Phrase.MatchIterator i = match.itemIterator(); + assertEquals(new WordItem(firstWord), i.next()); + assertNull(i.getReplace()); + assertEquals(new WordItem(secondWord), i.next()); + assertNull(i.getReplace()); + assertEquals(new WordItem(thirdWord), i.next()); + assertNull(i.getReplace()); + assertEquals(new WordItem(fourthWord), i.next()); + assertNull(i.getReplace()); assertFalse(i.hasNext()); } @Test - public void testPhraseMatchingWithNumber() { - PhraseMatcher matcher=new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa",true); - AndItem and=new AndItem(); + void testPhraseMatchingWithNumber() { + PhraseMatcher matcher = new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa", true); + AndItem and = new AndItem(); and.addItem(new WordItem("noisebefore")); and.addItem(new WordItem("this")); and.addItem(new WordItem("is")); and.addItem(new IntItem("3")); and.addItem(new WordItem("tests")); and.addItem(new WordItem("noiseafter")); - List<?> matches=matcher.matchPhrases(and); + List<?> matches = matcher.matchPhrases(and); assertNotNull(matches); - assertEquals(1,matches.size()); - PhraseMatcher.Phrase match=(PhraseMatcher.Phrase)matches.get(0); - assertEquals(4,match.getLength()); - assertEquals("",match.getData()); - assertEquals(and,match.getOwner()); - assertEquals(1,match.getStartIndex()); - PhraseMatcher.Phrase.MatchIterator i=match.itemIterator(); - assertEquals(new WordItem("this"),i.next()); - assertEquals(null,i.getReplace()); - assertEquals(new WordItem("is"),i.next()); - assertEquals(null,i.getReplace()); - assertEquals(new IntItem("3"),i.next()); - assertEquals(null,i.getReplace()); - assertEquals(new WordItem("tests"),i.next()); - assertEquals(null,i.getReplace()); + assertEquals(1, matches.size()); + PhraseMatcher.Phrase match = (PhraseMatcher.Phrase) matches.get(0); + assertEquals(4, match.getLength()); + assertEquals("", match.getData()); + assertEquals(and, match.getOwner()); + assertEquals(1, match.getStartIndex()); + PhraseMatcher.Phrase.MatchIterator i = match.itemIterator(); + assertEquals(new WordItem("this"), i.next()); + assertNull(i.getReplace()); + assertEquals(new WordItem("is"), i.next()); + assertNull(i.getReplace()); + assertEquals(new IntItem("3"), i.next()); + assertNull(i.getReplace()); + assertEquals(new WordItem("tests"), i.next()); + assertNull(i.getReplace()); assertFalse(i.hasNext()); } @Test - public void testPhraseMatchingWithPluralIgnore() { - PhraseMatcher matcher=new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa",true); - AndItem and=new AndItem(); + void testPhraseMatchingWithPluralIgnore() { + PhraseMatcher matcher = new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa", true); + AndItem and = new AndItem(); and.addItem(new WordItem("noisebefore")); and.addItem(new WordItem("thi")); and.addItem(new WordItem("is")); and.addItem(new WordItem("a")); and.addItem(new WordItem("tests")); and.addItem(new WordItem("noiseafter")); - List<?> matches=matcher.matchPhrases(and); + List<?> matches = matcher.matchPhrases(and); assertNotNull(matches); - assertEquals(1,matches.size()); - PhraseMatcher.Phrase match=(PhraseMatcher.Phrase)matches.get(0); - assertEquals(4,match.getLength()); - assertEquals("",match.getData()); - assertEquals(and,match.getOwner()); - assertEquals(1,match.getStartIndex()); - PhraseMatcher.Phrase.MatchIterator i=match.itemIterator(); - assertEquals(new WordItem("thi"),i.next()); - assertEquals("this",i.getReplace()); - assertEquals(new WordItem("is"),i.next()); - assertEquals(null,i.getReplace()); - assertEquals(new WordItem("a"),i.next()); - assertEquals(null,i.getReplace()); - assertEquals(new WordItem("tests"),i.next()); - assertEquals("test",i.getReplace()); + assertEquals(1, matches.size()); + PhraseMatcher.Phrase match = (PhraseMatcher.Phrase) matches.get(0); + assertEquals(4, match.getLength()); + assertEquals("", match.getData()); + assertEquals(and, match.getOwner()); + assertEquals(1, match.getStartIndex()); + PhraseMatcher.Phrase.MatchIterator i = match.itemIterator(); + assertEquals(new WordItem("thi"), i.next()); + assertEquals("this", i.getReplace()); + assertEquals(new WordItem("is"), i.next()); + assertNull(i.getReplace()); + assertEquals(new WordItem("a"), i.next()); + assertNull(i.getReplace()); + assertEquals(new WordItem("tests"), i.next()); + assertEquals("test", i.getReplace()); assertFalse(i.hasNext()); } @Test - public void testPhraseMatchingCaseInsensitiveWithPluralIgnore() { - PhraseMatcher matcher=new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa",true); - AndItem and=new AndItem(); + void testPhraseMatchingCaseInsensitiveWithPluralIgnore() { + PhraseMatcher matcher = new PhraseMatcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa", true); + AndItem and = new AndItem(); and.addItem(new WordItem("noisebefore")); final String firstWord = "thI"; and.addItem(new WordItem(firstWord)); @@ -239,24 +236,24 @@ public class PhraseMatcherTestCase { final String fourthWord = "tEsts"; and.addItem(new WordItem(fourthWord)); and.addItem(new WordItem("noiseafter")); - List<?> matches=matcher.matchPhrases(and); + List<?> matches = matcher.matchPhrases(and); assertNotNull(matches); - assertEquals(1,matches.size()); - PhraseMatcher.Phrase match=(PhraseMatcher.Phrase)matches.get(0); - assertEquals(4,match.getLength()); - assertEquals("",match.getData()); - assertEquals(and,match.getOwner()); - assertEquals(1,match.getStartIndex()); - PhraseMatcher.Phrase.MatchIterator i=match.itemIterator(); - assertEquals(new WordItem(firstWord),i.next()); - assertEquals("this",i.getReplace()); - assertEquals(new WordItem(secondWord),i.next()); - assertEquals(null,i.getReplace()); - assertEquals(new WordItem(thirdWord),i.next()); - assertEquals(null,i.getReplace()); - assertEquals(new WordItem(fourthWord),i.next()); - assertEquals("test",i.getReplace()); + assertEquals(1, matches.size()); + PhraseMatcher.Phrase match = (PhraseMatcher.Phrase) matches.get(0); + assertEquals(4, match.getLength()); + assertEquals("", match.getData()); + assertEquals(and, match.getOwner()); + assertEquals(1, match.getStartIndex()); + PhraseMatcher.Phrase.MatchIterator i = match.itemIterator(); + assertEquals(new WordItem(firstWord), i.next()); + assertEquals("this", i.getReplace()); + assertEquals(new WordItem(secondWord), i.next()); + assertNull(i.getReplace()); + assertEquals(new WordItem(thirdWord), i.next()); + assertNull(i.getReplace()); + assertEquals(new WordItem(fourthWord), i.next()); + assertEquals("test", i.getReplace()); assertFalse(i.hasNext()); } diff --git a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/PhrasingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/PhrasingSearcherTestCase.java index 8f2ae910d1b..9eca9a5fed8 100644 --- a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/PhrasingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/PhrasingSearcherTestCase.java @@ -11,10 +11,10 @@ import com.yahoo.prelude.query.WordItem; import com.yahoo.prelude.querytransform.PhrasingSearcher; import com.yahoo.search.Searcher; import com.yahoo.search.searchchain.Execution; -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.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests phrasing stuff @@ -25,104 +25,104 @@ import static org.junit.Assert.assertTrue; public class PhrasingSearcherTestCase { @Test - public void testTotalPhrasing() { - Searcher searcher= - new PhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); - - Query query=new Query(); - AndItem andItem=new AndItem(); - andItem.addItem(new WordItem("tudor","someindex")); - andItem.addItem(new WordItem("vidor","someindex")); + void testTotalPhrasing() { + Searcher searcher = + new PhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); + + Query query = new Query(); + AndItem andItem = new AndItem(); + andItem.addItem(new WordItem("tudor", "someindex")); + andItem.addItem(new WordItem("vidor", "someindex")); query.getModel().getQueryTree().setRoot(andItem); new Execution(searcher, Execution.Context.createContextStub()).search(query); - Item item=((CompositeItem) query.getModel().getQueryTree().getRoot()).getItem(0); + Item item = ((CompositeItem) query.getModel().getQueryTree().getRoot()).getItem(0); assertTrue(item instanceof PhraseItem); - PhraseItem phrase=(PhraseItem)item; - assertEquals(2,phrase.getItemCount()); - assertEquals("tudor",phrase.getWordItem(0).getWord()); - assertEquals("vidor",phrase.getWordItem(1).getWord()); - assertEquals("someindex",phrase.getIndexName()); + PhraseItem phrase = (PhraseItem) item; + assertEquals(2, phrase.getItemCount()); + assertEquals("tudor", phrase.getWordItem(0).getWord()); + assertEquals("vidor", phrase.getWordItem(1).getWord()); + assertEquals("someindex", phrase.getIndexName()); } @Test - public void testPartialPhrasing() { - Searcher searcher= - new PhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); + void testPartialPhrasing() { + Searcher searcher = + new PhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); - Query query=new Query("?query=void%20tudor%20vidor%20kanoo"); + Query query = new Query("?query=void%20tudor%20vidor%20kanoo"); new Execution(searcher, Execution.Context.createContextStub()).search(query); - CompositeItem item=(CompositeItem) query.getModel().getQueryTree().getRoot(); - assertEquals("void",((WordItem)item.getItem(0)).getWord()); - assertEquals("kanoo",((WordItem)item.getItem(2)).getWord()); - - PhraseItem phrase=(PhraseItem)item.getItem(1); - assertEquals(2,phrase.getItemCount()); - assertEquals("tudor",phrase.getWordItem(0).getWord()); - assertEquals("vidor",phrase.getWordItem(1).getWord()); + CompositeItem item = (CompositeItem) query.getModel().getQueryTree().getRoot(); + assertEquals("void", ((WordItem) item.getItem(0)).getWord()); + assertEquals("kanoo", ((WordItem) item.getItem(2)).getWord()); + + PhraseItem phrase = (PhraseItem) item.getItem(1); + assertEquals(2, phrase.getItemCount()); + assertEquals("tudor", phrase.getWordItem(0).getWord()); + assertEquals("vidor", phrase.getWordItem(1).getWord()); } @Test - public void testPartialPhrasingSuggestOnly() { - Searcher searcher= - new PhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); + void testPartialPhrasingSuggestOnly() { + Searcher searcher = + new PhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); - Query query=new Query("?query=void%20tudor%20vidor%20kanoo&suggestonly=true"); + Query query = new Query("?query=void%20tudor%20vidor%20kanoo&suggestonly=true"); new Execution(searcher, Execution.Context.createContextStub()).search(query); - CompositeItem item=(CompositeItem) query.getModel().getQueryTree().getRoot(); - assertEquals("void", ((WordItem)item.getItem(0)).getWord()); - assertEquals("tudor",((WordItem)item.getItem(1)).getWord()); - assertEquals("vidor",((WordItem)item.getItem(2)).getWord()); - assertEquals("kanoo",((WordItem)item.getItem(3)).getWord()); + CompositeItem item = (CompositeItem) query.getModel().getQueryTree().getRoot(); + assertEquals("void", ((WordItem) item.getItem(0)).getWord()); + assertEquals("tudor", ((WordItem) item.getItem(1)).getWord()); + assertEquals("vidor", ((WordItem) item.getItem(2)).getWord()); + assertEquals("kanoo", ((WordItem) item.getItem(3)).getWord()); } @Test - public void testNoPhrasingIfDifferentIndices() { - Searcher searcher= - new PhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); - - Query query=new Query(); - AndItem andItem=new AndItem(); - andItem.addItem(new WordItem("tudor","someindex")); - andItem.addItem(new WordItem("vidor","anotherindex")); + void testNoPhrasingIfDifferentIndices() { + Searcher searcher = + new PhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); + + Query query = new Query(); + AndItem andItem = new AndItem(); + andItem.addItem(new WordItem("tudor", "someindex")); + andItem.addItem(new WordItem("vidor", "anotherindex")); query.getModel().getQueryTree().setRoot(andItem); new Execution(searcher, Execution.Context.createContextStub()).search(query); - CompositeItem item=(CompositeItem) query.getModel().getQueryTree().getRoot(); + CompositeItem item = (CompositeItem) query.getModel().getQueryTree().getRoot(); assertTrue(item.getItem(0) instanceof WordItem); - WordItem word=(WordItem)item.getItem(0); - assertEquals("tudor",word.getWord()); + WordItem word = (WordItem) item.getItem(0); + assertEquals("tudor", word.getWord()); assertTrue(item.getItem(1) instanceof WordItem); - word=(WordItem)item.getItem(1); - assertEquals("vidor",word.getWord()); + word = (WordItem) item.getItem(1); + assertEquals("vidor", word.getWord()); } @Test - public void testMultiplePhrases() { - Searcher searcher= - new PhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); - - Query query=new Query(); - AndItem andItem=new AndItem(); - andItem.addItem(new WordItem("tudor","someindex")); - andItem.addItem(new WordItem("tudor","someindex")); - andItem.addItem(new WordItem("vidor","someindex")); - andItem.addItem(new WordItem("vidor","someindex")); - - OrItem orItem=new OrItem(); + void testMultiplePhrases() { + Searcher searcher = + new PhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); + + Query query = new Query(); + AndItem andItem = new AndItem(); + andItem.addItem(new WordItem("tudor", "someindex")); + andItem.addItem(new WordItem("tudor", "someindex")); + andItem.addItem(new WordItem("vidor", "someindex")); + andItem.addItem(new WordItem("vidor", "someindex")); + + OrItem orItem = new OrItem(); andItem.addItem(orItem); orItem.addItem(new WordItem("tudor")); - AndItem andItem2=new AndItem(); - andItem2.addItem(new WordItem("this","anotherindex")); - andItem2.addItem(new WordItem("is","anotherindex")); - andItem2.addItem(new WordItem("a","anotherindex")); - andItem2.addItem(new WordItem("test","anotherindex")); - andItem2.addItem(new WordItem("tudor","anotherindex")); - andItem2.addItem(new WordItem("vidor","anotherindex")); + AndItem andItem2 = new AndItem(); + andItem2.addItem(new WordItem("this", "anotherindex")); + andItem2.addItem(new WordItem("is", "anotherindex")); + andItem2.addItem(new WordItem("a", "anotherindex")); + andItem2.addItem(new WordItem("test", "anotherindex")); + andItem2.addItem(new WordItem("tudor", "anotherindex")); + andItem2.addItem(new WordItem("vidor", "anotherindex")); orItem.addItem(andItem2); orItem.addItem(new WordItem("vidor")); @@ -134,12 +134,12 @@ public class PhrasingSearcherTestCase { } @Test - public void testNoDetection() { - Searcher searcher= - new PhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); + void testNoDetection() { + Searcher searcher = + new PhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa"); - Query query=new Query(); - AndItem andItem=new AndItem(); + Query query = new Query(); + AndItem andItem = new AndItem(); andItem.addItem(new WordItem("no")); andItem.addItem(new WordItem("such")); andItem.addItem(new WordItem("phrase")); @@ -152,11 +152,11 @@ public class PhrasingSearcherTestCase { } @Test - public void testNoFileNoChange() { + void testNoFileNoChange() { Searcher searcher = new PhrasingSearcher(""); - Query query=new Query(); - AndItem andItem=new AndItem(); + Query query = new Query(); + AndItem andItem = new AndItem(); andItem.addItem(new WordItem("no", "anindex")); andItem.addItem(new WordItem("such", "anindex")); andItem.addItem(new WordItem("phrase", "indexo")); diff --git a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/QueryRewriteTestCase.java b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/QueryRewriteTestCase.java index b8c5244fb98..16bfd5f315e 100644 --- a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/QueryRewriteTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/QueryRewriteTestCase.java @@ -13,11 +13,9 @@ import com.yahoo.search.Query; import com.yahoo.search.Result; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.test.QueryTestCase; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author baldersheim @@ -25,7 +23,7 @@ import static org.junit.Assert.assertTrue; public class QueryRewriteTestCase { @Test - public void testOptimizeByRestrict() { + void testOptimizeByRestrict() { Query query = new Query("?query=sddocname:music"); query.getModel().setRestrict("music"); QueryRewrite.optimizeByRestrict(query); @@ -33,7 +31,7 @@ public class QueryRewriteTestCase { } @Test - public void requireThatOptimizeByRestrictSimplifiesORItemsThatHaveFullRecallAndDontImpactRank() { + void requireThatOptimizeByRestrictSimplifiesORItemsThatHaveFullRecallAndDontImpactRank() { assertRewritten("sddocname:foo OR sddocname:bar OR sddocname:baz", "foo", "sddocname:foo"); assertRewritten("sddocname:foo OR sddocname:bar OR sddocname:baz", "bar", "sddocname:bar"); assertRewritten("sddocname:foo OR sddocname:bar OR sddocname:baz", "baz", "sddocname:baz"); @@ -48,16 +46,16 @@ public class QueryRewriteTestCase { } @Test - public void testRestrictRewriteDoesNotRemoveRankContributingTerms() { + void testRestrictRewriteDoesNotRemoveRankContributingTerms() { Query query = query("sddocname:per OR foo OR bar", "per"); assertRewritten(query, "OR sddocname:per foo bar"); - ((OrItem)query.getModel().getQueryTree().getRoot()).getItem(2).setRanked(false); // set 'bar' unranked + ((OrItem) query.getModel().getQueryTree().getRoot()).getItem(2).setRanked(false); // set 'bar' unranked assertRewritten(query, "OR sddocname:per foo"); assertRewritten("sddocname:per OR foo OR (bar AND fuz)", "per", "OR sddocname:per foo (AND bar fuz)"); } @Test - public void testRankContributingTermsAreNotRemovedOnFullRecall() { + void testRankContributingTermsAreNotRemovedOnFullRecall() { Query query = new Query(QueryTestCase.httpEncode("?query=default:term1 OR default:term2 OR default:term3 OR sddocname:per&type=adv&recall=+id:1&restrict=per")); RecallSearcher searcher = new RecallSearcher(); Result result = new Execution(searcher, Execution.Context.createContextStub()).search(query); @@ -67,7 +65,7 @@ public class QueryRewriteTestCase { } @Test - public void requireThatOptimizeByRestrictSimplifiesANDItemsThatHaveZeroRecall() { + void requireThatOptimizeByRestrictSimplifiesANDItemsThatHaveZeroRecall() { assertRewritten("sddocname:foo AND bar AND baz", "cox", "NULL"); assertRewritten("foo AND sddocname:bar AND baz", "cox", "NULL"); assertRewritten("foo AND bar AND sddocname:baz", "cox", "NULL"); @@ -82,7 +80,7 @@ public class QueryRewriteTestCase { } @Test - public void testRestrictRewrite() { + void testRestrictRewrite() { assertRewritten("a AND b", "per", "AND a b"); assertRewritten("a OR b", "per", "OR a b"); assertRewritten("sddocname:per", "per", "sddocname:per"); @@ -94,9 +92,9 @@ public class QueryRewriteTestCase { assertRewritten("sddocname:perder ANDNOT b", "per", "NULL"); assertRewritten("a ANDNOT sddocname:per a b", "per", "NULL"); } - + @Test - public void testRestrictRank() { + void testRestrictRank() { assertRewritten("sddocname:per&filter=abc", "espen", "NULL"); assertRewritten("sddocname:per&filter=abc", "per", "RANK sddocname:per |abc"); assertRewritten("sddocname:per RANK bar", "per", "RANK sddocname:per bar"); @@ -119,7 +117,7 @@ public class QueryRewriteTestCase { } @Test - public void assertAndNotMovedUp() { + void assertAndNotMovedUp() { Query query = new Query(); NotItem not = new NotItem(); not.addPositiveItem(new WordItem("a")); @@ -139,7 +137,7 @@ public class QueryRewriteTestCase { } @Test - public void assertMultipleAndNotIsCollapsed() { + void assertMultipleAndNotIsCollapsed() { Query query = new Query(); NotItem not1 = new NotItem(); not1.addPositiveItem(new WordItem("a")); @@ -165,7 +163,7 @@ public class QueryRewriteTestCase { AndItem a = (AndItem) n.getPositiveItem(); assertEquals(5, a.getItemCount()); assertEquals("na1", n.getItem(1).toString()); - assertEquals("na2",n.getItem(2).toString()); + assertEquals("na2", n.getItem(2).toString()); assertEquals("nb", n.getItem(3).toString()); assertEquals("1", a.getItem(0).toString()); assertEquals("a", a.getItem(1).toString()); diff --git a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/RecallSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/RecallSearcherTestCase.java index 409d01b5c46..e2d1555701c 100755 --- a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/RecallSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/RecallSearcherTestCase.java @@ -16,12 +16,9 @@ import com.yahoo.prelude.query.NullItem; import com.yahoo.prelude.query.WordItem; import com.yahoo.prelude.querytransform.RecallSearcher; import com.yahoo.search.searchchain.Execution; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; /** * @author Simon Thoresen Hult @@ -29,7 +26,7 @@ import static org.junit.Assert.fail; public class RecallSearcherTestCase { @Test - public void testIgnoreEmptyProperty() { + void testIgnoreEmptyProperty() { RecallSearcher searcher = new RecallSearcher(); Query query = new Query(); Result result = new Execution(searcher, Execution.Context.createContextStub()).search(query); @@ -38,7 +35,7 @@ public class RecallSearcherTestCase { } @Test - public void testDenyRankItems() { + void testDenyRankItems() { RecallSearcher searcher = new RecallSearcher(); Query query = new Query("?recall=foo"); Result result = new Execution(searcher, Execution.Context.createContextStub()).search(query); @@ -46,7 +43,7 @@ public class RecallSearcherTestCase { } @Test - public void testParse() { + void testParse() { List<String> empty = new ArrayList<>(); assertQueryTree("?query=foo", Arrays.asList("foo"), empty); assertQueryTree("?recall=%2bfoo", empty, Arrays.asList("foo")); diff --git a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/StemmingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/StemmingSearcherTestCase.java index 0d7b0caa65b..bcb243b4563 100644 --- a/container-search/src/test/java/com/yahoo/prelude/querytransform/test/StemmingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/querytransform/test/StemmingSearcherTestCase.java @@ -17,10 +17,10 @@ import com.yahoo.search.config.IndexInfoConfig; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.test.QueryTestCase; -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.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author <a href="mailto:mathiasm@yahoo-inc.com">Mathias M. Lidal</a> @@ -32,13 +32,13 @@ public class StemmingSearcherTestCase { "querytransform/test/", null); @Test - public void testStemOnlySomeTerms() { + void testStemOnlySomeTerms() { assertStem("/search?query=Holes in CVS and Subversion nostem:Found", - "WEAKAND(100) hole in cvs and subversion nostem:Found"); + "WEAKAND(100) hole in cvs and subversion nostem:Found"); } @Test - public void testPhraseSegmentTransforms() { + void testPhraseSegmentTransforms() { Query q1 = buildQueryWithSegmentPhrase(); executeStemming(q1); assertEquals("AND a 'd e'", q1.getModel().getQueryTree().getRoot().toString()); @@ -61,65 +61,65 @@ public class StemmingSearcherTestCase { } @Test - public void testPreserveConnectivityToPhrase() { + void testPreserveConnectivityToPhrase() { Query q1 = buildQueryWithSegmentPhrase(); - CompositeItem r = (CompositeItem)q1.getModel().getQueryTree().getRoot(); - WordItem first = (WordItem)r.getItem(0); - PhraseSegmentItem second = (PhraseSegmentItem)r.getItem(1); + CompositeItem r = (CompositeItem) q1.getModel().getQueryTree().getRoot(); + WordItem first = (WordItem) r.getItem(0); + PhraseSegmentItem second = (PhraseSegmentItem) r.getItem(1); first.setConnectivity(second, 1.0d); executeStemming(q1); assertEquals("AND a 'd e'", q1.getModel().getQueryTree().getRoot().toString()); - r = (CompositeItem)q1.getModel().getQueryTree().getRoot(); - first = (WordItem)r.getItem(0); - second = (PhraseSegmentItem)r.getItem(1); + r = (CompositeItem) q1.getModel().getQueryTree().getRoot(); + first = (WordItem) r.getItem(0); + second = (PhraseSegmentItem) r.getItem(1); var origSecond = first.getConnectedItem(); - assertEquals("Connectivity incorrect.", second, first.getConnectedItem()); + assertEquals(second, first.getConnectedItem(), "Connectivity incorrect."); } @Test - public void testDontStemPrefixes() { + void testDontStemPrefixes() { assertStem("/search?query=ist*&language=de", "WEAKAND(100) ist*"); } @Test - public void testStemming() { + void testStemming() { Query query = new Query("/search?query="); executeStemming(query); assertTrue(query.getModel().getQueryTree().getRoot() instanceof NullItem); } @Test - public void testNounStemming() { + void testNounStemming() { assertStem("/search?query=noun:towers noun:tower noun:tow", - "WEAKAND(100) noun:tower noun:tower noun:tow"); + "WEAKAND(100) noun:tower noun:tower noun:tow"); assertStem("/search?query=notnoun:towers notnoun:tower notnoun:tow", - "WEAKAND(100) notnoun:tower notnoun:tower notnoun:tow"); + "WEAKAND(100) notnoun:tower notnoun:tower notnoun:tow"); } @SuppressWarnings("deprecation") @Test - public void testEmptyIndexInfo() { + void testEmptyIndexInfo() { String indexInfoConfigID = "file:src/test/java/com/yahoo/prelude/querytransform/test/emptyindexinfo.cfg"; ConfigGetter<IndexInfoConfig> getter = new ConfigGetter<>(IndexInfoConfig.class); IndexInfoConfig config = getter.getConfig(indexInfoConfigID); - IndexFacts indexFacts = new IndexFacts(new IndexModel(config, (QrSearchersConfig)null)); + IndexFacts indexFacts = new IndexFacts(new IndexModel(config, (QrSearchersConfig) null)); Query q = new Query(QueryTestCase.httpEncode("?query=cars")); new Execution(new Chain<Searcher>(new StemmingSearcher(linguistics)), - Execution.Context.createContextStub(indexFacts, linguistics)).search(q); + Execution.Context.createContextStub(indexFacts, linguistics)).search(q); assertEquals("WEAKAND(100) cars", q.getModel().getQueryTree().getRoot().toString()); } @Test - public void testLiteralBoost() { + void testLiteralBoost() { Query q = new Query(QueryTestCase.httpEncode("/search?language=en&search=three")); WordItem scratch = new WordItem("trees", true); scratch.setStemmed(false); q.getModel().getQueryTree().setRoot(scratch); executeStemming(q); - assertTrue("Expected a set of word alternatives as root.", - q.getModel().getQueryTree().getRoot() instanceof WordAlternativesItem); + assertTrue(q.getModel().getQueryTree().getRoot() instanceof WordAlternativesItem, + "Expected a set of word alternatives as root."); WordAlternativesItem w = (WordAlternativesItem) q.getModel().getQueryTree().getRoot(); boolean foundExpectedBaseForm = false; for (WordAlternativesItem.Alternative a : w.getAlternatives()) { @@ -128,16 +128,16 @@ public class StemmingSearcherTestCase { foundExpectedBaseForm = true; } } - assertTrue("Did not find original word form in query.", foundExpectedBaseForm); + assertTrue(foundExpectedBaseForm, "Did not find original word form in query."); } @Test - public void testMultipleStemming() { + void testMultipleStemming() { Query q = new Query(QueryTestCase.httpEncode("/search?language=en&search=four&query=trees \"nouns girls\" flowers \"a verbs a\" girls&default-index=foobar")); executeStemming(q); - assertEquals("WEAKAND(100) WORD_ALTERNATIVES foobar:[ tree(0.7) trees(1.0) ] "+ - "foobar:\"noun girl\" WORD_ALTERNATIVES foobar:[ flower(0.7) flowers(1.0) ] "+ - "foobar:\"a verb a\" WORD_ALTERNATIVES foobar:[ girl(0.7) girls(1.0) ]", q.getModel().getQueryTree().getRoot().toString()); + assertEquals("WEAKAND(100) WORD_ALTERNATIVES foobar:[ tree(0.7) trees(1.0) ] " + + "foobar:\"noun girl\" WORD_ALTERNATIVES foobar:[ flower(0.7) flowers(1.0) ] " + + "foobar:\"a verb a\" WORD_ALTERNATIVES foobar:[ girl(0.7) girls(1.0) ]", q.getModel().getQueryTree().getRoot().toString()); } private Execution.Context newExecutionContext() { diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/BlendingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/BlendingSearcherTestCase.java index 4fffc450e74..156a0dcbb3e 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/BlendingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/BlendingSearcherTestCase.java @@ -31,12 +31,9 @@ import com.yahoo.search.searchchain.Execution; import com.yahoo.search.searchchain.SearchChain; import com.yahoo.search.searchchain.SearchChainRegistry; import com.yahoo.search.searchchain.testutil.DocumentSourceSearcher; -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.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Tests the BlendingSearcher class @@ -125,7 +122,7 @@ public class BlendingSearcherTestCase { } @Test - public void testitTwoPhase() { + void testitTwoPhase() { DocumentSourceSearcher chain1 = new DocumentSourceSearcher(); DocumentSourceSearcher chain2 = new DocumentSourceSearcher(); DocumentSourceSearcher chain3 = new DocumentSourceSearcher(); @@ -137,27 +134,63 @@ public class BlendingSearcherTestCase { Result r3 = new Result(q); r1.setTotalHitCount(13); - r1.hits().add(new Hit("http://host1.com", 101){{setSource("one");}}); - r1.hits().add(new Hit("http://host2.com", 102){{setSource("one");}}); - r1.hits().add(new Hit("http://host3.com", 103){{setSource("one");}}); + r1.hits().add(new Hit("http://host1.com", 101){ + { + setSource("one"); + } + }); + r1.hits().add(new Hit("http://host2.com", 102){ + { + setSource("one"); + } + }); + r1.hits().add(new Hit("http://host3.com", 103){ + { + setSource("one"); + } + }); chain1.addResult(q, r1); r2.setTotalHitCount(17); - r2.hits().add(new Hit("http://host1.com", 101){{setSource("two");}}); - r2.hits().add(new Hit("http://host2.com", 102){{setSource("two");}}); - r2.hits().add(new Hit("http://host4.com", 104){{setSource("two");}}); + r2.hits().add(new Hit("http://host1.com", 101){ + { + setSource("two"); + } + }); + r2.hits().add(new Hit("http://host2.com", 102){ + { + setSource("two"); + } + }); + r2.hits().add(new Hit("http://host4.com", 104){ + { + setSource("two"); + } + }); chain2.addResult(q, r2); r3.setTotalHitCount(37); - r3.hits().add(new Hit("http://host5.com", 100){{setSource("three");}}); - r3.hits().add(new Hit("http://host6.com", 106){{setSource("three");}}); - r3.hits().add(new Hit("http://host7.com", 105){{setSource("three");}}); + r3.hits().add(new Hit("http://host5.com", 100){ + { + setSource("three"); + } + }); + r3.hits().add(new Hit("http://host6.com", 106){ + { + setSource("three"); + } + }); + r3.hits().add(new Hit("http://host7.com", 105){ + { + setSource("three"); + } + }); chain3.addResult(q, r3); BlendingSearcherWrapper blender1 = new BlendingSearcherWrapper(); blender1.addSource("one", chain1); blender1.initialize(); - q.setWindow( 0, 10); + q.setWindow(0, 10); Result br1 = new Execution(blender1, Execution.Context.createContextStub()).search(q); assertEquals(3, br1.getHitCount()); assertEquals(13, br1.getTotalHitCount()); @@ -167,7 +200,7 @@ public class BlendingSearcherTestCase { blender2.addSource("two", chain1); blender2.addSource("three", chain2); blender2.initialize(); - q.setWindow( 0, 10); + q.setWindow(0, 10); Result br2 = new Execution(blender2, Execution.Context.createContextStub()).search(q); assertEquals(6, br2.getHitCount()); assertEquals(30, br2.getTotalHitCount()); @@ -178,28 +211,28 @@ public class BlendingSearcherTestCase { blender3.addSource("five", chain2); blender3.addSource("six", chain3); blender3.initialize(); - q.setWindow( 0, 10); + q.setWindow(0, 10); Result br3 = new Execution(blender3, Execution.Context.createContextStub()).search(q); assertEquals(9, br3.getHitCount()); assertEquals(67, br3.getTotalHitCount()); assertEquals("http://host6.com/", br3.hits().get(0).getId().toString()); - q.setWindow( 0, 10); + q.setWindow(0, 10); Result br4 = new Execution(blender3, Execution.Context.createContextStub()).search(q); assertEquals(9, br4.getHitCount()); assertEquals("http://host6.com/", br4.hits().get(0).getId().toString()); - q.setWindow( 3, 10); + q.setWindow(3, 10); Result br5 = new Execution(blender3, Execution.Context.createContextStub()).search(q); assertEquals(6, br5.getHitCount()); assertEquals("http://host3.com/", br5.hits().get(0).getId().toString()); - q.setWindow( 3, 10); + q.setWindow(3, 10); br5 = new Execution(blender3, Execution.Context.createContextStub()).search(q); assertEquals(6, br5.getHitCount()); assertEquals("http://host3.com/", br5.hits().get(0).getId().toString()); - q.setWindow( 3, 10); + q.setWindow(3, 10); br5 = new Execution(blender3, Execution.Context.createContextStub()).search(q); assertEquals(6, br5.getHitCount()); assertEquals("http://host3.com/", br5.hits().get(0).getId().toString()); @@ -207,7 +240,7 @@ public class BlendingSearcherTestCase { } @Test - public void testMultipleBackendsWithDuplicateRemoval() { + void testMultipleBackendsWithDuplicateRemoval() { DocumentSourceSearcher docSource1 = new DocumentSourceSearcher(); DocumentSourceSearcher docSource2 = new DocumentSourceSearcher(); Query q = new Query("/search?query=hannibal&search=a,b"); @@ -225,14 +258,14 @@ public class BlendingSearcherTestCase { blender.addSource(new Chain<>("a", new FillSearcher(), docSource1)); blender.addSource(new Chain<>("b", new FillSearcher(), docSource2)); blender.initialize(); - q.setWindow( 0, 10); + q.setWindow(0, 10); Result cr = new Execution(blender, Execution.Context.createContextStub()).search(q); assertEquals(1, cr.getHitCount()); assertEquals(101, ((int) cr.hits().get(0).getRelevance().getScore())); } @Test - public void testMultipleBackendsWithErrorMerging() { + void testMultipleBackendsWithErrorMerging() { DocumentSourceSearcher docSource1 = new DocumentSourceSearcher(); DocumentSourceSearcher docSource2 = new DocumentSourceSearcher(); Query q = new Query("/search?query=hannibal&search=a,b"); @@ -249,25 +282,25 @@ public class BlendingSearcherTestCase { blender.addSource(new Chain<>("a", new FillSearcher(), docSource1)); blender.addSource(new Chain<>("b", new FillSearcher(), docSource2)); blender.initialize(); - q.setWindow( 0, 10); + q.setWindow(0, 10); Result cr = new Execution(blender, Execution.Context.createContextStub()).search(q); assertEquals(2, cr.getHitCount()); assertEquals(1, cr.getConcreteHitCount()); com.yahoo.search.result.ErrorHit errorHit = cr.hits().getErrorHit(); Iterator errorIterator = errorHit.errorIterator(); List<String> errorList = Arrays.asList("Source 'a': No backends in service. Try later", - "Source 'b': 2: Request too large"); + "Source 'b': 2: Request too large"); String a = errorIterator.next().toString(); - assertTrue(a, errorList.contains(a)); + assertTrue(errorList.contains(a), a); String b = errorIterator.next().toString(); - assertTrue(a, errorList.contains(b)); + assertTrue(errorList.contains(b), a); assertFalse(errorIterator.hasNext()); assertEquals(102, ((int) cr.hits().get(1).getRelevance().getScore())); assertEquals(com.yahoo.container.protect.Error.NO_BACKENDS_IN_SERVICE.code, cr.hits().getError().getCode()); } @Test - public void testBlendingWithSortSpec() { + void testBlendingWithSortSpec() { DocumentSourceSearcher docSource1 = new DocumentSourceSearcher(); DocumentSourceSearcher docSource2 = new DocumentSourceSearcher(); @@ -310,7 +343,7 @@ public class BlendingSearcherTestCase { blender.addSource(new Chain<>("a", new FillSearcher(), docSource1)); blender.addSource(new Chain<>("b", new FillSearcher(), docSource2)); blender.initialize(); - q.setWindow( 0, 10); + q.setWindow(0, 10); Result br = new Execution(blender, Execution.Context.createContextStub()).search(q); assertEquals(202, ((int) br.hits().get(0).getRelevance().getScore())); assertEquals(103, ((int) br.hits().get(1).getRelevance().getScore())); @@ -326,7 +359,7 @@ public class BlendingSearcherTestCase { * But are we sure fsearch handles this case correctly? */ @Test - public void testBlendingWithSortSpecAnd2Phase() { + void testBlendingWithSortSpecAnd2Phase() { DocumentSourceSearcher docSource1 = new DocumentSourceSearcher(); DocumentSourceSearcher docSource2 = new DocumentSourceSearcher(); @@ -362,7 +395,7 @@ public class BlendingSearcherTestCase { blender.addSource("chainedone", docSource1); blender.addSource("chainedtwo", docSource2); blender.initialize(); - q.setWindow( 0, 10); + q.setWindow(0, 10); Result br = new Execution(blender, Execution.Context.createContextStub()).search(q); assertEquals(202, ((int) br.hits().get(0).getRelevance().getScore())); assertEquals(103, ((int) br.hits().get(1).getRelevance().getScore())); @@ -400,7 +433,7 @@ public class BlendingSearcherTestCase { } @Test - public void testOnlyFirstBackend() { + void testOnlyFirstBackend() { BlendingSearcherWrapper searcher = setupFirstAndSecond(); Query query = new Query("/search?query=banana&search=first"); @@ -410,7 +443,7 @@ public class BlendingSearcherTestCase { } @Test - public void testOnlySecondBackend() { + void testOnlySecondBackend() { BlendingSearcherWrapper searcher = setupFirstAndSecond(); Query query = new Query("/search?query=banana&search=second"); @@ -421,7 +454,7 @@ public class BlendingSearcherTestCase { } @Test - public void testBothBackendsExplicitly() { + void testBothBackendsExplicitly() { BlendingSearcherWrapper searcher = setupFirstAndSecond(); Query query = new Query("/search?query=banana&search=first,second"); @@ -433,7 +466,7 @@ public class BlendingSearcherTestCase { } @Test - public void testBothBackendsImplicitly() { + void testBothBackendsImplicitly() { BlendingSearcherWrapper searcher = setupFirstAndSecond(); Query query = new Query("/search?query=banana"); @@ -445,7 +478,7 @@ public class BlendingSearcherTestCase { } @Test - public void testNonexistingBackendCausesError() { + void testNonexistingBackendCausesError() { BlendingSearcherWrapper searcher = setupFirstAndSecond(); Query query = new Query("/search?query=banana&search=nonesuch"); @@ -459,7 +492,7 @@ public class BlendingSearcherTestCase { } @Test - public void testNonexistingBackendsCausesErrorOnFirst() { + void testNonexistingBackendsCausesErrorOnFirst() { // Feel free to change to include all in the detail message... BlendingSearcherWrapper searcher = setupFirstAndSecond(); Query query = new Query("/search?query=banana&search=nonesuch,orsuch"); @@ -471,11 +504,11 @@ public class BlendingSearcherTestCase { assertEquals("Invalid query parameter", e.getMessage()); //TODO: Do not depend on sources order assertEquals("4: Invalid query parameter: Could not resolve source ref 'nonesuch'. Could not resolve source ref 'orsuch'. Valid source refs are first, second.", - e.toString()); + e.toString()); } @Test - public void testExistingAndNonExistingBackendCausesBothErrorAndResult() { + void testExistingAndNonExistingBackendCausesBothErrorAndResult() { BlendingSearcherWrapper searcher = setupFirstAndSecond(); Query query = new Query("/search?query=banana&search=first,nonesuch,second"); @@ -488,11 +521,11 @@ public class BlendingSearcherTestCase { ErrorMessage e = result.hits().getError(); //TODO: Do not depend on sources order assertEquals("Could not resolve source ref 'nonesuch'. Valid source refs are first, second.", - e.getDetailedMessage()); + e.getDetailedMessage()); } @Test - public void testBlendingFederationWithGrouping() { + void testBlendingFederationWithGrouping() { DocumentSourceSearcher docSource1 = new DocumentSourceSearcher(); DocumentSourceSearcher docSource2 = new DocumentSourceSearcher(); @@ -528,22 +561,22 @@ public class BlendingSearcherTestCase { blender.addSource(new Chain<>("a", new FillSearcher(), docSource1)); blender.addSource(new Chain<>("b", new FillSearcher(), docSource2)); blender.initialize(); - q.setWindow( 0, 10); + q.setWindow(0, 10); Result result = new Execution(blender, Execution.Context.createContextStub()).search(q); assertEquals(2, result.hits().size()); assertTrue(result.hits().get(0) instanceof RootGroup); - RootGroup resultRoot1 = (RootGroup)result.hits().get(0); + RootGroup resultRoot1 = (RootGroup) result.hits().get(0); assertEquals(1, resultRoot1.asList().size()); assertTrue(result.hits().get(1) instanceof RootGroup); - RootGroup resultRoot2 = (RootGroup)result.hits().get(1); + RootGroup resultRoot2 = (RootGroup) result.hits().get(1); assertEquals(2, resultRoot2.asList().size()); } /** Multiple document types in the same cluster are returned without a top level group representing each */ @Test - public void testBlendingMultipleDocumentTypesWithGrouping() { + void testBlendingMultipleDocumentTypesWithGrouping() { DocumentSourceSearcher docSource = new DocumentSourceSearcher(); Query q = new Query("/search?query=test"); @@ -574,23 +607,23 @@ public class BlendingSearcherTestCase { docSource.addResult(q, r); Chain<Searcher> chain = new Chain<>("main", - new FillSearcher(), - new BlendingSearcher(ComponentId.fromString("test"), new QrSearchersConfig.Builder().build()), - docSource); - q.setWindow( 0, 10); + new FillSearcher(), + new BlendingSearcher(ComponentId.fromString("test"), new QrSearchersConfig.Builder().build()), + docSource); + q.setWindow(0, 10); Result result = new Execution(chain, Execution.Context.createContextStub()).search(q); assertEquals(3, result.hits().size()); assertTrue(result.hits().get(0) instanceof Group); - Group resultSubGroup1 = (Group)result.hits().get(0); + Group resultSubGroup1 = (Group) result.hits().get(0); assertEquals(4, resultSubGroup1.asList().size()); assertTrue(result.hits().get(1) instanceof Group); - Group resultSubGroup2 = (Group)result.hits().get(1); + Group resultSubGroup2 = (Group) result.hits().get(1); assertEquals(3, resultSubGroup2.asList().size()); assertTrue(result.hits().get(2) instanceof Group); - Group resultSubGroup3 = (Group)result.hits().get(2); + Group resultSubGroup3 = (Group) result.hits().get(2); assertEquals(2, resultSubGroup3.asList().size()); } diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/FieldCollapsingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/FieldCollapsingSearcherTestCase.java index de6a55354fd..4a2a34a64c2 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/FieldCollapsingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/FieldCollapsingSearcherTestCase.java @@ -21,18 +21,14 @@ import com.yahoo.search.result.HitGroup; import com.yahoo.search.result.Relevance; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.searchchain.testutil.DocumentSourceSearcher; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Tests the FieldCollapsingSearcher class @@ -42,7 +38,7 @@ import static org.junit.Assert.assertTrue; public class FieldCollapsingSearcherTestCase { @Test - public void testFieldCollapsingWithoutHits() { + void testFieldCollapsingWithoutHits() { // Set up Map<Searcher, Searcher> chained = new HashMap<>(); @@ -59,7 +55,7 @@ public class FieldCollapsingSearcherTestCase { } @Test - public void testFieldCollapsingWithoutHitsHugeOffset() { + void testFieldCollapsingWithoutHitsHugeOffset() { Map<Searcher, Searcher> chained = new HashMap<>(); FieldCollapsingSearcher collapse = new FieldCollapsingSearcher("other"); @@ -75,7 +71,7 @@ public class FieldCollapsingSearcherTestCase { } @Test - public void testFieldCollapsing() { + void testFieldCollapsing() { Map<Searcher, Searcher> chained = new HashMap<>(); // Set up @@ -89,7 +85,7 @@ public class FieldCollapsingSearcherTestCase { // The searcher turns off collapsing further on in the chain q.properties().set("collapse", "0"); Result r = new Result(q); - r.hits().add(createHit("http://acme.org/a.html",10, 0)); + r.hits().add(createHit("http://acme.org/a.html", 10, 0)); r.hits().add(createHit("http://acme.org/b.html", 9, 0)); r.hits().add(createHit("http://acme.org/c.html", 9, 1)); r.hits().add(createHit("http://acme.org/d.html", 8, 1)); @@ -106,14 +102,14 @@ public class FieldCollapsingSearcherTestCase { assertEquals(4, r.getHitCount()); assertEquals(1, docsource.getQueryCount()); - assertHit("http://acme.org/a.html",10, 0, r.hits().get(0)); + assertHit("http://acme.org/a.html", 10, 0, r.hits().get(0)); assertHit("http://acme.org/c.html", 9, 1, r.hits().get(1)); assertHit("http://acme.org/e.html", 8, 2, r.hits().get(2)); assertHit("http://acme.org/g.html", 7, 3, r.hits().get(3)); } @Test - public void testFieldCollapsingTwoPhase() { + void testFieldCollapsingTwoPhase() { // Set up Map<Searcher, Searcher> chained = new HashMap<>(); FieldCollapsingSearcher collapse = new FieldCollapsingSearcher("other"); @@ -125,7 +121,7 @@ public class FieldCollapsingSearcherTestCase { // The searcher turns off collapsing further on in the chain q.properties().set("collapse", "0"); Result r = new Result(q); - r.hits().add(createHit("http://acme.org/a.html",10, 0)); + r.hits().add(createHit("http://acme.org/a.html", 10, 0)); r.hits().add(createHit("http://acme.org/b.html", 9, 0)); r.hits().add(createHit("http://acme.org/c.html", 9, 1)); r.hits().add(createHit("http://acme.org/d.html", 8, 1)); @@ -142,14 +138,14 @@ public class FieldCollapsingSearcherTestCase { assertEquals(4, r.getHitCount()); assertEquals(1, docsource.getQueryCount()); - assertHit("http://acme.org/a.html",10,0, r.hits().get(0)); - assertHit("http://acme.org/c.html", 9,1, r.hits().get(1)); - assertHit("http://acme.org/e.html", 8,2, r.hits().get(2)); - assertHit("http://acme.org/g.html", 7,3, r.hits().get(3)); + assertHit("http://acme.org/a.html", 10, 0, r.hits().get(0)); + assertHit("http://acme.org/c.html", 9, 1, r.hits().get(1)); + assertHit("http://acme.org/e.html", 8, 2, r.hits().get(2)); + assertHit("http://acme.org/g.html", 7, 3, r.hits().get(3)); } @Test - public void testNoCollapsingIfNotAskedTo() { + void testNoCollapsingIfNotAskedTo() { // Set up Map<Searcher, Searcher> chained = new HashMap<>(); FieldCollapsingSearcher collapse = new FieldCollapsingSearcher(); @@ -158,7 +154,7 @@ public class FieldCollapsingSearcherTestCase { Query q = new Query("?query=test_collapse"); Result r = new Result(q); - r.hits().add(createHit("http://acme.org/a.html",10, 0)); + r.hits().add(createHit("http://acme.org/a.html", 10, 0)); r.hits().add(createHit("http://acme.org/b.html", 9, 0)); r.hits().add(createHit("http://acme.org/c.html", 9, 1)); r.hits().add(createHit("http://acme.org/d.html", 8, 1)); @@ -182,10 +178,10 @@ public class FieldCollapsingSearcherTestCase { * an excessive number of backend requests */ @Test - public void testCollapsingLargeCollection() { + void testCollapsingLargeCollection() { // Set up Map<Searcher, Searcher> chained = new HashMap<>(); - FieldCollapsingSearcher collapse = new FieldCollapsingSearcher(4,2.0,"amid"); + FieldCollapsingSearcher collapse = new FieldCollapsingSearcher(4, 2.0, "amid"); DocumentSourceSearcher docsource = new DocumentSourceSearcher(); chained.put(collapse, docsource); @@ -193,7 +189,7 @@ public class FieldCollapsingSearcherTestCase { // The searcher turns off collapsing further on in the chain q.properties().set("collapse", "0"); Result r = new Result(q); - r.hits().add(createHit("http://acme.org/a.html",10, 0)); + r.hits().add(createHit("http://acme.org/a.html", 10, 0)); r.hits().add(createHit("http://acme.org/b.html", 9, 0)); r.hits().add(createHit("http://acme.org/c.html", 9, 0)); r.hits().add(createHit("http://acme.org/d.html", 8, 0)); @@ -212,7 +208,7 @@ public class FieldCollapsingSearcherTestCase { assertEquals(2, r.getHitCount()); assertEquals(2, docsource.getQueryCount()); - assertHit("http://acme.org/a.html",10, 0, r.hits().get(0)); + assertHit("http://acme.org/a.html", 10, 0, r.hits().get(0)); assertHit("http://acme.org/i.html", 5, 1, r.hits().get(1)); // Next results @@ -220,17 +216,17 @@ public class FieldCollapsingSearcherTestCase { r = doSearch(collapse, q, 2, 2, chained); assertEquals(1, r.getHitCount()); assertEquals(2, docsource.getQueryCount()); - assertHit("http://acme.org/j.html",4, 2, r.hits().get(0)); + assertHit("http://acme.org/j.html", 4, 2, r.hits().get(0)); } /** * Tests collapsing of "messy" data */ @Test - public void testCollapsingDispersedCollection() { + void testCollapsingDispersedCollection() { // Set up Map<Searcher, Searcher> chained = new HashMap<>(); - FieldCollapsingSearcher collapse = new FieldCollapsingSearcher(1,2.0,"amid"); + FieldCollapsingSearcher collapse = new FieldCollapsingSearcher(1, 2.0, "amid"); DocumentSourceSearcher docsource = new DocumentSourceSearcher(); chained.put(collapse, docsource); @@ -256,12 +252,12 @@ public class FieldCollapsingSearcherTestCase { r = doSearch(collapse, q, 0, 3, chained); assertEquals(2, r.getHitCount()); - assertHit("http://acme.org/a.html",10,1,r.hits().get(0)); - assertHit("http://acme.org/c.html",10,0,r.hits().get(1)); + assertHit("http://acme.org/a.html", 10, 1, r.hits().get(0)); + assertHit("http://acme.org/c.html", 10, 0, r.hits().get(1)); } @Test - public void testQueryTransformAndCollapsing() { + void testQueryTransformAndCollapsing() { // Set up Map<Searcher, Searcher> chained = new HashMap<>(); FieldCollapsingSearcher collapse = new FieldCollapsingSearcher("other"); @@ -277,14 +273,14 @@ public class FieldCollapsingSearcherTestCase { // The searcher turns off collapsing further on in the chain q.properties().set("collapse", "0"); Result r = new Result(q); - r.hits().add(createHit("http://acme.org/a.html",10,0)); - r.hits().add(createHit("http://acme.org/b.html", 9,0)); - r.hits().add(createHit("http://acme.org/c.html", 9,0)); - r.hits().add(createHit("http://acme.org/d.html", 8,0)); - r.hits().add(createHit("http://acme.org/e.html", 8,0)); - r.hits().add(createHit("http://acme.org/f.html", 7,0)); - r.hits().add(createHit("http://acme.org/g.html", 7,0)); - r.hits().add(createHit("http://acme.org/h.html", 6,1)); + r.hits().add(createHit("http://acme.org/a.html", 10, 0)); + r.hits().add(createHit("http://acme.org/b.html", 9, 0)); + r.hits().add(createHit("http://acme.org/c.html", 9, 0)); + r.hits().add(createHit("http://acme.org/d.html", 8, 0)); + r.hits().add(createHit("http://acme.org/e.html", 8, 0)); + r.hits().add(createHit("http://acme.org/f.html", 7, 0)); + r.hits().add(createHit("http://acme.org/g.html", 7, 0)); + r.hits().add(createHit("http://acme.org/h.html", 6, 1)); r.setTotalHitCount(8); docsource.addResult(q, r); @@ -294,12 +290,12 @@ public class FieldCollapsingSearcherTestCase { assertEquals(2, docsource.getQueryCount()); assertEquals(2, r.getHitCount()); - assertHit("http://acme.org/a.html",10, 0, r.hits().get(0)); + assertHit("http://acme.org/a.html", 10, 0, r.hits().get(0)); assertHit("http://acme.org/h.html", 6, 1, r.hits().get(1)); } @Test - public void testFieldCollapsingTwoPhaseSelectSummary() { + void testFieldCollapsingTwoPhaseSelectSummary() { // Set up Map<Searcher, Searcher> chained = new HashMap<>(); FieldCollapsingSearcher collapse = new FieldCollapsingSearcher("other"); @@ -311,14 +307,14 @@ public class FieldCollapsingSearcherTestCase { // The searcher turns off collapsing further on in the chain q.properties().set("collapse", "0"); Result r = new Result(q); - r.hits().add(createHit("http://acme.org/a.html",10,0)); - r.hits().add(createHit("http://acme.org/b.html", 9,0)); - r.hits().add(createHit("http://acme.org/c.html", 9,1)); - r.hits().add(createHit("http://acme.org/d.html", 8,1)); - r.hits().add(createHit("http://acme.org/e.html", 8,2)); - r.hits().add(createHit("http://acme.org/f.html", 7,2)); - r.hits().add(createHit("http://acme.org/g.html", 7,3)); - r.hits().add(createHit("http://acme.org/h.html", 6,3)); + r.hits().add(createHit("http://acme.org/a.html", 10, 0)); + r.hits().add(createHit("http://acme.org/b.html", 9, 0)); + r.hits().add(createHit("http://acme.org/c.html", 9, 1)); + r.hits().add(createHit("http://acme.org/d.html", 8, 1)); + r.hits().add(createHit("http://acme.org/e.html", 8, 2)); + r.hits().add(createHit("http://acme.org/f.html", 7, 2)); + r.hits().add(createHit("http://acme.org/g.html", 7, 3)); + r.hits().add(createHit("http://acme.org/h.html", 6, 3)); r.setTotalHitCount(8); docsource.addResult(q, r); @@ -329,7 +325,7 @@ public class FieldCollapsingSearcherTestCase { assertEquals(4, r.getHitCount()); assertEquals(1, docsource.getQueryCount()); assertTrue(r.isFilled("placeholder")); - assertHit("http://acme.org/a.html",10, 0, r.hits().get(0)); + assertHit("http://acme.org/a.html", 10, 0, r.hits().get(0)); assertHit("http://acme.org/c.html", 9, 1, r.hits().get(1)); assertHit("http://acme.org/e.html", 8, 2, r.hits().get(2)); assertHit("http://acme.org/g.html", 7, 3, r.hits().get(3)); @@ -343,18 +339,18 @@ public class FieldCollapsingSearcherTestCase { assertEquals(1, docsource.getQueryCount()); assertFalse(r.isFilled("placeholder")); assertTrue(r.isFilled("short")); - assertHit("http://acme.org/a.html",10, 0, r.hits().get(0)); + assertHit("http://acme.org/a.html", 10, 0, r.hits().get(0)); assertHit("http://acme.org/c.html", 9, 1, r.hits().get(1)); assertHit("http://acme.org/e.html", 8, 2, r.hits().get(2)); assertHit("http://acme.org/g.html", 7, 3, r.hits().get(3)); } @Test - public void testFieldCollapsingWithGrouping() { + void testFieldCollapsingWithGrouping() { // Set up FieldCollapsingSearcher collapse = new FieldCollapsingSearcher("other"); DocumentSourceSearcher docsource = new DocumentSourceSearcher(); - Chain<Searcher> chain=new Chain<>(collapse,new AddAggregationStyleGroupingResultSearcher(),docsource); + Chain<Searcher> chain = new Chain<>(collapse, new AddAggregationStyleGroupingResultSearcher(), docsource); // Caveat: Collapse is set to false, because that's what the // collapser asks for @@ -362,7 +358,7 @@ public class FieldCollapsingSearcherTestCase { // The searcher turns off collapsing further on in the chain q.properties().set("collapse", "0"); Result r = new Result(q); - r.hits().add(createHit("http://acme.org/a.html",10, 0)); + r.hits().add(createHit("http://acme.org/a.html", 10, 0)); r.hits().add(createHit("http://acme.org/b.html", 9, 0)); r.hits().add(createHit("http://acme.org/c.html", 9, 1)); r.hits().add(createHit("http://acme.org/d.html", 8, 1)); @@ -380,7 +376,7 @@ public class FieldCollapsingSearcherTestCase { // Assert that the regular hits are collapsed assertEquals(4 + 1, result.getHitCount()); assertEquals(1, docsource.getQueryCount()); - assertHit("http://acme.org/a.html",10, 0, result.hits().get(0)); + assertHit("http://acme.org/a.html", 10, 0, result.hits().get(0)); assertHit("http://acme.org/c.html", 9, 1, result.hits().get(1)); assertHit("http://acme.org/e.html", 8, 2, result.hits().get(2)); assertHit("http://acme.org/g.html", 7, 3, result.hits().get(3)); @@ -388,12 +384,12 @@ public class FieldCollapsingSearcherTestCase { // Assert that the aggregation group hierarchy is left intact HitGroup root = getFirstGroupIn(result.hits()); assertNotNull(root); - assertEquals("group:root:",root.getId().stringValue().substring(0, 11)); // The id ends by a global counter currently + assertEquals("group:root:", root.getId().stringValue().substring(0, 11)); // The id ends by a global counter currently assertEquals(1, root.size()); - HitGroup groupList = (GroupList)root.get("grouplist:g1"); + HitGroup groupList = (GroupList) root.get("grouplist:g1"); assertNotNull(groupList); assertEquals(1, groupList.size()); - HitGroup group = (HitGroup)groupList.get("group:long:37"); + HitGroup group = (HitGroup) groupList.get("group:long:37"); assertNotNull(group); } diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/JSONDebugSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/JSONDebugSearcherTestCase.java index 6a230da4950..a10ecfb99e0 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/JSONDebugSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/JSONDebugSearcherTestCase.java @@ -14,10 +14,10 @@ import com.yahoo.search.searchchain.Execution; import com.yahoo.search.searchchain.testutil.DocumentSourceSearcher; import com.yahoo.yolean.trace.TraceNode; import com.yahoo.yolean.trace.TraceVisitor; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Visit the trace and check JSON payload is stored there when requested. @@ -30,7 +30,7 @@ public class JSONDebugSearcherTestCase { private static final String DUMPJSON = "?query=1&dumpjson=jsonfield&tracelevel=6"; @Test - public void test() { + void test() { Chain<Searcher> searchChain = makeSearchChain("{1: 2}", new JSONDebugSearcher()); Execution e = new Execution(searchChain, Execution.Context.createContextStub()); e.search(new Query(NODUMPJSON)); diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/JuniperSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/JuniperSearcherTestCase.java index 706d217269b..bd72ed9fd08 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/JuniperSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/JuniperSearcherTestCase.java @@ -1,9 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.searcher.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; import com.google.common.collect.ImmutableList; import com.yahoo.component.ComponentId; @@ -22,7 +20,7 @@ import com.yahoo.search.result.Relevance; import com.yahoo.search.searchchain.testutil.DocumentSourceSearcher; import com.yahoo.prelude.searcher.JuniperSearcher; import com.yahoo.search.searchchain.Execution; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collection; import java.util.LinkedHashMap; @@ -113,19 +111,19 @@ public class JuniperSearcherTestCase { } @Test - public void testFieldRewriting() { + void testFieldRewriting() { Result check = createResult("\u001FXYZ\u001F\u001EQWE\u001FJKL\u001FASD&"); assertEquals(1, check.getHitCount()); assertEquals("<hi>XYZ</hi><sep />QWE<hi>JKL</hi>ASD&", - check.hits().get(0).getField("dynteaser").toString()); + check.hits().get(0).getField("dynteaser").toString()); check = createResult("a&b&c"); assertEquals(1, check.getHitCount()); assertEquals("a&b&c", - check.hits().get(0).getField("dynteaser").toString()); + check.hits().get(0).getField("dynteaser").toString()); } @Test - public void testNoRewritingDueToSearchDefinition() { + void testNoRewritingDueToSearchDefinition() { Result check = createResult("two", "\u001FXYZ\u001F\u001EQWE\u001FJKL\u001FASD&"); assertEquals(1, check.getHitCount()); assertEquals("\u001FXYZ\u001F\u001EQWE\u001FJKL\u001FASD&", @@ -137,20 +135,20 @@ public class JuniperSearcherTestCase { } @Test - public void testBoldingEquals() { + void testBoldingEquals() { assertNotEquals(new Query("?query=12"), new Query("?query=12&bolding=false")); } @Test - public void testUnboldedRewriting() { + void testUnboldedRewriting() { Result check = createResult("one", "\u001FXYZ\u001F\u001EQWE\u001FJKL\u001FASD&", false); assertEquals(1, check.getHitCount()); assertEquals("XYZ...QWEJKLASD&", - check.hits().get(0).getField("dynteaser").toString()); + check.hits().get(0).getField("dynteaser").toString()); } @Test - public void testAnnotatedSummaryFields() { + void testAnnotatedSummaryFields() { Result check = createResult("\uFFF9Feeding\uFFFAfeed\uFFFB \u001F\uFFF9documents\uFFFAdocument\uFFFB\u001F into Vespa \uFFF9is\uFFFAbe\u001Eincrement of a set of \u001F\uFFF9documents\uFFFAdocument\uFFFB\u001F fed into Vespa \uFFF9is\u001Efloat in XML when \u001Fdocument\u001F attribute \uFFF9is\uFFFAbe\uFFFB int\u001E"); assertEquals(1, check.getHitCount()); assertEquals("Feeding <hi>documents</hi> into Vespa is<sep />increment of a set of <hi>documents</hi> fed into Vespa <sep />float in XML when <hi>document</hi> attribute is int<sep />", check.hits().get(0).getField("dynteaser").toString()); @@ -185,7 +183,7 @@ public class JuniperSearcherTestCase { } @Test - public void testThatIncompleteAnnotationWithHighlightIsIgnored() { + void testThatIncompleteAnnotationWithHighlightIsIgnored() { // Look at bug 5707026 for details. { Result check = createResult("of\u001e\u001fyahoo\u001f\uFFFB! \uFFF9Angels\uFFFAangels\uFFFB \uFFF9\u001fYahoo\u001f\uFFFA\u001fyahoo\u001f\uFFFB! \uFFF9Angles\uFFFAangels\uFFFB \uFFF9is\uFFFAbe\u001e"); @@ -202,7 +200,7 @@ public class JuniperSearcherTestCase { } @Test - public void testThatIncompleteAnnotationWithHighlightAtTheBeginningIsIgnored() { + void testThatIncompleteAnnotationWithHighlightAtTheBeginningIsIgnored() { { Result check = createResult("\u001e\u001fIncomplete\uFFFAincomplete\uFFFB\u001f \uFFF9Original\uFFFAstemmed\uFFFB\u001e"); assertEquals(1, check.getHitCount()); @@ -221,7 +219,7 @@ public class JuniperSearcherTestCase { } @Test - public void testThatIncompleteAnnotationWithHighlightAtTheEndIsIgnored() { + void testThatIncompleteAnnotationWithHighlightAtTheEndIsIgnored() { { Result check = createResult("\u001e\uFFF9Original\uFFFAstemmed\uFFFB \u001f\uFFF9Incomplete\uFFFAincomplete\u001f\u001e"); assertEquals(1, check.getHitCount()); @@ -240,7 +238,7 @@ public class JuniperSearcherTestCase { } @Test - public void testExplicitTwoPhase() { + void testExplicitTwoPhase() { Chain<Searcher> searchChain = createSearchChain("one", "\u001e\uFFFAbe\uFFFB within the set of \u001f\uFFF9documents\uFFFAdocument\uFFFB\u001f. \uFFF9phrases\uFFFA\u001E\uFFFA\uFFFB to as a remedy). Each of the \u001fdocument\u001f \uFFF9fields\uFFFAfield\uFFFB in a catalog can be \uFFF9\u001e"); Query q = new Query("?query=12"); Result check = createExecution(searchChain).search(q); @@ -252,7 +250,7 @@ public class JuniperSearcherTestCase { } @Test - public void testCompoundWordsBolding() { + void testCompoundWordsBolding() { Result check = createResult("\u001eTest \u001fkommunikations\u001f\u001ffehler\u001f"); assertEquals(1, check.getHitCount()); assertEquals("<sep />Test <hi>kommunikationsfehler</hi>", check.hits().get(0).getField("dynteaser").toString()); diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/MultipleResultsTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/MultipleResultsTestCase.java index 0a250c9b973..0024bf9cd66 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/MultipleResultsTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/MultipleResultsTestCase.java @@ -11,10 +11,10 @@ import com.yahoo.search.result.Hit; import com.yahoo.search.result.HitGroup; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.searchchain.testutil.DocumentSourceSearcher; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Test of MultipleResultsSearcher @@ -30,7 +30,7 @@ public class MultipleResultsTestCase { private Chain<Searcher> chain; - @Before + @BeforeEach public void setUp() { docSource=new DocumentSourceSearcher(); searcher=new MultipleResultsSearcher(); @@ -38,11 +38,11 @@ public class MultipleResultsTestCase { } @Test - public void testRetrieveHeterogenousHits() { + void testRetrieveHeterogenousHits() { Query query = createQuery(); Result originalResult = new Result(query); - int n1 = 15, n2 = 25, n3 = 25, n4=25; + int n1 = 15, n2 = 25, n3 = 25, n4 = 25; addHits(originalResult, "others", n1); addHits(originalResult, "music", n2); addHits(originalResult, "movies", n3); @@ -51,23 +51,23 @@ public class MultipleResultsTestCase { docSource.addResult(query, originalResult); - query.setWindow(0,30); + query.setWindow(0, 30); Result result = new Execution(chain, Execution.Context.createContextStub()).search(query); - HitGroup musicGroup = (HitGroup)result.hits().get("music"); - HitGroup moviesGroup = (HitGroup)result.hits().get("movies"); + HitGroup musicGroup = (HitGroup) result.hits().get("music"); + HitGroup moviesGroup = (HitGroup) result.hits().get("movies"); - assertEquals( 15, musicGroup.size() ); - assertEquals( 15, moviesGroup.size() ); - assertEquals( 3, docSource.getQueryCount() ); + assertEquals(15, musicGroup.size()); + assertEquals(15, moviesGroup.size()); + assertEquals(3, docSource.getQueryCount()); } @Test - public void testRetrieveHitsForGroup() { + void testRetrieveHitsForGroup() { Query query = createQuery(); Result originalResult = new Result(query); - int n1 = 200, n2=30; + int n1 = 200, n2 = 30; addHits(originalResult, "music", n1, 1000); addHits(originalResult, "movies", n2, 100); originalResult.setTotalHitCount(n1 + n2); @@ -81,18 +81,18 @@ public class MultipleResultsTestCase { docSource.addResult(restrictedQuery, restrictedResult); - query.setWindow(0,30); + query.setWindow(0, 30); Result result = new Execution(chain, Execution.Context.createContextStub()).search(query); - HitGroup musicGroup = (HitGroup)result.hits().get("music"); - HitGroup moviesGroup = (HitGroup)result.hits().get("movies"); + HitGroup musicGroup = (HitGroup) result.hits().get("music"); + HitGroup moviesGroup = (HitGroup) result.hits().get("movies"); - assertEquals( 15, musicGroup.size()); - assertEquals( 15, moviesGroup.size()); + assertEquals(15, musicGroup.size()); + assertEquals(15, moviesGroup.size()); } @Test - public void testNoHitsForResultSet() { + void testNoHitsForResultSet() { Query query = createQuery(); Result originalResult = new Result(query); @@ -104,14 +104,14 @@ public class MultipleResultsTestCase { docSource.addResult(query, originalResult); - query.setWindow(0,30); + query.setWindow(0, 30); Result result = new Execution(chain, Execution.Context.createContextStub()).search(query); - HitGroup musicGroup = (HitGroup)result.hits().get("music"); - HitGroup moviesGroup = (HitGroup)result.hits().get("movies"); + HitGroup musicGroup = (HitGroup) result.hits().get("music"); + HitGroup moviesGroup = (HitGroup) result.hits().get("movies"); - assertEquals( 15, musicGroup.size()); - assertEquals( 0, moviesGroup.size()); + assertEquals(15, musicGroup.size()); + assertEquals(0, moviesGroup.size()); } private void addHits(Result result, String docName, int numHits, diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/PosSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/PosSearcherTestCase.java index 43911b33161..755a1c11d47 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/PosSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/PosSearcherTestCase.java @@ -10,12 +10,12 @@ import com.yahoo.search.Searcher; import com.yahoo.search.rendering.RendererRegistry; import com.yahoo.search.result.ErrorHit; import com.yahoo.search.searchchain.Execution; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests for the PosSearcher @@ -31,7 +31,7 @@ public class PosSearcherTestCase { * Tests basic lat/long input. */ @Test - public void testBasics() { + void testBasics() { Query q = new Query(); q.properties().set("pos.ll", "N0;E0"); doSearch(searcher, q, 0, 10); @@ -47,44 +47,44 @@ public class PosSearcherTestCase { * Tests basic bounding box input. */ @Test - public void testBoundingBox() { + void testBoundingBox() { Query q = new Query(); q.properties().set("pos.bb", "n=51.9,s=50.2,e=0.34,w=-10.01"); doSearch(searcher, q, 0, 10); assertEquals("[2,-10010000,50200000,340000,51900000]", - q.getRanking().getLocation().toString()); + q.getRanking().getLocation().toString()); q = new Query(); q.properties().set("pos.bb", "n=0,s=0,e=123.456789,w=-123.456789"); doSearch(searcher, q, 0, 10); assertEquals("[2,-123456789,0,123456789,0]", - q.getRanking().getLocation().toString()); + q.getRanking().getLocation().toString()); q = new Query(); q.properties().set("pos.bb", "n=12.345678,s=-12.345678,e=0,w=0"); doSearch(searcher, q, 0, 10); assertEquals("[2,0,-12345678,0,12345678]", - q.getRanking().getLocation().toString()); + q.getRanking().getLocation().toString()); q = new Query(); q.properties().set("pos.bb", "n=0.000001,s=-0.000001,e=0.000001,w=-0.000001"); doSearch(searcher, q, 0, 10); assertEquals("[2,-1,-1,1,1]", - q.getRanking().getLocation().toString()); + q.getRanking().getLocation().toString()); } /** * Tests basic bounding box input. */ @Test - public void testBoundingBoxAndRadius() { + void testBoundingBoxAndRadius() { Query q = new Query(); q.properties().set("pos.bb", "n=60.111,s=59.999,e=30.111,w=29.999"); q.properties().set("pos.ll", "N60;E30"); doSearch(searcher, q, 0, 10); assertEquals( "[2,29999000,59999000,30111000,60111000]" + - "(2,30000000,60000000,450668,0,1,0,2147483647)", + "(2,30000000,60000000,450668,0,1,0,2147483647)", q.getRanking().getLocation().toString()); } @@ -92,7 +92,7 @@ public class PosSearcherTestCase { * Tests different ways of specifying the radius. */ @Test - public void testRadiusUnits() { + void testRadiusUnits() { Query q = new Query(); q.properties().set("pos.ll", "N0;E0"); q.properties().set("pos.radius", "2km"); @@ -130,7 +130,7 @@ public class PosSearcherTestCase { * Tests xy position (internal format). */ @Test - public void testXY() { + void testXY() { Query q = new Query(); q.properties().set("pos.xy", "22500;22500"); doSearch(searcher, q, 0, 10); @@ -144,7 +144,7 @@ public class PosSearcherTestCase { } @Test - public void testNotOverridingOldStyleParameters() { + void testNotOverridingOldStyleParameters() { PosSearcher searcher = new PosSearcher(); Query q = new Query("?query=test&pos.ll=N10.15;E6.08&location=(2,-1100222,0,300,0,1,0,CalcLatLon)"); q.setTraceLevel(1); @@ -156,7 +156,7 @@ public class PosSearcherTestCase { * Tests input parameters that should report errors. */ @Test - public void testInvalidInput() { + void testInvalidInput() { PosSearcher searcher = new PosSearcher(); Result result; @@ -164,18 +164,18 @@ public class PosSearcherTestCase { q.properties().set("pos.ll", "NE74.14;E14.48"); result = doSearch(searcher, q, 0, 10); assertEquals("Error in pos parameters: Unable to parse lat/long string 'NE74.14;E14.48': already set direction once, cannot add direction: E", - ((ErrorHit)result.hits().get(0)).errors().iterator().next().getDetailedMessage()); + ((ErrorHit) result.hits().get(0)).errors().iterator().next().getDetailedMessage()); q = new Query(); q.properties().set("pos.ll", "NE74.14;E14.48"); q.properties().set("pos.xy", "82400, 72800"); result = doSearch(searcher, q, 0, 10); assertEquals("Error in pos parameters: Cannot handle both lat/long and xy coords at the same time", - ((ErrorHit)result.hits().get(0)).errors().iterator().next().getDetailedMessage()); + ((ErrorHit) result.hits().get(0)).errors().iterator().next().getDetailedMessage()); } @Test - public void testWrappingTheNorthPole() { + void testWrappingTheNorthPole() { Query q = new Query(); q.properties().set("pos.ll", "N89.9985365158;E122.163600102"); q.properties().set("pos.radius", "20mi"); diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuotingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuotingSearcherTestCase.java index 0b926f5e9b7..be297b5d6c3 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuotingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuotingSearcherTestCase.java @@ -15,14 +15,15 @@ import com.yahoo.search.result.Hit; import com.yahoo.search.result.Relevance; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.searchchain.testutil.DocumentSourceSearcher; -import org.junit.Test; +import org.junit.jupiter.api.Test; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -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; /** * Tests hit property quoting. @@ -38,10 +39,10 @@ public class QuotingSearcherTestCase { } @Test - public void testBasicQuoting() { + void testBasicQuoting() { Map<Searcher, Searcher> chained = new HashMap<>(); Searcher s = createQuotingSearcher("file:src/test/java/com/yahoo/prelude/" - + "searcher/test/testquoting.cfg"); + + "searcher/test/testquoting.cfg"); DocumentSourceSearcher docsource = new DocumentSourceSearcher(); chained.put(s, docsource); Query q = new Query("?query=a"); @@ -58,10 +59,10 @@ public class QuotingSearcherTestCase { } @Test - public void testBasicQuotingWithNoisyStrings() { + void testBasicQuotingWithNoisyStrings() { Map<Searcher, Searcher> chained = new HashMap<>(); Searcher s = createQuotingSearcher("file:src/test/java/com/yahoo/prelude/" - + "searcher/test/testquoting.cfg"); + + "searcher/test/testquoting.cfg"); DocumentSourceSearcher docsource = new DocumentSourceSearcher(); chained.put(s, docsource); Query q = new Query("?query=a"); @@ -78,10 +79,10 @@ public class QuotingSearcherTestCase { } @Test - public void testFieldQuotingWithNoisyStrings() { + void testFieldQuotingWithNoisyStrings() { Map<Searcher, Searcher> chained = new HashMap<>(); Searcher s = createQuotingSearcher("file:src/test/java/com/yahoo/prelude/" - + "searcher/test/testquoting.cfg"); + + "searcher/test/testquoting.cfg"); DocumentSourceSearcher docsource = new DocumentSourceSearcher(); chained.put(s, docsource); Query q = new Query("?query=a"); @@ -99,10 +100,10 @@ public class QuotingSearcherTestCase { @Test - public void testNoQuotingWithOtherTypes() { + void testNoQuotingWithOtherTypes() { Map<Searcher, Searcher> chained = new HashMap<>(); Searcher s = createQuotingSearcher("file:src/test/java/com/yahoo/prelude/" - + "searcher/test/testquoting.cfg"); + + "searcher/test/testquoting.cfg"); DocumentSourceSearcher docsource = new DocumentSourceSearcher(); chained.put(s, docsource); Query q = new Query("?query=a"); diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/ValidatePredicateSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/ValidatePredicateSearcherTestCase.java index 061c9bc5681..9375dc2a4b2 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/ValidatePredicateSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/ValidatePredicateSearcherTestCase.java @@ -17,10 +17,10 @@ import com.yahoo.search.rendering.RendererRegistry; import com.yahoo.search.result.ErrorMessage; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.yql.YqlParser; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; /** * @author Magnar Nedland @@ -28,7 +28,7 @@ import static org.junit.Assert.assertNull; public class ValidatePredicateSearcherTestCase { @Test - public void testValidQuery() { + void testValidQuery() { ValidatePredicateSearcher searcher = new ValidatePredicateSearcher(); String q = "select * from sources * where predicate(predicate_field,0,{\"age\":20L})"; Result r = doSearch(searcher, q, "predicate-bounds [0..99]"); @@ -36,7 +36,7 @@ public class ValidatePredicateSearcherTestCase { } @Test - public void testQueryOutOfBounds() { + void testQueryOutOfBounds() { ValidatePredicateSearcher searcher = new ValidatePredicateSearcher(); String q = "select * from sources * where predicate(predicate_field,0,{\"age\":200L})"; Result r = doSearch(searcher, q, "predicate-bounds [0..99]"); @@ -44,7 +44,7 @@ public class ValidatePredicateSearcherTestCase { } @Test - public void queryFailsWhenPredicateFieldIsUsedInTermSearch() { + void queryFailsWhenPredicateFieldIsUsedInTermSearch() { ValidatePredicateSearcher searcher = new ValidatePredicateSearcher(); String q = "select * from sources * where predicate_field CONTAINS \"true\""; Result r = doSearch(searcher, q, "predicate-bounds [0..99]"); diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/ValidateSortingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/ValidateSortingSearcherTestCase.java index 6b8c268f4ca..4090fbc5de3 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/ValidateSortingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/ValidateSortingSearcherTestCase.java @@ -12,13 +12,12 @@ import com.yahoo.search.config.ClusterConfig; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.test.QueryTestCase; import com.yahoo.vespa.config.search.AttributesConfig; -import org.junit.Test; +import org.junit.jupiter.api.Test; + import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; /** * Check sorting validation behaves OK. @@ -43,7 +42,7 @@ public class ValidateSortingSearcherTestCase { } @Test - public void testBasicValidation() { + void testBasicValidation() { assertNotNull(quoteAndTransform("+a -b +c")); assertNotNull(quoteAndTransform("+a")); assertNotNull(quoteAndTransform(null)); @@ -54,12 +53,12 @@ public class ValidateSortingSearcherTestCase { } @Test - public void testInvalidSpec() { + void testInvalidSpec() { assertNull(quoteAndTransform("+a -e +c")); } @Test - public void testConfigOverride() { + void testConfigOverride() { assertEquals("[ASCENDING:uca(title,en_US,TERTIARY)]", quoteAndTransform("title")); assertEquals("[ASCENDING:uca(title,en_US,TERTIARY)]", quoteAndTransform("uca(title)")); assertEquals("[ASCENDING:uca(title,en_US,TERTIARY)]", quoteAndTransform("+uca(title)")); @@ -67,7 +66,7 @@ public class ValidateSortingSearcherTestCase { } @Test - public void requireThatQueryLocaleIsDefault() { + void requireThatQueryLocaleIsDefault() { assertEquals("[ASCENDING:lowercase(a)]", quoteAndTransform("a")); assertEquals("[ASCENDING:uca(a,en_US,PRIMARY)]", transform("a", "en-US")); assertEquals("[ASCENDING:uca(a,en_NO,PRIMARY)]", transform("a", "en-NO")); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/parser/test/SemanticsParserTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/parser/test/SemanticsParserTestCase.java index bf99a709df3..3a366882475 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/parser/test/SemanticsParserTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/parser/test/SemanticsParserTestCase.java @@ -8,11 +8,9 @@ import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.prelude.semantics.RuleBase; import com.yahoo.prelude.semantics.RuleImporter; import com.yahoo.prelude.semantics.parser.ParseException; -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.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Tests parsing of semantic rules bases @@ -24,33 +22,33 @@ public class SemanticsParserTestCase { private final static String ROOT = "src/test/java/com/yahoo/prelude/semantics/parser/test/"; @Test - public void testRuleReading() throws java.io.IOException, ParseException { + void testRuleReading() throws java.io.IOException, ParseException { RuleBase rules = new RuleImporter(new SimpleLinguistics()).importFile(ROOT + "rules.sr"); Iterator<?> i = rules.ruleIterator(); assertEquals("[listing] [preposition] [place] -> listing:[listing] place:[place]!150", - i.next().toString()); + i.next().toString()); assertEquals("[listing] [place] +> place:[place]", - i.next().toString()); + i.next().toString()); assertEquals("[brand] -> brand:[brand]", - i.next().toString()); + i.next().toString()); assertEquals("[category] -> category:[category]", - i.next().toString()); + i.next().toString()); assertEquals("digital camera -> digicamera", - i.next().toString()); + i.next().toString()); assertEquals("(parameter.ranking='cat'), (parameter.ranking='cat0') -> one", i.next().toString()); assertFalse(i.hasNext()); i = rules.conditionIterator(); assertEquals("[listing] :- restaurant, shop, cafe, hotel", - i.next().toString()); + i.next().toString()); assertEquals("[preposition] :- in, at, near", - i.next().toString()); + i.next().toString()); assertEquals("[place] :- geary", - i.next().toString()); + i.next().toString()); assertEquals("[brand] :- sony, dell", - i.next().toString()); + i.next().toString()); assertEquals("[category] :- digital camera, camera, phone", - i.next().toString()); + i.next().toString()); assertFalse(i.hasNext()); assertTrue(rules.isDefault()); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/AlibabaTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/AlibabaTestCase.java index d1000e031da..8ff14011483 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/AlibabaTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/AlibabaTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test a case reported by Alibaba @@ -15,23 +15,23 @@ public class AlibabaTestCase extends RuleBaseAbstractTestCase { } @Test - public void testNumberReplacement() { - assertSemantics("AND nokia 3100","3100"); + void testNumberReplacement() { + assertSemantics("AND nokia 3100", "3100"); } @Test - public void testRuleFollowingNumber() { - assertSemantics("lenovo","legend"); + void testRuleFollowingNumber() { + assertSemantics("lenovo", "legend"); } @Test - public void testCombinedNumberAndRegular1() { - assertSemantics("AND lenovo nokia 3100","legend 3100"); + void testCombinedNumberAndRegular1() { + assertSemantics("AND lenovo nokia 3100", "legend 3100"); } @Test - public void testCombinedNumberAndRegular2() { - assertSemantics("AND nokia 3100 lenovo","3100 legend"); + void testCombinedNumberAndRegular2() { + assertSemantics("AND nokia 3100 lenovo", "3100 legend"); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/AnchorTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/AnchorTestCase.java index 9173053e660..dfba036efae 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/AnchorTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/AnchorTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests anchoring @@ -15,7 +15,7 @@ public class AnchorTestCase extends RuleBaseAbstractTestCase { } @Test - public void testSingleWordAnchoredBothSides() { + void testSingleWordAnchoredBothSides() { assertSemantics("anchor", "word"); assertSemantics("anchor", "anotherword"); assertSemantics("notthisword", "notthisword"); @@ -23,7 +23,7 @@ public class AnchorTestCase extends RuleBaseAbstractTestCase { } @Test - public void testMultiwordAnchored() { + void testMultiwordAnchored() { assertSemantics("anchor", "this is complete"); assertSemantics("AND this is complete toomuch", "this is complete toomuch"); assertSemantics("anchor", "a phrase"); @@ -31,28 +31,28 @@ public class AnchorTestCase extends RuleBaseAbstractTestCase { } @Test - public void testFirstAnchored() { - assertSemantics("anchor","first"); - assertSemantics("AND anchor andmore","first andmore"); - assertSemantics("AND before first","before first"); - assertSemantics("AND before first andmore","before first andmore"); + void testFirstAnchored() { + assertSemantics("anchor", "first"); + assertSemantics("AND anchor andmore", "first andmore"); + assertSemantics("AND before first", "before first"); + assertSemantics("AND before first andmore", "before first andmore"); } @Test - public void testLastAnchored() { - assertSemantics("anchor","last"); - assertSemantics("AND andmore anchor","andmore last"); - assertSemantics("AND last after","last after"); - assertSemantics("AND andmore last after","andmore last after"); + void testLastAnchored() { + assertSemantics("anchor", "last"); + assertSemantics("AND andmore anchor", "andmore last"); + assertSemantics("AND last after", "last after"); + assertSemantics("AND andmore last after", "andmore last after"); } @Test - public void testFirstAndLastAnchored() { - assertSemantics("AND anchor anchor","first last"); - assertSemantics("AND last first","last first"); - assertSemantics("AND anchor between anchor","first between last"); - assertSemantics("AND anchor last after","first last after"); - assertSemantics("AND before first anchor","before first last"); + void testFirstAndLastAnchored() { + assertSemantics("AND anchor anchor", "first last"); + assertSemantics("AND last first", "last first"); + assertSemantics("AND anchor between anchor", "first between last"); + assertSemantics("AND anchor last after", "first last after"); + assertSemantics("AND before first anchor", "before first last"); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/AutomataNotTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/AutomataNotTestCase.java index 4493038fc86..b138ba50ca9 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/AutomataNotTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/AutomataNotTestCase.java @@ -1,8 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; /** * Tests that ![a] is interpreted as "default:![a]", not as "!default:[a]", @@ -16,9 +16,10 @@ public class AutomataNotTestCase extends RuleBaseAbstractTestCase { super("automatanot.sr", "semantics.fsa"); } + // TODO: MAKE THIS WORK! @Test - @Ignore // TODO: MAKE THIS WORK! - public void testAutomataNot() { + @Disabled + void testAutomataNot() { if (System.currentTimeMillis() > 0) return; assertSemantics("carpenter", "carpenter"); assertSemantics("RANK brukbar busname:brukbar", "brukbar"); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/AutomataTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/AutomataTestCase.java index 71e36e45acc..a9c7202f7cd 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/AutomataTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/AutomataTestCase.java @@ -3,11 +3,11 @@ package com.yahoo.prelude.semantics.test; import com.yahoo.search.Query; import com.yahoo.prelude.semantics.RuleBase; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; -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; /** * Tests rule bases using automatas for matching @@ -23,62 +23,63 @@ public class AutomataTestCase extends RuleBaseAbstractTestCase { } @Test - public void testAutomataRuleBase() { - RuleBase ruleBase=searcher.getDefaultRuleBase(); - assertEquals(RuleBase.class,ruleBase.getClass()); + void testAutomataRuleBase() { + RuleBase ruleBase = searcher.getDefaultRuleBase(); + assertEquals(RuleBase.class, ruleBase.getClass()); assertTrue(ruleBase.getSource().endsWith(root + "automatarules.sr")); - assertEquals(root + "semantics.fsa",ruleBase.getAutomataFile()); + assertEquals(root + "semantics.fsa", ruleBase.getAutomataFile()); - Query query=new Query("?query=sony+digital+camera"); - ruleBase.analyze(query,0); + Query query = new Query("?query=sony+digital+camera"); + ruleBase.analyze(query, 0); assertEquals("RANK (WEAKAND(100) sony digital camera) dsp1:sony dsp5:digicamera", query.getModel().getQueryTree().getRoot().toString()); - query=new Query("?query=sony+digital+camera&rules.reload"); - ruleBase=searcher.getDefaultRuleBase(); + query = new Query("?query=sony+digital+camera&rules.reload"); + ruleBase = searcher.getDefaultRuleBase(); assertTrue(ruleBase.getSource().endsWith(root + "automatarules.sr")); - assertEquals(root + "semantics.fsa",ruleBase.getAutomataFile()); - ruleBase.analyze(query,0); + assertEquals(root + "semantics.fsa", ruleBase.getAutomataFile()); + ruleBase.analyze(query, 0); assertEquals("RANK (WEAKAND(100) sony digital camera) dsp1:sony dsp5:digicamera", query.getModel().getQueryTree().getRoot().toString()); } @Test - public void testAutomataSingleQuery() { - assertSemantics("RANK sony dsp1:sony","sony"); + void testAutomataSingleQuery() { + assertSemantics("RANK sony dsp1:sony", "sony"); } @Test - public void testAutomataFilterIsIgnored() { - assertSemantics("RANK sony |something dsp1:sony","sony&filter=something"); - assertSemantics("RANK something |sony","something&filter=sony"); + void testAutomataFilterIsIgnored() { + assertSemantics("RANK sony |something dsp1:sony", "sony&filter=something"); + assertSemantics("RANK something |sony", "something&filter=sony"); } @Test - public void testAutomataPluralMatches() { - assertSemantics("RANK sonys dsp1:sony","sonys"); + void testAutomataPluralMatches() { + assertSemantics("RANK sonys dsp1:sony", "sonys"); - assertSemantics("RANK (AND car cleaner) dsp1:\"car cleaners\" dsp5:\"car cleaners\"","car cleaner"); + assertSemantics("RANK (AND car cleaner) dsp1:\"car cleaners\" dsp5:\"car cleaners\"", "car cleaner"); - assertSemantics("RANK (AND sony digitals cameras) dsp1:sony dsp5:digicamera","sony digitals cameras"); + assertSemantics("RANK (AND sony digitals cameras) dsp1:sony dsp5:digicamera", "sony digitals cameras"); } @Test - public void testMatchingMultipleAutomataConditionsSingleWord() { - assertSemantics("RANK carpenter dsp1:carpenter dsp5:carpenter","carpenter"); + void testMatchingMultipleAutomataConditionsSingleWord() { + assertSemantics("RANK carpenter dsp1:carpenter dsp5:carpenter", "carpenter"); } @Test - public void testMatchingMultipleAutomataConditionsPhrase() { - assertSemantics("RANK (AND car cleaners) dsp1:\"car cleaners\" dsp5:\"car cleaners\"","car cleaners"); + void testMatchingMultipleAutomataConditionsPhrase() { + assertSemantics("RANK (AND car cleaners) dsp1:\"car cleaners\" dsp5:\"car cleaners\"", "car cleaners"); } + // TODO: Make this work again @Test - @Ignore // TODO: Make this work again - public void testReplaceOnNoMatch() { - assertSemantics("nomatch:sonny","sonny&donomatch"); - assertSemantics("RANK sony dsp1:sony","sony&donomatch"); - assertSemantics("RANK sonys dsp1:sony","sonys&donomatch"); - assertSemantics("AND nomatch:sonny nomatch:boy","sonny boy&donomatch"); - assertSemantics("RANK (AND sony nomatch:boy) dsp1:sony","sony boy&donomatch"); + @Disabled + void testReplaceOnNoMatch() { + assertSemantics("nomatch:sonny", "sonny&donomatch"); + assertSemantics("RANK sony dsp1:sony", "sony&donomatch"); + assertSemantics("RANK sonys dsp1:sony", "sonys&donomatch"); + assertSemantics("AND nomatch:sonny nomatch:boy", "sonny boy&donomatch"); + assertSemantics("RANK (AND sony nomatch:boy) dsp1:sony", "sony boy&donomatch"); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/BacktrackingTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/BacktrackingTestCase.java index 06f7112f851..3a4f0344994 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/BacktrackingTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/BacktrackingTestCase.java @@ -5,6 +5,8 @@ import java.util.ArrayList; import java.util.List; import com.yahoo.component.chain.Chain; + +import static org.junit.jupiter.api.Assertions.assertEquals; import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.search.Query; import com.yahoo.prelude.semantics.RuleImporter; @@ -14,9 +16,7 @@ import com.yahoo.search.Searcher; import com.yahoo.search.rendering.RendererRegistry; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.test.QueryTestCase; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; /** * @author bratseth @@ -50,47 +50,47 @@ public class BacktrackingTestCase { // Literal terms --------------- @Test - public void testMultilevelBacktrackingLiteralTerms() { - assertSemantics("WEAKAND(100) replaced","word1 word2 word5 word8"); + void testMultilevelBacktrackingLiteralTerms() { + assertSemantics("WEAKAND(100) replaced", "word1 word2 word5 word8"); } @Test - public void testMultilevelBacktrackingWontReorderOthertermsLiteralTerms() { - assertSemantics("WEAKAND(100) other1 other2 other3 replaced","other1 other2 other3 word1 word2 word5 word8"); + void testMultilevelBacktrackingWontReorderOthertermsLiteralTerms() { + assertSemantics("WEAKAND(100) other1 other2 other3 replaced", "other1 other2 other3 word1 word2 word5 word8"); } @Test - public void testMultilevelBacktrackingWithMulticompoundMatchLiteralTerms() { - assertSemantics("WEAKAND(100) other1 other2 other3 replaced","other1 other2 other3 word1 word2 word5-word8"); + void testMultilevelBacktrackingWithMulticompoundMatchLiteralTerms() { + assertSemantics("WEAKAND(100) other1 other2 other3 replaced", "other1 other2 other3 word1 word2 word5-word8"); } @Test - public void testMultilevelBacktrackingPreservePartialMatchBeforeLiteralTerms() { - assertSemantics("WEAKAND(100) word1 word2 word5 replaced","word1 word2 word5 word1 word2 word5 word8"); + void testMultilevelBacktrackingPreservePartialMatchBeforeLiteralTerms() { + assertSemantics("WEAKAND(100) word1 word2 word5 replaced", "word1 word2 word5 word1 word2 word5 word8"); } @Test - public void testMultilevelBacktrackingPreservePartialMatchAfterLiteralTerms() { - assertSemantics("WEAKAND(100) replaced word1 word2 word5","word1 word2 word5 word8 word1 word2 word5 "); + void testMultilevelBacktrackingPreservePartialMatchAfterLiteralTerms() { + assertSemantics("WEAKAND(100) replaced word1 word2 word5", "word1 word2 word5 word8 word1 word2 word5 "); } // reference terms --------------- @Test - public void testMultilevelBacktrackingReferenceTerms() { - assertSemantics("WEAKAND(100) ref:ref1 ref:ref2 ref:ref5 ref:ref8","ref1 ref2 ref5 ref8"); + void testMultilevelBacktrackingReferenceTerms() { + assertSemantics("WEAKAND(100) ref:ref1 ref:ref2 ref:ref5 ref:ref8", "ref1 ref2 ref5 ref8"); } @Test - public void testMultilevelBacktrackingPreservePartialMatchBeforeReferenceTerms() { + void testMultilevelBacktrackingPreservePartialMatchBeforeReferenceTerms() { assertSemantics("WEAKAND(100) ref1 ref2 ref5 ref:ref1 ref:ref2 ref:ref5 ref:ref8", - "ref1 ref2 ref5 ref1 ref2 ref5 ref8"); + "ref1 ref2 ref5 ref1 ref2 ref5 ref8"); } @Test - public void testMultilevelBacktrackingPreservePartialMatchAfterReferenceTerms() { + void testMultilevelBacktrackingPreservePartialMatchAfterReferenceTerms() { assertSemantics("WEAKAND(100) ref:ref1 ref:ref2 ref:ref5 ref:ref8 ref1 ref2 ref5", - "ref1 ref2 ref5 ref8 ref1 ref2 ref5"); + "ref1 ref2 ref5 ref8 ref1 ref2 ref5"); } private Result doSearch(Searcher searcher, Query query, int offset, int hits) { diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/BlendingTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/BlendingTestCase.java index 9e590698f4a..334ff8d05a6 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/BlendingTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/BlendingTestCase.java @@ -2,9 +2,9 @@ package com.yahoo.prelude.semantics.test; import com.yahoo.search.Query; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests blending rules @@ -19,9 +19,9 @@ public class BlendingTestCase extends RuleBaseAbstractTestCase { /** Tests parameter literal matching */ @Test - public void testLiteralEquals() { - assertParameterSemantics("AND a sun came cd","a sun came cd","search","[music]"); - assertParameterSemantics("AND driving audi","driving audi","search","[cars]"); + void testLiteralEquals() { + assertParameterSemantics("AND a sun came cd", "a sun came cd", "search", "[music]"); + assertParameterSemantics("AND driving audi", "driving audi", "search", "[cars]"); //assertParameterSemantics("AND audi music quality","audi music quality","search","carstereos",1); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/CJKTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/CJKTestCase.java index 0aaa5f2cea7..457a2063173 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/CJKTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/CJKTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests that using rule bases containing cjk characters work @@ -15,14 +15,14 @@ public class CJKTestCase extends RuleBaseAbstractTestCase { } @Test - public void testIt() { - assertSemantics("\u7d22a","a\u7d22"); - assertSemantics("\u7d22a","\u7d22a"); - assertSemantics("brand:\u7d22\u5c3c","\u7d22\u5c3c"); - assertSemantics("brand:\u60e0\u666e","\u60e0\u666e"); - assertSemantics("brand:\u4f73\u80fd","\u4f73\u80fd"); - assertSemantics("AND brand:\u4f73\u80fd \u7d22a","\u4f73\u80fd a\u7d22"); - assertSemantics("\u4f73\u80fd\u7d22\u5c3c","\u4f73\u80fd\u7d22\u5c3c"); + void testIt() { + assertSemantics("\u7d22a", "a\u7d22"); + assertSemantics("\u7d22a", "\u7d22a"); + assertSemantics("brand:\u7d22\u5c3c", "\u7d22\u5c3c"); + assertSemantics("brand:\u60e0\u666e", "\u60e0\u666e"); + assertSemantics("brand:\u4f73\u80fd", "\u4f73\u80fd"); + assertSemantics("AND brand:\u4f73\u80fd \u7d22a", "\u4f73\u80fd a\u7d22"); + assertSemantics("\u4f73\u80fd\u7d22\u5c3c", "\u4f73\u80fd\u7d22\u5c3c"); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonTestCase.java index 988d69a55d3..0c5447c120a 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author bratseth @@ -17,30 +17,30 @@ public class ComparisonTestCase extends RuleBaseAbstractTestCase { * different conditions (coffee, island) */ @Test - public void testNamedConditionReturnComparison() { + void testNamedConditionReturnComparison() { // Not sufficient that both conditions are matched - assertSemantics("AND borneo arabica island:borneo coffee:arabica","borneo arabica"); + assertSemantics("AND borneo arabica island:borneo coffee:arabica", "borneo arabica"); // They must match the same word - assertSemantics("AND java noise island:java coffee:java control:ambigous off","java noise"); + assertSemantics("AND java noise island:java coffee:java control:ambigous off", "java noise"); // Works also when there are other, not-equal matches assertSemantics("AND borneo arabica java island:borneo island:java coffee:arabica coffee:java control:ambigous off", - "borneo arabica java"); + "borneo arabica java"); } @Test - public void testContainsAsSubstring() { - assertSemantics("AND java island:java coffee:java control:ambigous off","java"); - assertSemantics("AND kanava island:kanava off","kanava"); - assertSemantics("AND borneo island:borneo","borneo"); + void testContainsAsSubstring() { + assertSemantics("AND java island:java coffee:java control:ambigous off", "java"); + assertSemantics("AND kanava island:kanava off", "kanava"); + assertSemantics("AND borneo island:borneo", "borneo"); } @Test - public void testAlphanumericComparison() { - assertSemantics("a","a"); - assertSemantics("AND z highletter","z"); - assertSemantics("AND p highletter","p"); + void testAlphanumericComparison() { + assertSemantics("a", "a"); + assertSemantics("AND z highletter", "z"); + assertSemantics("AND p highletter", "p"); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonsTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonsTestCase.java index a8fe78ac1ff..867a57aebeb 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonsTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonsTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author bratseth @@ -13,11 +13,11 @@ public class ComparisonsTestCase extends RuleBaseAbstractTestCase { } @Test - public void testLiteralEquals() { - assertSemantics("a","a"); - assertSemantics("RANK a foo:a","a&ranking=category"); - assertSemantics("a","a&ranking=somethingelse"); - assertSemantics("a","a&otherparam=category"); + void testLiteralEquals() { + assertSemantics("a", "a"); + assertSemantics("RANK a foo:a", "a&ranking=category"); + assertSemantics("a", "a&ranking=somethingelse"); + assertSemantics("a", "a&otherparam=category"); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConditionTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConditionTestCase.java index 17eb4120b84..d7297bd79a4 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConditionTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConditionTestCase.java @@ -14,10 +14,10 @@ import com.yahoo.prelude.semantics.rule.ProductionRule; import com.yahoo.prelude.semantics.rule.ReplacingProductionRule; import com.yahoo.prelude.semantics.rule.SequenceCondition; import com.yahoo.prelude.semantics.rule.TermCondition; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author bratseth @@ -25,7 +25,7 @@ import static org.junit.Assert.assertTrue; public class ConditionTestCase { @Test - public void testTermCondition() { + void testTermCondition() { var linguistics = new RuleBaseLinguistics(new SimpleLinguistics()); TermCondition term = new TermCondition("foo", linguistics); Query query = new Query("?query=foo"); @@ -33,23 +33,23 @@ public class ConditionTestCase { } @Test - public void testSequenceCondition() { + void testSequenceCondition() { var linguistics = new RuleBaseLinguistics(new SimpleLinguistics()); TermCondition term1 = new TermCondition("foo", linguistics); - TermCondition term2 = new TermCondition("bar",linguistics); + TermCondition term2 = new TermCondition("bar", linguistics); SequenceCondition sequence = new SequenceCondition(); sequence.addCondition(term1); sequence.addCondition(term2); Query query = new Query("?query=foo+bar"); - assertTrue(query + " matches " + sequence,sequence.matches(new Evaluation(query, null).freshRuleEvaluation())); + assertTrue(sequence.matches(new Evaluation(query, null).freshRuleEvaluation()), query + " matches " + sequence); Query query2 = new Query("?query=foo"); - assertFalse(query2 + " does not match " + sequence,sequence.matches(new Evaluation(query2, null).freshRuleEvaluation())); + assertFalse(sequence.matches(new Evaluation(query2, null).freshRuleEvaluation()), query2 + " does not match " + sequence); Query query3 = new Query("?query=bar"); - assertFalse(query3 + " does not match " + sequence,sequence.matches(new Evaluation(query3, null).freshRuleEvaluation())); + assertFalse(sequence.matches(new Evaluation(query3, null).freshRuleEvaluation()), query3 + " does not match " + sequence); } @Test - public void testChoiceCondition() { + void testChoiceCondition() { var linguistics = new RuleBaseLinguistics(new SimpleLinguistics()); TermCondition term1 = new TermCondition("foo", linguistics); TermCondition term2 = new TermCondition("bar", linguistics); @@ -57,18 +57,18 @@ public class ConditionTestCase { choice.addCondition(term1); choice.addCondition(term2); Query query1 = new Query("?query=foo+bar"); - assertTrue(query1 + " matches " + choice, choice.matches(new Evaluation(query1, null).freshRuleEvaluation())); + assertTrue(choice.matches(new Evaluation(query1, null).freshRuleEvaluation()), query1 + " matches " + choice); Query query2 = new Query("?query=foo"); - assertTrue(query2 + " matches " + choice, choice.matches(new Evaluation(query2, null).freshRuleEvaluation())); + assertTrue(choice.matches(new Evaluation(query2, null).freshRuleEvaluation()), query2 + " matches " + choice); Query query3 = new Query("?query=bar"); - assertTrue(query3 + " matches " + choice, choice.matches(new Evaluation(query3, null).freshRuleEvaluation())); + assertTrue(choice.matches(new Evaluation(query3, null).freshRuleEvaluation()), query3 + " matches " + choice); } @Test - public void testNamedConditionReference() { + void testNamedConditionReference() { var linguistics = new RuleBaseLinguistics(new SimpleLinguistics()); TermCondition term = new TermCondition("foo", linguistics); - NamedCondition named = new NamedCondition("cond",term); + NamedCondition named = new NamedCondition("cond", term); ConditionReference reference = new ConditionReference("cond"); // To initialize the condition reference... @@ -81,7 +81,7 @@ public class ConditionTestCase { ruleBase.initialize(); Query query = new Query("?query=foo"); - assertTrue(query + " matches " + reference,reference.matches(new Evaluation(query, null).freshRuleEvaluation())); + assertTrue(reference.matches(new Evaluation(query, null).freshRuleEvaluation()), query + " matches " + reference); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConfigurationTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConfigurationTestCase.java index 7d9ea07339f..569ae569f18 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConfigurationTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConfigurationTestCase.java @@ -13,13 +13,12 @@ import com.yahoo.search.Result; import com.yahoo.search.Searcher; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.test.QueryTestCase; -import org.junit.Test; +import org.junit.jupiter.api.Test; + import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; /** * Tests creating a set of rule bases (the same set as in inheritingrules) from config @@ -52,7 +51,7 @@ public class ConfigurationTestCase { } @Test - public void testReadingConfigurationRuleBase() { + void testReadingConfigurationRuleBase() { RuleBase parent = searcher.getRuleBase("parent"); assertNotNull(parent); assertEquals("parent", parent.getName()); @@ -60,7 +59,7 @@ public class ConfigurationTestCase { } @Test - public void testParent() { + void testParent() { assertSemantics("WEAKAND(100) vehiclebrand:audi", "audi cars", "parent"); assertSemantics("WEAKAND(100) vehiclebrand:alfa", "alfa bus", "parent"); assertSemantics("AND (WEAKAND(100) vehiclebrand:bmw) expensivetv", "bmw motorcycle", "parent.sr"); @@ -69,7 +68,7 @@ public class ConfigurationTestCase { } @Test - public void testChild1() { + void testChild1() { assertSemantics("WEAKAND(100) vehiclebrand:skoda", "audi cars", "child1.sr"); assertSemantics("WEAKAND(100) vehiclebrand:alfa", "alfa bus", "child1"); assertSemantics("AND (WEAKAND(100) vehiclebrand:bmw) expensivetv", "bmw motorcycle", "child1"); @@ -78,7 +77,7 @@ public class ConfigurationTestCase { } @Test - public void testChild2() { + void testChild2() { assertSemantics("WEAKAND(100) vehiclebrand:audi", "audi cars", "child2"); assertSemantics("WEAKAND(100) vehiclebrand:alfa", "alfa bus", "child2.sr"); assertSemantics("AND (WEAKAND(100) vehiclebrand:bmw) expensivetv", "bmw motorcycle", "child2.sr"); @@ -87,7 +86,7 @@ public class ConfigurationTestCase { } @Test - public void testGrandchild() { + void testGrandchild() { assertSemantics("WEAKAND(100) vehiclebrand:skoda", "audi cars", "grandchild.sr"); assertSemantics("WEAKAND(100) vehiclebrand:alfa", "alfa bus", "grandchild"); assertSemantics("AND (WEAKAND(100) vehiclebrand:bmw) expensivetv", "bmw motorcycle", "grandchild"); @@ -96,7 +95,7 @@ public class ConfigurationTestCase { } @Test - public void testSearcher() { + void testSearcher() { assertSemantics("WEAKAND(100) vehiclebrand:skoda", "vw cars", "grandchild"); assertSemantics("WEAKAND(100) vehiclebrand:skoda", "vw cars", "grandchild.sd"); try { @@ -110,14 +109,14 @@ public class ConfigurationTestCase { assertSemanticsRulesOff("WEAKAND(100) vw cars", "vw cars"); assertSemantics("WEAKAND(100) vw car", "vw cars", "child2"); - assertSemantics("WEAKAND(100) vehiclebrand:skoda","skoda cars","child2"); + assertSemantics("WEAKAND(100) vehiclebrand:skoda", "skoda cars", "child2"); - assertSemantics("WEAKAND(100) vehiclebrand:skoda","audi cars", "child1"); - assertSemantics("WEAKAND(100) vehiclebrand:skoda","vw cars", "child1"); - assertSemantics("WEAKAND(100) skoda car", "skoda cars","child1"); + assertSemantics("WEAKAND(100) vehiclebrand:skoda", "audi cars", "child1"); + assertSemantics("WEAKAND(100) vehiclebrand:skoda", "vw cars", "child1"); + assertSemantics("WEAKAND(100) skoda car", "skoda cars", "child1"); assertSemantics("WEAKAND(100) vw car", "vw cars", "parent"); - assertSemantics("WEAKAND(100) skoda car", "skoda cars","parent"); + assertSemantics("WEAKAND(100) skoda car", "skoda cars", "parent"); } private Result doSearch(Searcher searcher, Query query, int offset, int hits) { diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/DuplicateRuleTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/DuplicateRuleTestCase.java index 76c8c3966b7..a692217fef6 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/DuplicateRuleTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/DuplicateRuleTestCase.java @@ -5,10 +5,10 @@ import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.prelude.semantics.RuleBaseException; import com.yahoo.prelude.semantics.RuleImporter; import com.yahoo.prelude.semantics.parser.ParseException; -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 bratseth @@ -18,7 +18,7 @@ public class DuplicateRuleTestCase { private final String root = "src/test/java/com/yahoo/prelude/semantics/test/rulebases/"; @Test - public void testDuplicateRuleBaseLoading() throws java.io.IOException, ParseException { + void testDuplicateRuleBaseLoading() throws java.io.IOException, ParseException { if (System.currentTimeMillis() > 0) return; // TODO: Include this test... try { diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/Ellipsis2TestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/Ellipsis2TestCase.java index 28ffe549711..0808092da65 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/Ellipsis2TestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/Ellipsis2TestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * tersts the ellipsis rule base @@ -15,8 +15,8 @@ public class Ellipsis2TestCase extends RuleBaseAbstractTestCase { } @Test - public void testUnreferencedEllipsis() { - assertSemantics("AND a b c someindex:\"a b c\"","a b c"); + void testUnreferencedEllipsis() { + assertSemantics("AND a b c someindex:\"a b c\"", "a b c"); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/EllipsisTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/EllipsisTestCase.java index 1c570220f52..d1fe2091bc2 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/EllipsisTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/EllipsisTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * tersts the ellipsis rule base @@ -15,34 +15,34 @@ public class EllipsisTestCase extends RuleBaseAbstractTestCase { } @Test - public void testUnreferencedEllipsis() { - assertSemantics("AND why is stench unpleasant about:stench","why is stench unpleasant"); - assertSemantics("AND why is the sky blue about:\"the sky\"","why is the sky blue"); + void testUnreferencedEllipsis() { + assertSemantics("AND why is stench unpleasant about:stench", "why is stench unpleasant"); + assertSemantics("AND why is the sky blue about:\"the sky\"", "why is the sky blue"); assertSemantics("AND why is aardwark almost always most relevant in dictionaries about:aardwark", - "why is aardwark almost always most relevant in dictionaries"); + "why is aardwark almost always most relevant in dictionaries"); } @Test - public void testReferencedEllipsis() { - assertSemantics("album:parade","parade album"); - assertSemantics("album:\"a sun came\"","a sun came album"); - assertSemantics("album:parade","parade cd"); - assertSemantics("album:\"a sun came\"","a sun came cd"); + void testReferencedEllipsis() { + assertSemantics("album:parade", "parade album"); + assertSemantics("album:\"a sun came\"", "a sun came album"); + assertSemantics("album:parade", "parade cd"); + assertSemantics("album:\"a sun came\"", "a sun came cd"); } @Test - public void testEllipsisInNamedCondition() { - assertSemantics("AND name:\"a sun came\" product:video","buy a sun came"); - assertSemantics("AND name:stalker product:video","buy stalker video"); - assertSemantics("AND name:\"the usual suspects\" product:video","buy the usual suspects video"); + void testEllipsisInNamedCondition() { + assertSemantics("AND name:\"a sun came\" product:video", "buy a sun came"); + assertSemantics("AND name:stalker product:video", "buy stalker video"); + assertSemantics("AND name:\"the usual suspects\" product:video", "buy the usual suspects video"); } @Test - public void testMultipleEllipsis() { - assertSemantics("AND from:paris to:texas","from paris to texas"); - assertSemantics("AND from:\"sao paulo\" to:\"real madrid\"","from sao paulo to real madrid"); - assertSemantics("AND from:\"from from\" to:oslo","from from from to oslo"); - assertSemantics("AND from:\"from from to\" to:koko","from from from to to koko"); // Matching is greedy left-right + void testMultipleEllipsis() { + assertSemantics("AND from:paris to:texas", "from paris to texas"); + assertSemantics("AND from:\"sao paulo\" to:\"real madrid\"", "from sao paulo to real madrid"); + assertSemantics("AND from:\"from from\" to:oslo", "from from from to oslo"); + assertSemantics("AND from:\"from from to\" to:koko", "from from from to to koko"); // Matching is greedy left-right } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExactMatchTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExactMatchTestCase.java index 8f9c33dab51..d04ea0eabf9 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExactMatchTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExactMatchTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author bratseth @@ -13,8 +13,8 @@ public class ExactMatchTestCase extends RuleBaseAbstractTestCase { } @Test - public void testCompleteMatch() { - assertSemantics("AND primetime in no time","primetime notime"); + void testCompleteMatch() { + assertSemantics("AND primetime in no time", "primetime notime"); } /* diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExactMatchTrickTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExactMatchTrickTestCase.java index c566b05405d..6ca055ff980 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExactMatchTrickTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExactMatchTrickTestCase.java @@ -3,7 +3,7 @@ package com.yahoo.prelude.semantics.test; import com.yahoo.search.Query; import com.yahoo.search.test.QueryTestCase; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author bratseth @@ -15,20 +15,20 @@ public class ExactMatchTrickTestCase extends RuleBaseAbstractTestCase { } @Test - public void testCompleteMatch() { + void testCompleteMatch() { assertSemantics("AND default:primetime default:in default:no default:time", "primetime notime"); } @Test - public void testCompleteMatchWithNegative() { // Notice ordering bug + void testCompleteMatchWithNegative() { // Notice ordering bug assertSemantics("+(AND default:primetime default:in default:time default:no TRUE) -regionexcl:us", - new Query(QueryTestCase.httpEncode("?query=primetime ANDNOT regionexcl:us&type=adv"))); + new Query(QueryTestCase.httpEncode("?query=primetime ANDNOT regionexcl:us&type=adv"))); } @Test - public void testCompleteMatchWithFilterAndNegative() { + void testCompleteMatchWithFilterAndNegative() { assertSemantics("AND (+(AND default:primetime default:in default:time default:no TRUE) -regionexcl:us) |lang:en", - new Query(QueryTestCase.httpEncode("?query=primetime ANDNOT regionexcl:us&type=adv&filter=+lang:en"))); + new Query(QueryTestCase.httpEncode("?query=primetime ANDNOT regionexcl:us&type=adv&filter=+lang:en"))); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExpansionTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExpansionTestCase.java index 111f37bf8e4..13b65716ffc 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExpansionTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExpansionTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ExpansionTestCase extends RuleBaseAbstractTestCase { @@ -10,24 +10,24 @@ public class ExpansionTestCase extends RuleBaseAbstractTestCase { } @Test - public void testOrExpansion() { + void testOrExpansion() { assertSemantics("OR or1 or2 or3", "or1"); } @Test - public void testEquivExpansion1() { + void testEquivExpansion1() { assertSemantics("EQUIV equiv1 equiv2 equiv3", "equiv1"); } @Test - public void testEquivExpansion2() { + void testEquivExpansion2() { assertSemantics("EQUIV testfield:e1 testfield:e2 testfield:e3", "testfield:foo"); } @Test - public void testEquivExpansion3() { + void testEquivExpansion3() { assertSemantics("AND testfield:e1 testfield:e2 testfield:e3 testfield:e1 testfield:e2 testfield:e3", - "testfield:foo testfield:bar"); + "testfield:foo testfield:bar"); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/InheritanceTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/InheritanceTestCase.java index baec0066fb3..e9fa8dfa4be 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/InheritanceTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/InheritanceTestCase.java @@ -15,12 +15,9 @@ import com.yahoo.search.Result; import com.yahoo.search.Searcher; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.test.QueryTestCase; -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.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; /** * @author bratseth @@ -58,7 +55,7 @@ public class InheritanceTestCase { } @Test - public void testInclusion() { + void testInclusion() { assertTrue(grandchild.includes("child1")); assertTrue(grandchild.includes("child2")); assertTrue(grandchild.includes("parent")); @@ -74,8 +71,8 @@ public class InheritanceTestCase { } @Test - public void testInclusionOrderAndContentDump() { - StringTokenizer lines = new StringTokenizer(grandchild.toContentString(),"\n",false); + void testInclusionOrderAndContentDump() { + StringTokenizer lines = new StringTokenizer(grandchild.toContentString(), "\n", false); assertEquals("vw -> audi", lines.nextToken()); assertEquals("car -> car", lines.nextToken()); assertEquals("[brand] [vehicle] -> vehiclebrand:[brand]", lines.nextToken()); @@ -88,7 +85,7 @@ public class InheritanceTestCase { } @Test - public void testParent() { + void testParent() { assertSemantics("WEAKAND(100) vehiclebrand:audi", "audi cars", parent); assertSemantics("WEAKAND(100) vehiclebrand:alfa", "alfa bus", parent); assertSemantics("AND (WEAKAND(100) vehiclebrand:bmw) expensivetv", "bmw motorcycle", parent); @@ -97,7 +94,7 @@ public class InheritanceTestCase { } @Test - public void testChild1() { + void testChild1() { assertSemantics("WEAKAND(100) vehiclebrand:skoda", "audi cars", child1); assertSemantics("WEAKAND(100) vehiclebrand:alfa", "alfa bus", child1); assertSemantics("AND (WEAKAND(100) vehiclebrand:bmw) expensivetv", "bmw motorcycle", child1); @@ -106,25 +103,25 @@ public class InheritanceTestCase { } @Test - public void testChild2() { - assertSemantics("WEAKAND(100) vehiclebrand:audi","audi cars", child2); - assertSemantics("WEAKAND(100) vehiclebrand:alfa","alfa bus", child2); - assertSemantics("AND (WEAKAND(100) vehiclebrand:bmw) expensivetv","bmw motorcycle", child2); - assertSemantics("WEAKAND(100) vw car","vw cars", child2); - assertSemantics("WEAKAND(100) vehiclebrand:skoda","skoda cars", child2); + void testChild2() { + assertSemantics("WEAKAND(100) vehiclebrand:audi", "audi cars", child2); + assertSemantics("WEAKAND(100) vehiclebrand:alfa", "alfa bus", child2); + assertSemantics("AND (WEAKAND(100) vehiclebrand:bmw) expensivetv", "bmw motorcycle", child2); + assertSemantics("WEAKAND(100) vw car", "vw cars", child2); + assertSemantics("WEAKAND(100) vehiclebrand:skoda", "skoda cars", child2); } @Test - public void testGrandchild() { - assertSemantics("WEAKAND(100) vehiclebrand:skoda","audi cars", grandchild); - assertSemantics("WEAKAND(100) vehiclebrand:alfa","alfa bus", grandchild); - assertSemantics("AND (WEAKAND(100) vehiclebrand:bmw) expensivetv","bmw motorcycle", grandchild); - assertSemantics("WEAKAND(100) vehiclebrand:skoda","vw cars", grandchild); - assertSemantics("WEAKAND(100) vehiclebrand:skoda","skoda cars", grandchild); + void testGrandchild() { + assertSemantics("WEAKAND(100) vehiclebrand:skoda", "audi cars", grandchild); + assertSemantics("WEAKAND(100) vehiclebrand:alfa", "alfa bus", grandchild); + assertSemantics("AND (WEAKAND(100) vehiclebrand:bmw) expensivetv", "bmw motorcycle", grandchild); + assertSemantics("WEAKAND(100) vehiclebrand:skoda", "vw cars", grandchild); + assertSemantics("WEAKAND(100) vehiclebrand:skoda", "skoda cars", grandchild); } @Test - public void testRuleBaseNames() { + void testRuleBaseNames() { assertEquals("parent", parent.getName()); assertEquals("child1", child1.getName()); assertEquals("child2", child2.getName()); @@ -132,10 +129,10 @@ public class InheritanceTestCase { } @Test - public void testSearcher() { - assertSemantics("WEAKAND(100) vehiclebrand:skoda","vw cars", ""); - assertSemantics("WEAKAND(100) vehiclebrand:skoda","vw cars", "&rules.rulebase=grandchild"); - assertSemantics("WEAKAND(100) vehiclebrand:skoda","vw cars", "&rules.rulebase=grandchild.sd"); + void testSearcher() { + assertSemantics("WEAKAND(100) vehiclebrand:skoda", "vw cars", ""); + assertSemantics("WEAKAND(100) vehiclebrand:skoda", "vw cars", "&rules.rulebase=grandchild"); + assertSemantics("WEAKAND(100) vehiclebrand:skoda", "vw cars", "&rules.rulebase=grandchild.sd"); try { assertSemantics("WEAKAND(100) vw cars", "vw cars", "&rules.rulebase=doesntexist"); fail("No exception on missing rule base"); @@ -147,14 +144,14 @@ public class InheritanceTestCase { assertSemantics("WEAKAND(100) vw cars", "vw cars", "&rules.off"); assertSemantics("WEAKAND(100) vw car", "vw cars", "&rules.rulebase=child2"); - assertSemantics("WEAKAND(100) vehiclebrand:skoda","skoda cars","&rules.rulebase=child2"); + assertSemantics("WEAKAND(100) vehiclebrand:skoda", "skoda cars", "&rules.rulebase=child2"); - assertSemantics("WEAKAND(100) vehiclebrand:skoda","audi cars", "&rules.rulebase=child1"); - assertSemantics("WEAKAND(100) vehiclebrand:skoda","vw cars", "&rules.rulebase=child1"); - assertSemantics("WEAKAND(100) skoda car", "skoda cars","&rules.rulebase=child1"); + assertSemantics("WEAKAND(100) vehiclebrand:skoda", "audi cars", "&rules.rulebase=child1"); + assertSemantics("WEAKAND(100) vehiclebrand:skoda", "vw cars", "&rules.rulebase=child1"); + assertSemantics("WEAKAND(100) skoda car", "skoda cars", "&rules.rulebase=child1"); assertSemantics("WEAKAND(100) vw car", "vw cars", "&rules.rulebase=parent"); - assertSemantics("WEAKAND(100) skoda car", "skoda cars","&rules.rulebase=parent"); + assertSemantics("WEAKAND(100) skoda car", "skoda cars", "&rules.rulebase=parent"); } protected void assertSemantics(String result,String input,String ruleSelection) { diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/LabelMatchingTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/LabelMatchingTestCase.java index d45e114e89f..0a12ea2c49f 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/LabelMatchingTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/LabelMatchingTestCase.java @@ -4,7 +4,7 @@ package com.yahoo.prelude.semantics.test; import java.io.IOException; import com.yahoo.prelude.semantics.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests label-dependent matching @@ -19,30 +19,30 @@ public class LabelMatchingTestCase extends RuleBaseAbstractTestCase { /** Tests that matching with no label matches the default label (index) only */ @Test - public void testDefaultLabelMatching() throws IOException, ParseException { - assertSemantics("matched:term","term"); - assertSemantics("alabel:term","alabel:term"); + void testDefaultLabelMatching() throws IOException, ParseException { + assertSemantics("matched:term", "term"); + assertSemantics("alabel:term", "alabel:term"); - assertSemantics("AND term2 hit","term2"); - assertSemantics("alabel:term2","alabel:term2"); + assertSemantics("AND term2 hit", "term2"); + assertSemantics("alabel:term2", "alabel:term2"); } @Test - public void testSpecificLabelMatchingInConditionReference() throws IOException, ParseException { - assertSemantics("+dcattitle:restaurants -dcat:hotel","dcattitle:restaurants"); + void testSpecificLabelMatchingInConditionReference() throws IOException, ParseException { + assertSemantics("+dcattitle:restaurants -dcat:hotel", "dcattitle:restaurants"); } @Test - public void testSpecificlabelMatchingInNestedCondition() throws IOException, ParseException { - assertSemantics("three","foo:one"); - assertSemantics("three","foo:two"); - assertSemantics("bar:one","bar:one"); - assertSemantics("bar:two","bar:two"); - assertSemantics("foo:three","foo:three"); - assertSemantics("one","one"); - assertSemantics("two","two"); - assertSemantics("AND three three","foo:one foo:two"); - assertSemantics("AND bar:one bar:two","bar:one bar:two"); + void testSpecificlabelMatchingInNestedCondition() throws IOException, ParseException { + assertSemantics("three", "foo:one"); + assertSemantics("three", "foo:two"); + assertSemantics("bar:one", "bar:one"); + assertSemantics("bar:two", "bar:two"); + assertSemantics("foo:three", "foo:three"); + assertSemantics("one", "one"); + assertSemantics("two", "two"); + assertSemantics("AND three three", "foo:one foo:two"); + assertSemantics("AND bar:one bar:two", "bar:one bar:two"); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/MatchAllTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/MatchAllTestCase.java index 22b24e1a0b0..270c2789ec5 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/MatchAllTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/MatchAllTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * tersts the ellipsis rule base @@ -15,17 +15,17 @@ public class MatchAllTestCase extends RuleBaseAbstractTestCase { } @Test - public void testMatchAll() { - assertSemantics("RANK a normtitle:a","a"); - assertSemantics("RANK (AND a b) normtitle:\"a b\"","a b"); - assertSemantics("RANK (AND a a b a) normtitle:\"a a b a\"","a a b a"); + void testMatchAll() { + assertSemantics("RANK a normtitle:a", "a"); + assertSemantics("RANK (AND a b) normtitle:\"a b\"", "a b"); + assertSemantics("RANK (AND a a b a) normtitle:\"a a b a\"", "a a b a"); } @Test - public void testMatchAllFilterIsIgnored() { - assertSemantics("RANK a |b normtitle:a","a&filter=b"); - assertSemantics("RANK (AND a b) |b |c normtitle:\"a b\"","a b&filter=b c"); - assertSemantics("RANK (AND a a b a) |a |a |c |d |b normtitle:\"a a b a\"","a a b a&filter=a a c d b"); + void testMatchAllFilterIsIgnored() { + assertSemantics("RANK a |b normtitle:a", "a&filter=b"); + assertSemantics("RANK (AND a b) |b |c normtitle:\"a b\"", "a b&filter=b c"); + assertSemantics("RANK (AND a a b a) |a |a |c |d |b normtitle:\"a a b a\"", "a a b a&filter=a a c d b"); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/MatchOnlyIfNotOnlyTermTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/MatchOnlyIfNotOnlyTermTestCase.java index c398f0ed99e..30a88e74e91 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/MatchOnlyIfNotOnlyTermTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/MatchOnlyIfNotOnlyTermTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Experiments with a way to match only if it doesn't remove all hard conditions in the query. @@ -16,13 +16,13 @@ public class MatchOnlyIfNotOnlyTermTestCase extends RuleBaseAbstractTestCase { } @Test - public void testMatch() { + void testMatch() { assertSemantics("RANK showname:\"saturday night live\"!1000 (AND justin timberlake)", "justin timberlake snl"); assertSemantics("RANK showname:\"saturday night live\"!1000 (AND justin timberlake)", "justin timberlake saturday night live"); } @Test - public void testNoMatch() { + void testNoMatch() { // TODO: This shows that we do match, i.e that currently the behavior is undesired assertSemantics("showname:\"saturday night live\"!1000", "snl"); assertSemantics("showname:\"saturday night live\"!1000", "saturday night live"); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/MusicTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/MusicTestCase.java index 006dcb3c714..49766cc027c 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/MusicTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/MusicTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests the rewriting in the semanticsearcher system test @@ -11,7 +11,7 @@ import org.junit.Test; public class MusicTestCase { @Test - public void testMusic() { + void testMusic() { var tester = new RuleBaseTester("music.sr"); tester.assertSemantics("AND song:together artist:youngbloods", "together by youngbloods"); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/NoStemmingTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/NoStemmingTestCase.java index fbdd72fe6ac..04bc3249efe 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/NoStemmingTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/NoStemmingTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests a case reported by tularam @@ -16,20 +16,20 @@ public class NoStemmingTestCase extends RuleBaseAbstractTestCase { /** Should rewrite correctly */ @Test - public void testCorrectRewriting1() { - assertSemantics("+(AND i:arts i:sciences TRUE) -i:b","i:as -i:b"); + void testCorrectRewriting1() { + assertSemantics("+(AND i:arts i:sciences TRUE) -i:b", "i:as -i:b"); } /** Should rewrite correctly too */ @Test - public void testCorrectRewriting2() { - assertSemantics("+(AND i:arts i:sciences i:crafts TRUE) -i:b","i:asc -i:b"); + void testCorrectRewriting2() { + assertSemantics("+(AND i:arts i:sciences i:crafts TRUE) -i:b", "i:asc -i:b"); } /** Should not rewrite */ @Test - public void testNoRewriting() { - assertSemantics("+i:a -i:s","i:a -i:s"); + void testNoRewriting() { + assertSemantics("+i:a -i:s", "i:a -i:s"); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/NotTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/NotTestCase.java index c76db0a7afd..0ec320c7780 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/NotTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/NotTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author bratseth @@ -13,11 +13,11 @@ public class NotTestCase extends RuleBaseAbstractTestCase { } @Test - public void testLiteralEquals() { - assertSemantics("RANK a foo:a","a"); - assertSemantics("a","a&ranking=category"); - assertSemantics("RANK a foo:a","a&ranking=somethingelse"); - assertSemantics("RANK a foo:a","a&otherparam=category"); + void testLiteralEquals() { + assertSemantics("RANK a foo:a", "a"); + assertSemantics("a", "a&ranking=category"); + assertSemantics("RANK a foo:a", "a&ranking=somethingelse"); + assertSemantics("RANK a foo:a", "a&otherparam=category"); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/NumbersTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/NumbersTestCase.java index b18cafdd161..60ccaa35cc4 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/NumbersTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/NumbersTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests numbers as conditions and productions @@ -15,13 +15,13 @@ public class NumbersTestCase extends RuleBaseAbstractTestCase { } @Test - public void testNumbers() { - assertSemantics("elite","1337"); - assertSemantics("1","one"); - assertSemantics("AND bort ned","opp"); - assertSemantics("AND kanoo knagg","foo bar"); - assertSemantics("AND 3 three","two 2"); - assertSemantics("AND 1 elite","one 1337"); + void testNumbers() { + assertSemantics("elite", "1337"); + assertSemantics("1", "one"); + assertSemantics("AND bort ned", "opp"); + assertSemantics("AND kanoo knagg", "foo bar"); + assertSemantics("AND 3 three", "two 2"); + assertSemantics("AND 1 elite", "one 1337"); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/NumericTermsTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/NumericTermsTestCase.java index f76deeacbb5..b63b3579c76 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/NumericTermsTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/NumericTermsTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests numeric terms @@ -15,13 +15,13 @@ public class NumericTermsTestCase extends RuleBaseAbstractTestCase { } @Test - public void testNumericProduction() { - assertSemantics("+restaurants -ycat2gc:96929265","restaurants"); + void testNumericProduction() { + assertSemantics("+restaurants -ycat2gc:96929265", "restaurants"); } @Test - public void testNumericConditionAndProduction() { - assertSemantics("48","49"); + void testNumericConditionAndProduction() { + assertSemantics("48", "49"); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/OrPhraseTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/OrPhraseTestCase.java index 1d6eea8d7de..045d8698547 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/OrPhraseTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/OrPhraseTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author bratseth @@ -13,14 +13,14 @@ public class OrPhraseTestCase extends RuleBaseAbstractTestCase { } @Test - public void testReplacing1() { - assertSemantics("OR title:\"software engineer\" (AND new york)","software engineer new york"); - assertSemantics("title:\"software engineer\"","software engineer"); // Skip or when there is nothing else + void testReplacing1() { + assertSemantics("OR title:\"software engineer\" (AND new york)", "software engineer new york"); + assertSemantics("title:\"software engineer\"", "software engineer"); // Skip or when there is nothing else } @Test - public void testReplacing2() { - assertSemantics("OR lotr \"lord of the rings\"","lotr"); + void testReplacing2() { + assertSemantics("OR lotr \"lord of the rings\"", "lotr"); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/Parameter2TestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/Parameter2TestCase.java index 5b1c38b7752..b9332effcb7 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/Parameter2TestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/Parameter2TestCase.java @@ -2,9 +2,9 @@ package com.yahoo.prelude.semantics.test; import com.yahoo.search.Query; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests parameter matching and production @@ -19,8 +19,8 @@ public class Parameter2TestCase extends RuleBaseAbstractTestCase { /** Tests parameter production */ @Test - public void testParameterProduction() { - assertRankParameterSemantics("WEAKAND(100) a","a&ranking=usrank","date",0); + void testParameterProduction() { + assertRankParameterSemantics("WEAKAND(100) a", "a&ranking=usrank", "date", 0); } private void assertRankParameterSemantics(String producedQuery,String inputQuery, diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ParameterTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ParameterTestCase.java index b597443d1d3..7df1ccbc156 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ParameterTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ParameterTestCase.java @@ -2,9 +2,9 @@ package com.yahoo.prelude.semantics.test; import com.yahoo.search.Query; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests parameter matching and production @@ -19,7 +19,7 @@ public class ParameterTestCase extends RuleBaseAbstractTestCase { /** Tests parameter literal matching */ @Test - public void testLiteralEquals() { + void testLiteralEquals() { assertSemantics("a", "a"); assertSemantics("RANK a foo:a", "a&ranking=category"); assertSemantics("a", "a&ranking=somethingelse"); @@ -28,7 +28,7 @@ public class ParameterTestCase extends RuleBaseAbstractTestCase { /** Tests parameter matching of larger */ @Test - public void testLarger() { + void testLarger() { assertSemantics("a", "a"); assertSemantics("AND a largepage", "a&hits=11"); assertSemantics("AND a largepage", "a&hits=12"); @@ -36,8 +36,8 @@ public class ParameterTestCase extends RuleBaseAbstractTestCase { /** Tests parameter containment matching */ @Test - public void testContainsAsList() { - assertSemantics("a","a"); + void testContainsAsList() { + assertSemantics("a", "a"); assertSemantics("AND a intent:music", "a&search=music"); assertSemantics("AND a intent:music", "a&search=music,books"); assertSemantics("AND a intent:music", "a&search=kanoos,music,books"); @@ -45,7 +45,7 @@ public class ParameterTestCase extends RuleBaseAbstractTestCase { /** Tests parameter production */ @Test - public void testParameterProduction() { + void testParameterProduction() { assertParameterSemantics("AND a b c", "a b c", "search", "[letters, alphabet]"); assertParameterSemantics("AND a c d", "a c d", "search", "[letters, someletters]"); assertParameterSemantics("+(AND a d e) -letter:c", "a d e", "search", "[someletters]"); @@ -54,7 +54,7 @@ public class ParameterTestCase extends RuleBaseAbstractTestCase { } @Test - public void testMultipleAlternativeParameterValuesInCondition() { + void testMultipleAlternativeParameterValuesInCondition() { assertInputRankParameterSemantics("WEAKAND(100) one", "foo", "cat"); assertInputRankParameterSemantics("WEAKAND(100) one", "foo", "cat0"); assertInputRankParameterSemantics("WEAKAND(100) one", "bar", "cat"); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/PhraseMatchTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/PhraseMatchTestCase.java index fd9003e0e05..9536c1bfb7c 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/PhraseMatchTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/PhraseMatchTestCase.java @@ -1,8 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; /** * Tests that the phrase produced by an automata match can subsequently be replaced by an AND of the @@ -16,14 +16,15 @@ public class PhraseMatchTestCase extends RuleBaseAbstractTestCase { super("phrasematch.sr", "semantics.fsa"); } + // TODO: Work in progress @Test - @Ignore // TODO: Work in progress - public void testLiteralEquals() { - assertSemantics("AND retailer:digital retailer:camera","keyword:digital keyword:camera"); + @Disabled + void testLiteralEquals() { + assertSemantics("AND retailer:digital retailer:camera", "keyword:digital keyword:camera"); } @Test - public void testMatchingPhrase() { + void testMatchingPhrase() { assertSemantics("OR (AND iphone 7) i7", "iphone 7"); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ProductionRuleTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ProductionRuleTestCase.java index e892adc3b1c..44ebd4f1995 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ProductionRuleTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ProductionRuleTestCase.java @@ -15,10 +15,10 @@ import com.yahoo.prelude.semantics.rule.ReferenceTermProduction; import com.yahoo.prelude.semantics.rule.ReplacingProductionRule; import com.yahoo.prelude.semantics.rule.TermCondition; import com.yahoo.prelude.semantics.rule.TermProduction; -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.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author bratseth @@ -26,7 +26,7 @@ import static org.junit.Assert.assertTrue; public class ProductionRuleTestCase { @Test - public void testProductionRule() { + void testProductionRule() { var linguistics = new RuleBaseLinguistics(new SimpleLinguistics()); TermCondition term = new TermCondition("sony", linguistics); NamedCondition named = new NamedCondition("brand", term); @@ -46,7 +46,7 @@ public class ProductionRuleTestCase { ruleBase.addRule(rule); ruleBase.initialize(); - assertTrue("Brand is referenced", rule.matchReferences().contains("brand")); + assertTrue(rule.matchReferences().contains("brand"), "Brand is referenced"); Query query = new Query("?query=sony"); RuleEvaluation e = new Evaluation(query, null).freshRuleEvaluation(); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/RuleBaseAbstractTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/RuleBaseAbstractTestCase.java index 84e47edae29..668251c0a1f 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/RuleBaseAbstractTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/RuleBaseAbstractTestCase.java @@ -14,7 +14,7 @@ import com.yahoo.search.test.QueryTestCase; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * DO NOT USE. Use RuleBaseTester instead diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/RuleBaseTester.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/RuleBaseTester.java index cc9e758a0e0..dc43ffc55e7 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/RuleBaseTester.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/RuleBaseTester.java @@ -14,7 +14,7 @@ import com.yahoo.search.test.QueryTestCase; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Helper for testing with a rule base. diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/SegmentSubstitutionTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/SegmentSubstitutionTestCase.java index 69faed1da90..8d7c16f5544 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/SegmentSubstitutionTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/SegmentSubstitutionTestCase.java @@ -8,8 +8,7 @@ import com.yahoo.prelude.query.parser.TestLinguistics; import com.yahoo.search.Query; import com.yahoo.search.query.parser.Parsable; import com.yahoo.search.query.parser.ParserEnvironment; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SegmentSubstitutionTestCase extends RuleBaseAbstractTestCase { @@ -18,7 +17,7 @@ public class SegmentSubstitutionTestCase extends RuleBaseAbstractTestCase { } @Test - public void testBasicSubstitution() { + void testBasicSubstitution() { Item a = parseQuery("firstsecond"); Query q = new Query("?query=ignored&tracelevel=0&tracelevel.rules=0"); q.getModel().getQueryTree().setRoot(a); @@ -27,7 +26,7 @@ public class SegmentSubstitutionTestCase extends RuleBaseAbstractTestCase { } @Test - public void testSubstitutionAndMoreTerms() { + void testSubstitutionAndMoreTerms() { Item a = parseQuery("bcfirstsecondfg"); Query q = new Query("?query=ignored&tracelevel=0&tracelevel.rules=0"); q.getModel().getQueryTree().setRoot(a); @@ -36,7 +35,7 @@ public class SegmentSubstitutionTestCase extends RuleBaseAbstractTestCase { } @Test - public void testSubstitutionAndNot() { + void testSubstitutionAndNot() { Item a = parseQuery("-firstsecond bc"); Query q = new Query("?query=ignored&tracelevel=0&tracelevel.rules=0"); q.getModel().getQueryTree().setRoot(a); @@ -45,7 +44,7 @@ public class SegmentSubstitutionTestCase extends RuleBaseAbstractTestCase { } @Test - public void testSubstitutionSomeNoise() { + void testSubstitutionSomeNoise() { Item a = parseQuery("9270bcsecond2389"); Query q = new Query("?query=ignored&tracelevel=0&tracelevel.rules=0"); q.getModel().getQueryTree().setRoot(a); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/SemanticSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/SemanticSearcherTestCase.java index bee65db4347..489afcb3088 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/SemanticSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/SemanticSearcherTestCase.java @@ -8,12 +8,12 @@ import com.yahoo.prelude.query.NullItem; import com.yahoo.search.Result; import com.yahoo.search.Searcher; import com.yahoo.search.searchchain.Execution; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests semantic searching @@ -27,128 +27,128 @@ public class SemanticSearcherTestCase extends RuleBaseAbstractTestCase { } @Test - public void testSingleShopping() { + void testSingleShopping() { assertSemantics("brand:sony", - "sony"); + "sony"); assertSemantics("brand:sony!150", - "sony!150"); + "sony!150"); } @Test - public void testCombinedShopping() { + void testCombinedShopping() { assertSemantics("AND brand:sony category:camera", - "sony camera"); + "sony camera"); } @Test - public void testPhrasedShopping() { + void testPhrasedShopping() { assertSemantics("AND brand:sony category:\"digital camera\"", - "sony digital camera"); + "sony digital camera"); } @Test - public void testSimpleLocal() { + void testSimpleLocal() { assertSemantics("AND listing:restaurant place:geary", - "restaurant in geary"); + "restaurant in geary"); } @Test - public void testLocal() { + void testLocal() { assertSemantics("AND listing:restaurant place:\"geary street san francisco\"", - "restaurant in geary street san francisco"); + "restaurant in geary street san francisco"); } @Test - public void testLiteralReplacing() { + void testLiteralReplacing() { assertSemantics("AND lord of rings", "lotr"); } @Test - public void testAddingAnd() { + void testAddingAnd() { assertSemantics("AND bar foobar:bar", - "bar"); + "bar"); } @Test - public void testAddingRank() { + void testAddingRank() { assertSemantics("RANK word foobar:word", - "word"); + "word"); } @Test - public void testFilterIsIgnored() { + void testFilterIsIgnored() { assertSemantics("RANK word |a |word |b foobar:word", - "word&filter=a word b"); + "word&filter=a word b"); assertSemantics("RANK a |word |b", - "a&filter=word b"); + "a&filter=word b"); } @Test - public void testAddingNegative() { + void testAddingNegative() { assertSemantics("+java -coffee", - "java"); + "java"); } @Test - public void testAddingNegativePluralToSingular() { + void testAddingNegativePluralToSingular() { assertSemantics("+javas -coffee", - "javas"); + "javas"); } @Test - public void testCombined() { + void testCombined() { assertSemantics("AND bar listing:restaurant place:\"geary street san francisco\" foobar:bar", - "bar restaurant in geary street san francisco"); + "bar restaurant in geary street san francisco"); } @Test - public void testStopWord() { - assertSemantics("strokes","the strokes"); + void testStopWord() { + assertSemantics("strokes", "the strokes"); } @Test - public void testStopWords1() { - assertSemantics("strokes","be the strokes"); + void testStopWords1() { + assertSemantics("strokes", "be the strokes"); } @Test - public void testStopWords2() { - assertSemantics("strokes","the strokes be"); + void testStopWords2() { + assertSemantics("strokes", "the strokes be"); } @Test - public void testDontRemoveEverything() { - assertSemantics("the","the the the"); + void testDontRemoveEverything() { + assertSemantics("the", "the the the"); } @Test - public void testMoreStopWordRemoval() { - assertSemantics("hamlet","hamlet to be or not to be"); + void testMoreStopWordRemoval() { + assertSemantics("hamlet", "hamlet to be or not to be"); } @Test - public void testTypeChange() { - assertSemantics("RANK default:typechange doors","typechange doors"); + void testTypeChange() { + assertSemantics("RANK default:typechange doors", "typechange doors"); } @Test - public void testTypeChangeWithSingularToPluralButNonReplaceWillNotSingularify() { - assertSemantics("RANK default:typechange door","typechange door"); + void testTypeChangeWithSingularToPluralButNonReplaceWillNotSingularify() { + assertSemantics("RANK default:typechange door", "typechange door"); } @Test - public void testExplicitContext() { - assertSemantics("AND from:paris to:texas","paris to texas"); + void testExplicitContext() { + assertSemantics("AND from:paris to:texas", "paris to texas"); } @Test - public void testOrProduction() { + void testOrProduction() { assertSemantics("OR something somethingelse", "something"); } // This test is order dependent. Fix it!! @Test - public void testWeightedSetItem() { + void testWeightedSetItem() { Query q = new Query(); WeightedSetItem weightedSet = new WeightedSetItem("fieldName"); weightedSet.addToken("a", 1); @@ -158,7 +158,7 @@ public class SemanticSearcherTestCase extends RuleBaseAbstractTestCase { } @Test - public void testNullQuery() { + void testNullQuery() { Query query = new Query(""); // Causes a query containing a NullItem doSearch(searcher, query, 0, 10); assertEquals(NullItem.class, query.getModel().getQueryTree().getRoot().getClass()); // Still a NullItem diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/StemmingTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/StemmingTestCase.java index b8efbf7422b..c5277bf6ef6 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/StemmingTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/StemmingTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests stemming. @@ -11,43 +11,43 @@ import org.junit.Test; public class StemmingTestCase { @Test - public void testRewritingDueToStemmingInQuery() { + void testRewritingDueToStemmingInQuery() { var tester = new RuleBaseTester("stemming.sr"); tester.assertSemantics("+(AND i:vehicle TRUE) -i:s", "i:cars -i:s"); } @Test - public void testNoRewritingDueToStemmingInQueryWhenStemmingDisabled() { + void testNoRewritingDueToStemmingInQueryWhenStemmingDisabled() { var tester = new RuleBaseTester("stemming-none.sr"); tester.assertSemantics("+i:cars -i:s", "i:cars -i:s"); } @Test - public void testRewritingDueToStemmingInRule() { + void testRewritingDueToStemmingInRule() { var tester = new RuleBaseTester("stemming.sr"); tester.assertSemantics("+(AND i:animal TRUE) -i:s", "i:horse -i:s"); } @Test - public void testNoRewritingDueToStemmingInRuleWhenStemmingDisabled() { + void testNoRewritingDueToStemmingInRuleWhenStemmingDisabled() { var tester = new RuleBaseTester("stemming-none.sr"); tester.assertSemantics("+i:horse -i:s", "i:horse -i:s"); } @Test - public void testRewritingDueToExactMatch() { + void testRewritingDueToExactMatch() { var tester = new RuleBaseTester("stemming.sr"); tester.assertSemantics("+(AND i:arts i:sciences TRUE) -i:s", "i:as -i:s"); } @Test - public void testEnglishStemming() { + void testEnglishStemming() { var tester = new RuleBaseTester("stemming.sr"); tester.assertSemantics("i:drive", "i:going"); } @Test - public void testFrenchStemming() { + void testFrenchStemming() { var tester = new RuleBaseTester("stemming-french.sr"); tester.assertSemantics("i:going", "i:going"); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/StopwordTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/StopwordTestCase.java index a0c2cf4545c..207ae7f8877 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/StopwordTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/StopwordTestCase.java @@ -3,7 +3,7 @@ package com.yahoo.prelude.semantics.test; import com.yahoo.search.Query; import com.yahoo.search.test.QueryTestCase; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests numeric terms @@ -17,21 +17,21 @@ public class StopwordTestCase extends RuleBaseAbstractTestCase { } @Test - public void testStopwords() { + void testStopwords() { assertSemantics("WEAKAND(100) mlr:ve mlr:heard mlr:beautiful mlr:world", - new Query(QueryTestCase.httpEncode("?query=i don't know if you've heard, but it's a beautiful world&default-index=mlr&tracelevel.rules=0"))); + new Query(QueryTestCase.httpEncode("?query=i don't know if you've heard, but it's a beautiful world&default-index=mlr&tracelevel.rules=0"))); } /** If the query contains nothing but stopwords, we won't remove them */ @Test - public void testOnlyStopwords() { + void testOnlyStopwords() { assertSemantics("WEAKAND(100) mlr:the", new Query(QueryTestCase.httpEncode("?query=the the&default-index=mlr&tracelevel.rules=0"))); } @Test - public void testStopwordsInPhrase() { + void testStopwordsInPhrase() { assertSemantics("WEAKAND(100) mlr:\"ve heard\" mlr:beautiful mlr:world", - new Query(QueryTestCase.httpEncode("?query=\"i don't know if you've heard\", but it's a beautiful world&default-index=mlr&tracelevel.rules=0"))); + new Query(QueryTestCase.httpEncode("?query=\"i don't know if you've heard\", but it's a beautiful world&default-index=mlr&tracelevel.rules=0"))); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/SynonymTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/SynonymTestCase.java index 8f69be2f710..65001cfcd44 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/SynonymTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/SynonymTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author bratseth @@ -9,7 +9,7 @@ import org.junit.Test; public class SynonymTestCase { @Test - public void testReplacingBySynonyms() { + void testReplacingBySynonyms() { var tester = new RuleBaseTester("synonyms.sr"); tester.assertSemantics("EQUIV index1:foo index1:baz index1:bar", "index1:foo"); tester.assertSemantics("EQUIV index1:foo index1:baz index1:bar", "index1:bar"); @@ -20,7 +20,7 @@ public class SynonymTestCase { } @Test - public void testAddingSynonyms() { + void testAddingSynonyms() { var tester = new RuleBaseTester("synonyms.sr"); tester.assertSemantics("EQUIV index2:foo index2:baz index2:bar", "index2:foo"); tester.assertSemantics("EQUIV index2:bar index2:foo index2:baz", "index2:bar"); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/UrlTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/UrlTestCase.java index 9bc64370030..c9eb30b3578 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/UrlTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/UrlTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests working with url indexes @@ -15,8 +15,8 @@ public class UrlTestCase extends RuleBaseAbstractTestCase { } @Test - public void testFromDefaultToUrlIndex() { - assertSemantics("fromurl:\"youtube com\"","youtube.com"); + void testFromDefaultToUrlIndex() { + assertSemantics("fromurl:\"youtube com\"", "youtube.com"); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/WeightingTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/WeightingTestCase.java index d89e6fdbfa3..e5d7408f3c0 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/WeightingTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/WeightingTestCase.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.prelude.semantics.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author bratseth @@ -13,7 +13,7 @@ public class WeightingTestCase extends RuleBaseAbstractTestCase { } @Test - public void testWeighting() { + void testWeighting() { assertSemantics("foo!150", "foo"); assertSemantics("AND foo!150 snip", "foo snip"); assertSemantics("AND foo!150 bar", "foo bar"); diff --git a/container-search/src/test/java/com/yahoo/prelude/test/GetRawWordTestCase.java b/container-search/src/test/java/com/yahoo/prelude/test/GetRawWordTestCase.java index 9ed84298838..edf039723fd 100644 --- a/container-search/src/test/java/com/yahoo/prelude/test/GetRawWordTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/test/GetRawWordTestCase.java @@ -4,9 +4,9 @@ package com.yahoo.prelude.test; import com.yahoo.prelude.query.AndItem; import com.yahoo.prelude.query.WordItem; import com.yahoo.search.Query; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests a case reported by MSBE @@ -16,27 +16,28 @@ import static org.junit.Assert.assertEquals; public class GetRawWordTestCase { @Test - public void testGetRawWord() { + void testGetRawWord() { Query query = new Query("?query=%C4%B0%C5%9EBANKASI%20GAZ%C4%B0EM%C4%B0R&type=all&searchChain=vespa"); assertEquals("AND \u0130\u015EBANKASI GAZ\u0130EM\u0130R", query.getModel().getQueryTree().toString()); - AndItem root = (AndItem)query.getModel().getQueryTree().getRoot(); + AndItem root = (AndItem) query.getModel().getQueryTree().getRoot(); { - WordItem word = (WordItem)root.getItem(0); + WordItem word = (WordItem) root.getItem(0); assertEquals("\u0130\u015EBANKASI", word.getRawWord()); assertEquals(0, word.getOrigin().start); assertEquals(9, word.getOrigin().end); } { - WordItem word = (WordItem)root.getItem(1); + WordItem word = (WordItem) root.getItem(1); assertEquals("GAZ\u0130EM\u0130R", word.getRawWord()); assertEquals(10, word.getOrigin().start); assertEquals(18, word.getOrigin().end); } - assertEquals("Total string is just these words",18, - ((WordItem)root.getItem(0)).getOrigin().getSuperstring().length()); + assertEquals(18, + ((WordItem) root.getItem(0)).getOrigin().getSuperstring().length(), + "Total string is just these words"); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java b/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java index 6a54492f5e5..4b24ba3671e 100644 --- a/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java @@ -11,7 +11,8 @@ import com.yahoo.prelude.SearchDefinition; import com.yahoo.search.Query; import com.yahoo.search.config.IndexInfoConfig; import com.yahoo.search.searchchain.Execution; -import org.junit.Test; +import org.junit.jupiter.api.Test; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -20,10 +21,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Tests using synthetic index names for IndexFacts class. @@ -58,7 +56,7 @@ public class IndexFactsTestCase { } @Test - public void testBasicCases() { + void testBasicCases() { // First check default behavior IndexFacts indexFacts = createIndexFacts(); Query q = newQuery("?query=a:b", indexFacts); @@ -68,7 +66,7 @@ public class IndexFactsTestCase { } @Test - public void testDefaultPosition() { + void testDefaultPosition() { Index a = new Index("a"); assertFalse(a.isDefaultPosition()); a.addCommand("any"); @@ -80,21 +78,21 @@ public class IndexFactsTestCase { sd.addCommand("b", "any"); assertNull(sd.getDefaultPosition()); sd.addCommand("c", "default-position"); - assertTrue(sd.getDefaultPosition().equals("c")); + assertEquals(sd.getDefaultPosition(), "c"); SearchDefinition sd2 = new SearchDefinition("sd2"); sd2.addIndex(new Index("b").addCommand("any")); assertNull(sd2.getDefaultPosition()); sd2.addIndex(a); - assertTrue(sd2.getDefaultPosition().equals("a")); + assertEquals(sd2.getDefaultPosition(), "a"); IndexFacts indexFacts = createIndexFacts(ImmutableList.of(sd, sd2)); - assertTrue(indexFacts.getDefaultPosition(null).equals("a")); - assertTrue(indexFacts.getDefaultPosition("sd").equals("c")); + assertEquals(indexFacts.getDefaultPosition(null), "a"); + assertEquals(indexFacts.getDefaultPosition("sd"), "c"); } @Test - public void testIndicesInAnyConfigurationAreIndicesInDefault() { + void testIndicesInAnyConfigurationAreIndicesInDefault() { IndexFacts.Session indexFacts = createIndexFacts().newSession(new Query()); assertTrue(indexFacts.isIndex("a")); assertTrue(indexFacts.isIndex("b")); @@ -104,21 +102,21 @@ public class IndexFactsTestCase { } @Test - public void testDefaultIsUnionHostIndex() { + void testDefaultIsUnionHostIndex() { IndexFacts.Session session = createIndexFacts().newSession(new Query()); assertTrue(session.getIndex("c").isHostIndex()); assertFalse(session.getIndex("a").isHostIndex()); } @Test - public void testDefaultIsUnionUriIndex() { + void testDefaultIsUnionUriIndex() { IndexFacts indexFacts = createIndexFacts(); assertTrue(indexFacts.newSession(new Query()).getIndex("d").isUriIndex()); assertFalse(indexFacts.newSession(new Query()).getIndex("a").isUriIndex()); } @Test - public void testDefaultIsUnionStemMode() { + void testDefaultIsUnionStemMode() { IndexFacts.Session session = createIndexFacts().newSession(new Query()); assertEquals(StemMode.NONE, session.getIndex("a").getStemMode()); assertEquals(StemMode.NONE, session.getIndex("b").getStemMode()); @@ -140,7 +138,7 @@ public class IndexFactsTestCase { } @Test - public void testExactMatching() { + void testExactMatching() { assertExactIsWorking("test"); assertExactIsWorking("artist_name_ft_norm1"); @@ -157,7 +155,7 @@ public class IndexFactsTestCase { Index e = nullSession.getIndex("e"); assertTrue(e.isExact()); - assertEquals("kj(/&",e.getExactTerminator()); + assertEquals("kj(/&", e.getExactTerminator()); Index a = nullSession.getIndex("a"); assertFalse(a.isExact()); @@ -169,7 +167,7 @@ public class IndexFactsTestCase { } @Test - public void testComplexExactMatching() { + void testComplexExactMatching() { SearchDefinition sd = new SearchDefinition("foobar"); String u_name = "foo_bar"; Index u_index = new Index(u_name); @@ -190,7 +188,7 @@ public class IndexFactsTestCase { // This is also backed by a system test on cause of complex config @Test - public void testRestrictLists1() { + void testRestrictLists1() { Query query = new Query(); query.getModel().getSources().add("nalle"); query.getModel().getSources().add("one"); @@ -203,7 +201,7 @@ public class IndexFactsTestCase { } @Test - public void testRestrictLists2() { + void testRestrictLists2() { Query query = new Query(); query.getModel().getSources().add("clusterTwo"); query.getModel().getRestrict().add("three"); @@ -223,7 +221,7 @@ public class IndexFactsTestCase { } @Test - public void testRestrictLists3() { + void testRestrictLists3() { Query query = new Query(); query.getModel().getSources().add("clusterOne"); query.getModel().getRestrict().add("two"); @@ -242,7 +240,7 @@ public class IndexFactsTestCase { } @Test - public void testPredicateBounds() { + void testPredicateBounds() { Index index = new Index("a"); assertEquals(Long.MIN_VALUE, index.getPredicateLowerBound()); assertEquals(Long.MAX_VALUE, index.getPredicateUpperBound()); @@ -264,7 +262,7 @@ public class IndexFactsTestCase { } @Test - public void testUriIndexAndRestrict() { + void testUriIndexAndRestrict() { IndexInfoConfig.Builder b = new IndexInfoConfig.Builder(); IndexInfoConfig.Indexinfo.Builder b1 = new IndexInfoConfig.Indexinfo.Builder(); @@ -298,7 +296,7 @@ public class IndexFactsTestCase { } @Test - public void testConflictingAliases() { + void testConflictingAliases() { SearchDefinition first = new SearchDefinition("first"); Index field1 = new Index("field1"); first.addIndex(field1); diff --git a/container-search/src/test/java/com/yahoo/prelude/test/IntegrationTestCase.java b/container-search/src/test/java/com/yahoo/prelude/test/IntegrationTestCase.java index b34edbf208c..10573b63bdc 100644 --- a/container-search/src/test/java/com/yahoo/prelude/test/IntegrationTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/test/IntegrationTestCase.java @@ -5,7 +5,7 @@ import com.yahoo.search.result.Hit; import com.yahoo.search.Result; import com.yahoo.search.Searcher; import com.yahoo.search.searchchain.Execution; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Runs a query thru the configured search chain from a real http channel @@ -32,8 +32,8 @@ public class IntegrationTestCase { } @Test - public void testQuery() throws java.io.IOException { - /* + void testQuery() throws java.io.IOException { + /* TODO: (JSB) This blocks forever on Linux (not Windows) because the ServerSocketChannel.accept method in Server seems to starve the test running thread, diff --git a/container-search/src/test/java/com/yahoo/prelude/test/LocationTestCase.java b/container-search/src/test/java/com/yahoo/prelude/test/LocationTestCase.java index 07750613249..96a24ac92c8 100644 --- a/container-search/src/test/java/com/yahoo/prelude/test/LocationTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/test/LocationTestCase.java @@ -2,9 +2,9 @@ package com.yahoo.prelude.test; import com.yahoo.prelude.Location; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests the Location class. Currently does not test all "features" of Location class. @@ -14,7 +14,7 @@ import static org.junit.Assert.assertEquals; public class LocationTestCase { @Test - public void testAspect() { + void testAspect() { //0 degrees latitude, on the equator Location loc1 = new Location("[2,-1110000,330000,-1160000,340000](2,-1100222,0,300,0,1,0,CalcLatLon)"); assertEquals(loc1.toString(), "[2,-1110000,330000,-1160000,340000](2,-1100222,0,300,0,1,0,4294967295)"); diff --git a/container-search/src/test/java/com/yahoo/prelude/test/NullSetMemberTestCase.java b/container-search/src/test/java/com/yahoo/prelude/test/NullSetMemberTestCase.java index e77f0d00578..495f11e0780 100644 --- a/container-search/src/test/java/com/yahoo/prelude/test/NullSetMemberTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/test/NullSetMemberTestCase.java @@ -1,13 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.HashSet; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Tests null members in HashSet @@ -15,7 +13,7 @@ import static org.junit.Assert.assertTrue; public class NullSetMemberTestCase { @Test - public void testNullMember() { + void testNullMember() { HashSet<?> s = new HashSet<>(); assertEquals(s.size(), 0); assertFalse(s.contains(null)); diff --git a/container-search/src/test/java/com/yahoo/prelude/test/QueryTestCase.java b/container-search/src/test/java/com/yahoo/prelude/test/QueryTestCase.java index eaab7e12f33..95ecf3c2dba 100644 --- a/container-search/src/test/java/com/yahoo/prelude/test/QueryTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/test/QueryTestCase.java @@ -14,12 +14,12 @@ import com.yahoo.search.Query; import com.yahoo.search.query.Sorting; import com.yahoo.search.searchchain.Execution; import com.yahoo.yolean.Exceptions; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Tests for query class @@ -29,7 +29,7 @@ import static org.junit.Assert.*; public class QueryTestCase { @Test - public void testBoolItem() { + void testBoolItem() { var original = new BoolItem(false); var cloned = original.clone(); assertNotSame(original, cloned); @@ -37,7 +37,7 @@ public class QueryTestCase { } @Test - public void testSimpleQueryParsing () { + void testSimpleQueryParsing() { Query q = newQuery("/search?query=foobar&offset=10&hits=20&type=all"); assertEquals("foobar", ((WordItem) q.getModel().getQueryTree().getRoot()).getWord()); assertEquals(10, q.getOffset()); @@ -45,7 +45,7 @@ public class QueryTestCase { } @Test - public void testAdvancedQueryParsing () { + void testAdvancedQueryParsing() { Query q = newQuery("/search?query=fOObar and kanoo&offset=10&hits=20&filter=-foo +bar&type=adv&suggestonly=true"); assertEquals("AND (+(AND fOObar kanoo) -|foo) |bar", q.getModel().getQueryTree().getRoot().toString()); assertEquals(10, q.getOffset()); @@ -54,7 +54,7 @@ public class QueryTestCase { } @Test - public void testAnyQueryParsing () { + void testAnyQueryParsing() { Query q = newQuery("/search?query=foobar and kanoo&offset=10&hits=10&type=any&suggestonly=true&filter=-fast.type:offensive&encoding=latin1"); assertEquals("+(OR foobar and kanoo) -|fast.type:offensive", q.getModel().getQueryTree().getRoot().toString()); assertEquals(10, q.getOffset()); @@ -64,13 +64,13 @@ public class QueryTestCase { } @Test - public void testLongQueryParsing() { + void testLongQueryParsing() { Query q = newQuery("/p13n?query=news" - +"interest:cnn!254+interest:cnnfn!171+interest:cnn+" - +"financial!96+interest:" - +"yahoo+com!253+interest:www+yahoo!138+" - +"interest:www+yahoo+com!136" - +"&hits=20&offset=0&vectorranking=queryrank"); + + "interest:cnn!254+interest:cnnfn!171+interest:cnn+" + + "financial!96+interest:" + + "yahoo+com!253+interest:www+yahoo!138+" + + "interest:www+yahoo+com!136" + + "&hits=20&offset=0&vectorranking=queryrank"); assertEquals("/p13n", q.getHttpRequest().getUri().getPath()); assertEquals(0, q.getOffset()); assertEquals(20, q.getHits()); @@ -83,9 +83,9 @@ public class QueryTestCase { * is not a number. */ @Test - public void testGetParamInt() { + void testGetParamInt() { Query q = newQuery("/search?query=foo%20bar&someint=10¬int=hello"); - assertEquals(10, (int)q.properties().getInteger("someint")); + assertEquals(10, (int) q.properties().getInteger("someint")); // provoke an exception. if exception is not triggered // we fail the test. @@ -98,13 +98,13 @@ public class QueryTestCase { } @Test - public void testUtf8Decoding() { + void testUtf8Decoding() { Query q = new Query("/?query=beyonc%C3%A9&type=all"); assertEquals("beyonc\u00e9", ((WordItem) q.getModel().getQueryTree().getRoot()).getWord()); } @Test - public void testSortSpec() { + void testSortSpec() { Query q = newQuery("?query=test&sortspec=+a -b c +[rank]"); assertNotNull(q.getRanking().getSorting()); List<Sorting.FieldOrder> sortSpec = q.getRanking().getSorting().fieldOrders(); @@ -120,13 +120,13 @@ public class QueryTestCase { } @Test - public void testSortSpecLowerCase() { + void testSortSpecLowerCase() { Query q = newQuery("?query=test&sortspec=-lowercase(name)"); assertNotNull(q.getRanking().getSorting()); List<Sorting.FieldOrder> sortSpec = q.getRanking().getSorting().fieldOrders(); assertEquals(sortSpec.size(), 1); assertEquals(Sorting.Order.DESCENDING, - sortSpec.get(0).getSortOrder()); + sortSpec.get(0).getSortOrder()); assertEquals("name", sortSpec.get(0).getFieldName()); assertTrue(sortSpec.get(0).getSorter() instanceof Sorting.LowerCaseSorter); } @@ -143,7 +143,7 @@ public class QueryTestCase { } @Test - public void testSortSpecUca() { + void testSortSpecUca() { checkUcaUS("?query=test&sortspec=-uca(name,en_US)"); checkUcaUS("?query=test&sortspec=-UCA(name,en_US)"); checkSortSpecUcaUSOptional("?query=test&sortspec=-uca(name,en_US,tertiary)"); @@ -151,21 +151,21 @@ public class QueryTestCase { } @Test - public void testInvalidSortFunction() { + void testInvalidSortFunction() { assertQueryError( "?query=test&sortspec=-ucca(name,en_US)", "Could not set 'ranking.sorting' to '-ucca(name,en_US)': Unknown sort function 'ucca'"); } @Test - public void testMissingSortFunction() { + void testMissingSortFunction() { assertQueryError( "?query=test&sortspec=-(name)", "Could not set 'ranking.sorting' to '-(name)': No sort function specified"); } @Test - public void testInvalidUcaStrength() { + void testInvalidUcaStrength() { assertQueryError( "?query=test&sortspec=-uca(name,en_US,tertary)", "Could not set 'ranking.sorting' to '-uca(name,en_US,tertary)': Unknown collation strength: 'tertary'"); @@ -189,7 +189,7 @@ public class QueryTestCase { * Extremely simple for now, will be used for pathological cases. */ @Test - public void testHashCode() { + void testHashCode() { Query p = newQuery("?query=foo&type=any"); Query q = newQuery("?query=foo&type=all"); assertTrue(p.hashCode() != q.hashCode()); @@ -197,17 +197,17 @@ public class QueryTestCase { /** Test using the defauultindex feature */ @Test - public void testDefaultIndex() { + void testDefaultIndex() { Query q = newQuery("?query=hi hello keyword:kanoo " + - "default:munkz \"phrases too\"&default-index=def"); + "default:munkz \"phrases too\"&default-index=def"); assertEquals("WEAKAND(100) def:hi def:hello keyword:kanoo " + - "default:munkz def:\"phrases too\"", - q.getModel().getQueryTree().getRoot().toString()); + "default:munkz def:\"phrases too\"", + q.getModel().getQueryTree().getRoot().toString()); } - /** Test that GET parameter names are case in-sensitive */ - @Test - public void testGETParametersCase() { + /** Test that GET parameter names are case in-sensitive */ + @Test + void testGETParametersCase() { Query q = newQuery("?QUERY=testing&hits=10&oFfSeT=10"); assertEquals("testing", q.getModel().getQueryString()); @@ -217,108 +217,108 @@ public class QueryTestCase { @Test - public void testNegativeHitValue() { + void testNegativeHitValue() { assertQueryError( "?query=test&hits=-1", "Could not set 'hits' to '-1': Must be a positive number"); } @Test - public void testNaNHitValue() { + void testNaNHitValue() { assertQueryError( "?query=test&hits=NaN", "Could not set 'hits' to 'NaN': 'NaN' is not a valid integer"); } @Test - public void testNoneHitValue() { + void testNoneHitValue() { assertQueryError( "?query=test&hits=(none)", "Could not set 'hits' to '(none)': '(none)' is not a valid integer"); } @Test - public void testNegativeOffsetValue() { + void testNegativeOffsetValue() { assertQueryError( "?query=test&offset=-1", "Could not set 'offset' to '-1': Must be a positive number"); } @Test - public void testNaNOffsetValue() { + void testNaNOffsetValue() { assertQueryError( "?query=test&offset=NaN", "Could not set 'offset' to 'NaN': 'NaN' is not a valid integer"); } @Test - public void testNoneOffsetValue() { + void testNoneOffsetValue() { assertQueryError( "?query=test&offset=(none)", "Could not set 'offset' to '(none)': '(none)' is not a valid integer"); } @Test - public void testNoneHitsNegativeOffsetValue() { + void testNoneHitsNegativeOffsetValue() { assertQueryError( "?query=test&hits=(none)&offset=-10", "Could not set 'hits' to '(none)': '(none)' is not a valid integer"); } @Test - public void testFeedbackIsTransferredToResult() { + void testFeedbackIsTransferredToResult() { assertQueryError( "?query=test&hits=(none)&offset=-10", "Could not set 'hits' to '(none)': '(none)' is not a valid integer"); } @Test - public void testUnicodeNormalization() { + void testUnicodeNormalization() { Linguistics linguistics = new SimpleLinguistics(); Query query = newQueryFromEncoded("?query=content:%EF%BC%B3%EF%BC%AF%EF%BC%AE%EF%BC%B9&type=all", Language.ENGLISH, - linguistics); + linguistics); assertEquals("SONY", ((WordItem) query.getModel().getQueryTree().getRoot()).getWord()); query = newQueryFromEncoded("?query=foo&filter=+%EF%BC%B3%EF%BC%AF%EF%BC%AE%EF%BC%B9&type=all", Language.ENGLISH, - linguistics); + linguistics); assertEquals("RANK foo |SONY", query.getModel().getQueryTree().getRoot().toString()); query = newQueryFromEncoded("?query=foo+AND+%EF%BC%B3%EF%BC%AF%EF%BC%AE%EF%BC%B9)&type=adv", - Language.ENGLISH, linguistics); + Language.ENGLISH, linguistics); assertEquals("AND foo SONY", query.getModel().getQueryTree().getRoot().toString()); } /** Test a vertical specific patch, see Tokenizer */ @Test - @Ignore - public void testPrivateUseCharacterParsing() { + @Disabled + void testPrivateUseCharacterParsing() { Query query = newQuery("?query=%EF%89%AB"); assertEquals(Character.UnicodeBlock.PRIVATE_USE_AREA, - Character.UnicodeBlock.of(query.getModel().getQueryTree().getRoot().toString().charAt(0))); + Character.UnicodeBlock.of(query.getModel().getQueryTree().getRoot().toString().charAt(0))); } /** Test a vertical specific patch, see Tokenizer */ @Test - @Ignore - public void testOtherCharactersParsing() { + @Disabled + void testOtherCharactersParsing() { Query query = newQuery(com.yahoo.search.test.QueryTestCase.httpEncode("?query=\u3007\u2e80\u2eff\u2ed0")); assertEquals(Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION, - Character.UnicodeBlock.of(query.getModel().getQueryTree().getRoot().toString().charAt(0))); + Character.UnicodeBlock.of(query.getModel().getQueryTree().getRoot().toString().charAt(0))); assertEquals(Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT, - Character.UnicodeBlock.of(query.getModel().getQueryTree().getRoot().toString().charAt(1))); + Character.UnicodeBlock.of(query.getModel().getQueryTree().getRoot().toString().charAt(1))); assertEquals(Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT, - Character.UnicodeBlock.of(query.getModel().getQueryTree().getRoot().toString().charAt(2))); + Character.UnicodeBlock.of(query.getModel().getQueryTree().getRoot().toString().charAt(2))); assertEquals(Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT, - Character.UnicodeBlock.of(query.getModel().getQueryTree().getRoot().toString().charAt(3))); + Character.UnicodeBlock.of(query.getModel().getQueryTree().getRoot().toString().charAt(3))); } @Test - public void testFreshness() { + void testFreshness() { Query query = newQuery("?query=test&datetime=103"); - assertTrue(query.getRanking().getFreshness().getRefTime()==103); + assertEquals(query.getRanking().getFreshness().getRefTime(), 103); query.getRanking().setFreshness("193"); - assertTrue(query.getRanking().getFreshness().getRefTime()==193); + assertEquals(query.getRanking().getFreshness().getRefTime(), 193); query.getRanking().setFreshness("now"); assertTrue(query.getRanking().getFreshness().getSystemTimeInSecondsSinceEpoch() >= query.getRanking().getFreshness().getRefTime()); @@ -330,10 +330,10 @@ public class QueryTestCase { } @Test - public void testCopy() { + void testCopy() { Query qs = newQuery("?query=test&rankfeature.something=2"); assertEquals("WEAKAND(100) test", qs.getModel().getQueryTree().toString()); - assertEquals((int)qs.properties().getInteger("rankfeature.something"),2); + assertEquals((int) qs.properties().getInteger("rankfeature.something"), 2); Query qp = new Query(qs); assertEquals("WEAKAND(100) test", qp.getModel().getQueryTree().getRoot().toString()); assertFalse(qp.getRanking().getFeatures().isEmpty()); diff --git a/container-search/src/test/java/com/yahoo/prelude/test/ResultTestCase.java b/container-search/src/test/java/com/yahoo/prelude/test/ResultTestCase.java index edbfe558ffd..28afe0611d4 100644 --- a/container-search/src/test/java/com/yahoo/prelude/test/ResultTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/test/ResultTestCase.java @@ -4,11 +4,11 @@ package com.yahoo.prelude.test; import java.util.Iterator; import com.yahoo.search.Query; + +import static org.junit.jupiter.api.Assertions.assertEquals; import com.yahoo.search.result.Hit; import com.yahoo.search.Result; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; /** * Tests the result class @@ -18,16 +18,16 @@ import static org.junit.Assert.assertEquals; public class ResultTestCase { @Test - public void testHitOrdering() { - Result result=new Result(new Query("dummy")); - result.hits().add(new Hit("test:hit1",80)); - result.hits().add(new Hit("test:hit2",90)); - result.hits().add(new Hit("test:hit3",70)); + void testHitOrdering() { + Result result = new Result(new Query("dummy")); + result.hits().add(new Hit("test:hit1", 80)); + result.hits().add(new Hit("test:hit2", 90)); + result.hits().add(new Hit("test:hit3", 70)); - Iterator<?> hits= result.hits().deepIterator(); - assertEquals(new Hit("test:hit2",90),hits.next()); - assertEquals(new Hit("test:hit1",80),hits.next()); - assertEquals(new Hit("test:hit3",70),hits.next()); + Iterator<?> hits = result.hits().deepIterator(); + assertEquals(new Hit("test:hit2", 90), hits.next()); + assertEquals(new Hit("test:hit1", 80), hits.next()); + assertEquals(new Hit("test:hit3", 70), hits.next()); } private void resultInit(Result result){ @@ -43,48 +43,48 @@ public class ResultTestCase { } @Test - public void testHitTrimming(){ - Result result=new Result(new Query("dummy")); + void testHitTrimming() { + Result result = new Result(new Query("dummy")); //case 1: keep some hits in the middle resultInit(result); result.hits().trim(3, 3); - assertEquals(3,result.getHitCount()); - Iterator<Hit> hits= result.hits().deepIterator(); - assertEquals(new Hit("test:hit3",70),hits.next()); - assertEquals(new Hit("test:hit8",55),hits.next()); - assertEquals(new Hit("test:hit5",50),hits.next()); - assertEquals(false,hits.hasNext()); + assertEquals(3, result.getHitCount()); + Iterator<Hit> hits = result.hits().deepIterator(); + assertEquals(new Hit("test:hit3", 70), hits.next()); + assertEquals(new Hit("test:hit8", 55), hits.next()); + assertEquals(new Hit("test:hit5", 50), hits.next()); + assertEquals(false, hits.hasNext()); //case 2: keep some hits at the end - result=new Result(new Query("dummy")); + result = new Result(new Query("dummy")); resultInit(result); result.hits().trim(5, 4); - hits= result.hits().deepIterator(); - assertEquals(new Hit("test:hit5",50),hits.next()); - assertEquals(new Hit("test:hit4",40),hits.next()); - assertEquals(new Hit("test:hit6",20),hits.next()); - assertEquals(new Hit("test:hit7",20),hits.next()); - assertEquals(false,hits.hasNext()); + hits = result.hits().deepIterator(); + assertEquals(new Hit("test:hit5", 50), hits.next()); + assertEquals(new Hit("test:hit4", 40), hits.next()); + assertEquals(new Hit("test:hit6", 20), hits.next()); + assertEquals(new Hit("test:hit7", 20), hits.next()); + assertEquals(false, hits.hasNext()); //case 3: keep some hits at the beginning - result=new Result(new Query("dummy")); + result = new Result(new Query("dummy")); resultInit(result); result.hits().trim(0, 4); - hits= result.hits().deepIterator(); - assertEquals(new Hit("test:hit2",90),hits.next()); - assertEquals(new Hit("test:hit1",80),hits.next()); - assertEquals(new Hit("test:hit9",75),hits.next()); - assertEquals(new Hit("test:hit3",70),hits.next()); - assertEquals(false,hits.hasNext()); + hits = result.hits().deepIterator(); + assertEquals(new Hit("test:hit2", 90), hits.next()); + assertEquals(new Hit("test:hit1", 80), hits.next()); + assertEquals(new Hit("test:hit9", 75), hits.next()); + assertEquals(new Hit("test:hit3", 70), hits.next()); + assertEquals(false, hits.hasNext()); //case 4: keep no hits - result=new Result(new Query("dummy")); + result = new Result(new Query("dummy")); resultInit(result); result.hits().trim(10, 4); - hits= result.hits().deepIterator(); - assertEquals(false,hits.hasNext()); + hits = result.hits().deepIterator(); + assertEquals(false, hits.hasNext()); } //This test is broken |