summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-01-03 15:20:03 +0100
committerJon Bratseth <bratseth@gmail.com>2022-01-03 15:20:03 +0100
commita9e52aa32101dc5ce39c5caa1d80c9cd7aa7684a (patch)
tree80bd9aa551ee9de7afaffee23130e7fb432488f9
parent1f3e5d1003a33d9a7076575eab8059c582611cdb (diff)
Avoid deprecated APIs
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/test/QueryTestCase.java38
-rw-r--r--container-search/src/test/java/com/yahoo/search/dispatch/LoadBalancerTest.java67
-rw-r--r--container-search/src/test/java/com/yahoo/search/dispatch/SearchPathTest.java35
-rw-r--r--container-search/src/test/java/com/yahoo/search/dispatch/rpc/ProtobufSerializationTest.java4
-rw-r--r--container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SearchChainResolverTestCase.java35
-rw-r--r--container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SourceRefResolverTestCase.java34
-rw-r--r--container-search/src/test/java/com/yahoo/search/grouping/GroupingValidatorTestCase.java117
-rw-r--r--container-search/src/test/java/com/yahoo/search/grouping/UniqueGroupingSearcherTestCase.java9
-rw-r--r--container-search/src/test/java/com/yahoo/search/grouping/request/MathFunctionsTestCase.java100
-rw-r--r--container-search/src/test/java/com/yahoo/search/handler/SearchHandlerTest.java11
-rw-r--r--container-search/src/test/java/com/yahoo/search/handler/test/JSONSearchHandlerTestCase.java21
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/types/test/NativePropertiesTestCase.java5
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java90
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/textserialize/item/test/ParseItemTestCase.java70
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/textserialize/serializer/test/SerializeItemTestCase.java60
-rw-r--r--container-search/src/test/java/com/yahoo/search/searchchain/config/test/SearchChainConfigurerTestCase.java68
-rw-r--r--container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java31
-rw-r--r--container-search/src/test/java/com/yahoo/search/yql/YqlParserTestCase.java7
18 files changed, 413 insertions, 389 deletions
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 d9e3cf84726..d5efd3992b2 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,15 +14,11 @@ import com.yahoo.search.Query;
import com.yahoo.search.query.Sorting;
import com.yahoo.search.searchchain.Execution;
import com.yahoo.yolean.Exceptions;
-import org.hamcrest.Matcher;
import org.junit.Ignore;
import org.junit.Test;
import java.util.List;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.anyOf;
-
import static org.junit.Assert.*;
/**
@@ -158,21 +154,21 @@ public class QueryTestCase {
public void testInvalidSortFunction() {
assertQueryError(
"?query=test&sortspec=-ucca(name,en_US)",
- containsString("Could not set 'ranking.sorting' to '-ucca(name,en_US)': Unknown sort function 'ucca'"));
+ "Could not set 'ranking.sorting' to '-ucca(name,en_US)': Unknown sort function 'ucca'");
}
@Test
public void testMissingSortFunction() {
assertQueryError(
"?query=test&sortspec=-(name)",
- containsString("Could not set 'ranking.sorting' to '-(name)': No sort function specified"));
+ "Could not set 'ranking.sorting' to '-(name)': No sort function specified");
}
@Test
public void testInvalidUcaStrength() {
assertQueryError(
"?query=test&sortspec=-uca(name,en_US,tertary)",
- containsString("Could not set 'ranking.sorting' to '-uca(name,en_US,tertary)': Unknown collation strength: 'tertary'"));
+ "Could not set 'ranking.sorting' to '-uca(name,en_US,tertary)': Unknown collation strength: 'tertary'");
}
public void checkSortSpecUcaUSOptional(String spec) {
@@ -224,60 +220,56 @@ public class QueryTestCase {
public void testNegativeHitValue() {
assertQueryError(
"?query=test&hits=-1",
- containsString("Could not set 'hits' to '-1': Must be a positive number"));
+ "Could not set 'hits' to '-1': Must be a positive number");
}
@Test
public void testNaNHitValue() {
assertQueryError(
"?query=test&hits=NaN",
- containsString("Could not set 'hits' to 'NaN': 'NaN' is not a valid integer"));
+ "Could not set 'hits' to 'NaN': 'NaN' is not a valid integer");
}
@Test
public void testNoneHitValue() {
assertQueryError(
"?query=test&hits=(none)",
- containsString("Could not set 'hits' to '(none)': '(none)' is not a valid integer"));
+ "Could not set 'hits' to '(none)': '(none)' is not a valid integer");
}
@Test
public void testNegativeOffsetValue() {
assertQueryError(
"?query=test&offset=-1",
- containsString("Could not set 'offset' to '-1': Must be a positive number"));
+ "Could not set 'offset' to '-1': Must be a positive number");
}
@Test
public void testNaNOffsetValue() {
assertQueryError(
"?query=test&offset=NaN",
- containsString("Could not set 'offset' to 'NaN': 'NaN' is not a valid integer"));
+ "Could not set 'offset' to 'NaN': 'NaN' is not a valid integer");
}
@Test
public void testNoneOffsetValue() {
assertQueryError(
"?query=test&offset=(none)",
- containsString("Could not set 'offset' to '(none)': '(none)' is not a valid integer"));
+ "Could not set 'offset' to '(none)': '(none)' is not a valid integer");
}
@Test
public void testNoneHitsNegativeOffsetValue() {
assertQueryError(
"?query=test&hits=(none)&offset=-10",
- anyOf(
- containsString("Could not set 'offset' to '-10': Must be a positive number"),
- containsString("Could not set 'hits' to '(none)': '(none)' is not a valid integer")));
+ "Could not set 'hits' to '(none)': '(none)' is not a valid integer");
}
@Test
public void testFeedbackIsTransferredToResult() {
assertQueryError(
"?query=test&hits=(none)&offset=-10",
- anyOf(
- containsString("Could not set 'hits' to '(none)': '(none)' is not a valid integer"),
- containsString("Could not set 'offset' to '-10': Must be a positive number")));
+ "Could not set 'hits' to '(none)': '(none)' is not a valid integer");
}
@Test
@@ -300,7 +292,7 @@ public class QueryTestCase {
@Test
@Ignore
public void testPrivateUseCharacterParsing() {
- Query query=newQuery("?query=%EF%89%AB");
+ Query query = newQuery("?query=%EF%89%AB");
assertEquals(Character.UnicodeBlock.PRIVATE_USE_AREA,
Character.UnicodeBlock.of(query.getModel().getQueryTree().getRoot().toString().charAt(0)));
}
@@ -309,7 +301,7 @@ public class QueryTestCase {
@Test
@Ignore
public void testOtherCharactersParsing() {
- Query query=newQuery(com.yahoo.search.test.QueryTestCase.httpEncode("?query=\u3007\u2e80\u2eff\u2ed0"));
+ 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)));
assertEquals(Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT,
@@ -374,13 +366,13 @@ public class QueryTestCase {
return query;
}
- private void assertQueryError(final String queryString, final Matcher<String> expectedErrorMessage) {
+ private void assertQueryError(String queryString, String expectedErrorMessage) {
try {
newQuery(queryString);
fail("Above statement should throw");
} catch (IllegalArgumentException e) {
// As expected.
- assertThat(Exceptions.toMessageString(e), expectedErrorMessage);
+ assertEquals(expectedErrorMessage, Exceptions.toMessageString(e));
}
}
diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/LoadBalancerTest.java b/container-search/src/test/java/com/yahoo/search/dispatch/LoadBalancerTest.java
index 7254236319d..e95fbc366a6 100644
--- a/container-search/src/test/java/com/yahoo/search/dispatch/LoadBalancerTest.java
+++ b/container-search/src/test/java/com/yahoo/search/dispatch/LoadBalancerTest.java
@@ -16,11 +16,9 @@ import java.util.Optional;
import java.util.Random;
import static com.yahoo.search.dispatch.MockSearchCluster.createDispatchConfig;
-import static org.hamcrest.Matchers.closeTo;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
/**
* @author ollivir
@@ -37,7 +35,7 @@ public class LoadBalancerTest {
Group group = grp.orElseGet(() -> {
throw new AssertionFailedError("Expected a SearchCluster.Group");
});
- assertThat(group.nodes().size(), equalTo(1));
+ assertEquals(1, group.nodes().size());
}
@Test
@@ -51,7 +49,7 @@ public class LoadBalancerTest {
Group group = grp.orElseGet(() -> {
throw new AssertionFailedError("Expected a SearchCluster.Group");
});
- assertThat(group.nodes().size(), equalTo(1));
+ assertEquals(1, group.nodes().size());
}
@Test
@@ -64,7 +62,7 @@ public class LoadBalancerTest {
LoadBalancer lb = new LoadBalancer(cluster, true);
Optional<Group> grp = lb.takeGroup(null);
- assertThat(grp.isPresent(), is(true));
+ assertTrue(grp.isPresent());
}
@Test
@@ -84,36 +82,36 @@ public class LoadBalancerTest {
// get second group
grp = lb.takeGroup(null);
group = grp.get();
- assertThat(group.id(), not(equalTo(id1)));
+ assertNotEquals(id1, group.id());
}
@Test
public void requireCorrectAverageSearchTimeDecay() {
- final double SMALL = 0.00001;
+ final double delta = 0.00001;
GroupStatus gs = newGroupStatus(1);
gs.setQueryStatistics(0, 1.0);
updateSearchTime(gs, 1.0);
- assertThat(gs.averageSearchTime(), equalTo(1.0));
+ assertEquals(1.0, gs.averageSearchTime(), delta);
updateSearchTime(gs, 2.0);
- assertThat(gs.averageSearchTime(), closeTo(1.02326, SMALL));
+ assertEquals(1.02326, gs.averageSearchTime(), delta);
updateSearchTime(gs, 2.0);
- assertThat(gs.averageSearchTime(), closeTo(1.04545, SMALL));
+ assertEquals(1.04545, gs.averageSearchTime(), delta);
updateSearchTime(gs, 0.1);
updateSearchTime(gs, 0.1);
updateSearchTime(gs, 0.1);
updateSearchTime(gs, 0.1);
- assertThat(gs.averageSearchTime(), closeTo(0.966667, SMALL));
+ assertEquals(0.966667, gs.averageSearchTime(), delta);
for (int i = 0; i < 10000; i++) {
updateSearchTime(gs, 1.0);
}
- assertThat(gs.averageSearchTime(), closeTo(1.0, SMALL));
+ assertEquals(1.0, gs.averageSearchTime(), delta);
updateSearchTime(gs, 0.1);
- assertThat(gs.averageSearchTime(), closeTo(0.9991, SMALL));
+ assertEquals(0.9991, gs.averageSearchTime(), delta);
for (int i = 0; i < 10000; i++) {
updateSearchTime(gs, 0.0);
}
- assertThat(gs.averageSearchTime(), closeTo(0.001045, SMALL));
+ assertEquals(0.001045, gs.averageSearchTime(), delta);
}
@Test
@@ -125,14 +123,14 @@ public class LoadBalancerTest {
Random seq = sequence(0.0, 0.1, 0.2, 0.39, 0.4, 0.6, 0.8, 0.99999);
AdaptiveScheduler sched = new AdaptiveScheduler(seq, scoreboard);
- assertThat(sched.takeNextGroup(null).get().groupId(), equalTo(0));
- assertThat(sched.takeNextGroup(null).get().groupId(), equalTo(0));
- assertThat(sched.takeNextGroup(null).get().groupId(), equalTo(1));
- assertThat(sched.takeNextGroup(null).get().groupId(), equalTo(1));
- assertThat(sched.takeNextGroup(null).get().groupId(), equalTo(2));
- assertThat(sched.takeNextGroup(null).get().groupId(), equalTo(3));
- assertThat(sched.takeNextGroup(null).get().groupId(), equalTo(4));
- assertThat(sched.takeNextGroup(null).get().groupId(), equalTo(4));
+ assertEquals(0, sched.takeNextGroup(null).get().groupId());
+ assertEquals(0, sched.takeNextGroup(null).get().groupId());
+ assertEquals(1, sched.takeNextGroup(null).get().groupId());
+ assertEquals(1, sched.takeNextGroup(null).get().groupId());
+ assertEquals(2, sched.takeNextGroup(null).get().groupId());
+ assertEquals(3, sched.takeNextGroup(null).get().groupId());
+ assertEquals(4, sched.takeNextGroup(null).get().groupId());
+ assertEquals(4, sched.takeNextGroup(null).get().groupId());
}
@Test
@@ -146,15 +144,15 @@ public class LoadBalancerTest {
Random seq = sequence(0.0, 0.4379, 0.4380, 0.6569, 0.6570, 0.8029, 0.8030, 0.9124, 0.9125);
AdaptiveScheduler sched = new AdaptiveScheduler(seq, scoreboard);
- assertThat(sched.takeNextGroup(null).get().groupId(), equalTo(0));
- assertThat(sched.takeNextGroup(null).get().groupId(), equalTo(0));
- assertThat(sched.takeNextGroup(null).get().groupId(), equalTo(1));
- assertThat(sched.takeNextGroup(null).get().groupId(), equalTo(1));
- assertThat(sched.takeNextGroup(null).get().groupId(), equalTo(2));
- assertThat(sched.takeNextGroup(null).get().groupId(), equalTo(2));
- assertThat(sched.takeNextGroup(null).get().groupId(), equalTo(3));
- assertThat(sched.takeNextGroup(null).get().groupId(), equalTo(3));
- assertThat(sched.takeNextGroup(null).get().groupId(), equalTo(4));
+ assertEquals(0, sched.takeNextGroup(null).get().groupId());
+ assertEquals(0, sched.takeNextGroup(null).get().groupId());
+ assertEquals(1, sched.takeNextGroup(null).get().groupId());
+ assertEquals(1, sched.takeNextGroup(null).get().groupId());
+ assertEquals(2, sched.takeNextGroup(null).get().groupId());
+ assertEquals(2, sched.takeNextGroup(null).get().groupId());
+ assertEquals(3, sched.takeNextGroup(null).get().groupId());
+ assertEquals(3, sched.takeNextGroup(null).get().groupId());
+ assertEquals(4, sched.takeNextGroup(null).get().groupId());
}
private static void updateSearchTime(GroupStatus gs, double time) {
@@ -187,4 +185,5 @@ public class LoadBalancerTest {
}
};
}
+
}
diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/SearchPathTest.java b/container-search/src/test/java/com/yahoo/search/dispatch/SearchPathTest.java
index 0366d4873e0..3a1a60df7af 100644
--- a/container-search/src/test/java/com/yahoo/search/dispatch/SearchPathTest.java
+++ b/container-search/src/test/java/com/yahoo/search/dispatch/SearchPathTest.java
@@ -3,9 +3,7 @@ package com.yahoo.search.dispatch;
import com.yahoo.search.dispatch.SearchPath.InvalidSearchPathException;
import com.yahoo.search.dispatch.searchcluster.Node;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import java.util.Collection;
import java.util.Set;
@@ -14,6 +12,7 @@ import java.util.stream.Collectors;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* @author ollivir
@@ -52,28 +51,40 @@ public class SearchPathTest {
assertFalse(SearchPath.fromString("//").isPresent());
}
- @Rule
- public final ExpectedException exception = ExpectedException.none();
-
@Test
public void invalidRangeMustThrowException() {
- exception.expect(InvalidSearchPathException.class);
- SearchPath.fromString("[p,0>/0");
+ try {
+ SearchPath.fromString("[p,0>/0");
+ fail("Expected exception");
+ }
+ catch (InvalidSearchPathException e) {
+ // success
+ }
}
@Test
public void invalidPartMustThrowException() {
- exception.expect(InvalidSearchPathException.class);
- SearchPath.fromString("p/0");
+ try {
+ SearchPath.fromString("p/0");
+ fail("Expected exception");
+ }
+ catch (InvalidSearchPathException e) {
+ // success
+ }
}
@Test
public void invalidRowMustThrowException() {
- exception.expect(InvalidSearchPathException.class);
- SearchPath.fromString("1,2,3/r");
+ try {
+ SearchPath.fromString("1,2,3/r");
+ fail("Expected exception");
+ }
+ catch (InvalidSearchPathException e) {
+ // success
+ }
}
- private void verifyRandomGroup(MockSearchCluster cluster, String searchPath, Set possibleSolutions) {
+ private void verifyRandomGroup(MockSearchCluster cluster, String searchPath, Set<?> possibleSolutions) {
for (int i=0; i < 100; i++) {
String nodes = distKeysAsString(SearchPath.selectNodes(searchPath, cluster));
assertTrue(possibleSolutions.contains(nodes));
diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/rpc/ProtobufSerializationTest.java b/container-search/src/test/java/com/yahoo/search/dispatch/rpc/ProtobufSerializationTest.java
index 0d67c4d6ddc..0867366303b 100644
--- a/container-search/src/test/java/com/yahoo/search/dispatch/rpc/ProtobufSerializationTest.java
+++ b/container-search/src/test/java/com/yahoo/search/dispatch/rpc/ProtobufSerializationTest.java
@@ -16,10 +16,8 @@ import java.io.IOException;
import java.util.Collections;
import java.util.List;
-import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/**
@@ -37,7 +35,7 @@ public class ProtobufSerializationTest {
hit.setGlobalId(new GlobalId(IdString.createIdString("id:ns:type::id")).getRawId());
var bytes = ProtobufSerialization.serializeDocsumRequest(builder, Collections.singletonList(hit));
- assertThat(bytes.length, equalTo(41));
+ assertEquals(41, bytes.length);
}
SearchProtocol.SearchReply createSearchReply(int numHits, boolean useSorting) {
diff --git a/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SearchChainResolverTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SearchChainResolverTestCase.java
index 2d7e1c0ab5c..34224721487 100644
--- a/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SearchChainResolverTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SearchChainResolverTestCase.java
@@ -16,9 +16,8 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.SortedSet;
-import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
/**
@@ -55,11 +54,11 @@ public class SearchChainResolverTestCase {
@Test
public void check_default_search_chains() {
- assertThat(searchChainResolver.defaultTargets().size(), is(2));
+ assertEquals(2, searchChainResolver.defaultTargets().size());
Iterator<Target> iterator = searchChainResolver.defaultTargets().iterator();
- assertThat(iterator.next().searchRefDescription(), is(searchChainId.toString()));
- assertThat(iterator.next().searchRefDescription(), is(sourceChainInProviderId.toString()));
+ assertEquals(searchChainId.toString(), iterator.next().searchRefDescription());
+ assertEquals(sourceChainInProviderId.toString(), iterator.next().searchRefDescription());
}
@Test
@@ -68,22 +67,22 @@ public class SearchChainResolverTestCase {
resolve("no-such-source");
fail("Expected exception.");
} catch (UnresolvedSearchChainException e) {
- assertThat(e.getMessage(), is("Could not resolve source ref 'no-such-source'."));
+ assertEquals("Could not resolve source ref 'no-such-source'.", e.getMessage());
}
}
@Test
public void lookup_search_chain() throws Exception {
SearchChainInvocationSpec res = resolve(searchChainId.getName());
- assertThat(res.searchChainId, is(searchChainId));
+ assertEquals(searchChainId, res.searchChainId);
}
//TODO: TVT: @Test()
public void lookup_provider() throws Exception {
SearchChainInvocationSpec res = resolve(providerId.getName());
- assertThat(res.provider, is(providerId));
+ assertEquals(providerId, res.provider);
assertNull(res.source);
- assertThat(res.searchChainId, is(providerId));
+ assertEquals(providerId, res.searchChainId);
}
@Test
@@ -99,23 +98,23 @@ public class SearchChainResolverTestCase {
}
private void assertIsSourceInProvider(SearchChainInvocationSpec res) {
- assertThat(res.provider, is(providerId));
- assertThat(res.source, is(sourceId));
- assertThat(res.searchChainId, is(sourceChainInProviderId));
+ assertEquals(providerId, res.provider);
+ assertEquals(sourceId, res.source);
+ assertEquals(sourceChainInProviderId, res.searchChainId);
}
@Test
public void lookup_source_for_provider2() throws Exception {
SearchChainInvocationSpec res = resolve(sourceId.getName(), provider2Id.getName());
- assertThat(res.provider, is(provider2Id));
- assertThat(res.source, is(sourceId));
- assertThat(res.searchChainId, is(sourceChainInProvider2Id));
+ assertEquals(provider2Id, res.provider);
+ assertEquals(sourceId, res.source);
+ assertEquals(sourceChainInProvider2Id, res.searchChainId);
}
@Test
public void lists_source_ref_description_for_top_level_targets() {
SortedSet<Target> topLevelTargets = searchChainResolver.allTopLevelTargets();
- assertThat(topLevelTargets.size(), is(3));
+ assertEquals(3, topLevelTargets.size());
Iterator<Target> i = topLevelTargets.iterator();
assertSearchRefDescriptionIs(i.next(), providerId.toString());
@@ -124,7 +123,7 @@ public class SearchChainResolverTestCase {
}
private void assertSearchRefDescriptionIs(Target target, String expected) {
- assertThat(target.searchRefDescription(), is(expected));
+ assertEquals(expected, target.searchRefDescription());
}
static Properties emptySourceToProviderMap() {
@@ -146,7 +145,7 @@ public class SearchChainResolverTestCase {
throws UnresolvedSearchChainException {
SearchChainInvocationSpec res = searchChainResolver.resolve(
ComponentSpecification.fromString(sourceSpecification), sourceToProviderMap);
- assertThat(res.federationOptions, is(federationOptions));
+ assertEquals(federationOptions, res.federationOptions);
return res;
}
diff --git a/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SourceRefResolverTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SourceRefResolverTestCase.java
index 27412eb6c3f..acb68175921 100644
--- a/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SourceRefResolverTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SourceRefResolverTestCase.java
@@ -13,25 +13,23 @@ import com.yahoo.search.searchchain.model.federation.FederationOptions;
import org.junit.Test;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.TreeMap;
import static com.yahoo.search.federation.sourceref.test.SearchChainResolverTestCase.emptySourceToProviderMap;
-import static org.hamcrest.CoreMatchers.hasItem;
-import static org.hamcrest.CoreMatchers.hasItems;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-
/**
* Test for SourceRefResolver.
+ *
* @author Tony Vaagenes
*/
public class SourceRefResolverTestCase {
+
private static final String cluster1 = "cluster1";
private static final String cluster2 = "cluster2";
private static final String cluster3 = "cluster3";
@@ -55,29 +53,29 @@ public class SourceRefResolverTestCase {
private static void setupIndexFacts() {
TreeMap<String, List<String>> masterClusters = new TreeMap<>();
- masterClusters.put(cluster1, Arrays.asList("document1", "document2"));
- masterClusters.put(cluster2, Arrays.asList("document1"));
- masterClusters.put(cluster3, Arrays.asList("document3"));
+ masterClusters.put(cluster1, List.of("document1", "document2"));
+ masterClusters.put(cluster2, List.of("document1"));
+ masterClusters.put(cluster3, List.of("document3"));
indexFacts = new IndexFacts(new IndexModel(masterClusters, Collections.emptyList()));
}
@Test
public void check_test_assumptions() {
- assertThat(indexFacts.clustersHavingSearchDefinition("document1"), hasItems("cluster1", "cluster2"));
+ assertTrue(indexFacts.clustersHavingSearchDefinition("document1").containsAll(List.of("cluster1", "cluster2")));
}
@Test
public void lookup_search_chain() throws Exception {
Set<SearchChainInvocationSpec> searchChains = resolve(cluster1);
- assertThat(searchChains.size(), is(1));
- assertThat(searchChainIds(searchChains), hasItem(cluster1));
+ assertEquals(1, searchChains.size());
+ assertTrue(searchChainIds(searchChains).contains(cluster1));
}
@Test
public void lookup_search_chains_for_document1() throws Exception {
Set<SearchChainInvocationSpec> searchChains = resolve("document1");
- assertThat(searchChains.size(), is(2));
- assertThat(searchChainIds(searchChains), hasItems(cluster1, cluster2));
+ assertEquals(2, searchChains.size());
+ assertTrue(searchChainIds(searchChains).containsAll(List.of(cluster1, cluster2)));
}
@Test
@@ -86,8 +84,9 @@ public class SourceRefResolverTestCase {
resolve("document3");
fail("Expected exception");
} catch (UnresolvedSearchChainException e) {
- assertThat(e.getMessage(), is("Failed to resolve cluster search chain 'cluster3' " +
- "when using source ref 'document3' as a document name."));
+ assertEquals("Failed to resolve cluster search chain 'cluster3' " +
+ "when using source ref 'document3' as a document name.",
+ e.getMessage());
}
}
@@ -97,7 +96,7 @@ public class SourceRefResolverTestCase {
resolve("document4");
fail("Expected exception");
} catch (UnresolvedSearchChainException e) {
- assertThat(e.getMessage(), is("Could not resolve source ref 'document4'."));
+ assertEquals("Could not resolve source ref 'document4'.", e.getMessage());
}
}
@@ -112,4 +111,5 @@ public class SourceRefResolverTestCase {
private Set<SearchChainInvocationSpec> resolve(String documentName) throws UnresolvedSearchChainException {
return sourceRefResolver.resolve(ComponentSpecification.fromString(documentName), emptySourceToProviderMap(), indexFacts);
}
+
}
diff --git a/container-search/src/test/java/com/yahoo/search/grouping/GroupingValidatorTestCase.java b/container-search/src/test/java/com/yahoo/search/grouping/GroupingValidatorTestCase.java
index 8f757a0dd49..4f473b29918 100644
--- a/container-search/src/test/java/com/yahoo/search/grouping/GroupingValidatorTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/grouping/GroupingValidatorTestCase.java
@@ -7,117 +7,142 @@ import com.yahoo.search.Query;
import com.yahoo.search.config.ClusterConfig;
import com.yahoo.search.grouping.request.GroupingOperation;
import com.yahoo.search.searchchain.Execution;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import java.util.Arrays;
import java.util.Collection;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* @author Simon Thoresen Hult
*/
public class GroupingValidatorTestCase {
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
@Test
public void requireThatAvailableAttributesDoNotThrow() {
- validateGrouping(Arrays.asList("foo", "bar"),
+ validateGrouping(List.of("foo", "bar"),
"all(group(foo) each(output(max(bar))))");;
}
@Test
public void requireThatUnavailableAttributesThrow() {
- thrown.expect(UnavailableAttributeException.class);
- thrown.expectMessage(createMessage("bar"));
- validateGrouping(Arrays.asList("foo"),
- "all(group(foo) each(output(max(bar))))");
+ try {
+ validateGrouping(List.of("foo"), "all(group(foo) each(output(max(bar))))");
+ fail("Excpected exception");
+ }
+ catch (UnavailableAttributeException e) {
+ assertEquals(createMessage("bar"), e.getMessage());
+ }
}
@Test
public void requireThatEnableFlagPreventsThrow() {
Query query = createQuery("all(group(foo) each(output(max(bar))))");
query.properties().set(GroupingValidator.PARAM_ENABLED, "false");
- validateGrouping(Arrays.asList("foo"), query);
+ validateGrouping(List.of("foo"), query);
}
@Test
public void available_primitive_map_attribute_does_not_throw() {
- validateGrouping(Arrays.asList("map.key", "map.value"),
+ validateGrouping(List.of("map.key", "map.value"),
"all(group(map{\"foo\"}) each(output(count())))");
}
@Test
public void unavailable_primitive_map_key_attribute_throws() {
- thrown.expect(UnavailableAttributeException.class);
- thrown.expectMessage(createMessage("map.key"));
- validateGrouping(Arrays.asList("null"),
- "all(group(map{\"foo\"}) each(output(count())))");
+ try {
+ validateGrouping(List.of("null"), "all(group(map{\"foo\"}) each(output(count())))");
+ fail("Expected exception");
+ }
+ catch (UnavailableAttributeException e) {
+ assertEquals(createMessage("map.key"), e.getMessage());
+ }
}
@Test
public void unavailable_primitive_map_value_attribute_throws() {
- thrown.expect(UnavailableAttributeException.class);
- thrown.expectMessage(createMessage("map.value"));
- validateGrouping(Arrays.asList("map.key"),
- "all(group(map{\"foo\"}) each(output(count())))");
+ try {
+ validateGrouping(List.of("map.key"), "all(group(map{\"foo\"}) each(output(count())))");
+ fail("Expected exception");
+ }
+ catch (UnavailableAttributeException e) {
+ assertEquals(createMessage("map.value"), e.getMessage());
+ }
}
@Test
public void available_struct_map_attribute_does_not_throw() {
- validateGrouping(Arrays.asList("map.key", "map.value.name"),
+ validateGrouping(List.of("map.key", "map.value.name"),
"all(group(map{\"foo\"}.name) each(output(count())))");
}
@Test
public void unavailable_struct_map_key_attribute_throws() {
- thrown.expect(UnavailableAttributeException.class);
- thrown.expectMessage(createMessage("map.key"));
- validateGrouping(Arrays.asList("null"),
- "all(group(map{\"foo\"}.name) each(output(count())))");
+ try {
+ validateGrouping(List.of("null"), "all(group(map{\"foo\"}.name) each(output(count())))");
+ fail("Expected exception");
+ }
+ catch (UnavailableAttributeException e) {
+ assertEquals(createMessage("map.key"), e.getMessage());
+ }
}
@Test
public void unavailable_struct_map_value_attribute_throws() {
- thrown.expect(UnavailableAttributeException.class);
- thrown.expectMessage(createMessage("map.value.name"));
- validateGrouping(Arrays.asList("map.key"),
- "all(group(map{\"foo\"}.name) each(output(count())))");
+ try {
+ validateGrouping(List.of("map.key"), "all(group(map{\"foo\"}.name) each(output(count())))");
+ fail("Expected exception");
+ }
+ catch (UnavailableAttributeException e) {
+ assertEquals(createMessage("map.value.name"), e.getMessage());
+ }
}
@Test
public void available_key_source_attribute_does_not_throw() {
- validateGrouping(Arrays.asList("map.key", "map.value", "key_source"),
+ validateGrouping(List.of("map.key", "map.value", "key_source"),
"all(group(map{attribute(key_source)}) each(output(count())))");
}
@Test
public void unavailable_key_source_attribute_throws() {
- thrown.expect(UnavailableAttributeException.class);
- thrown.expectMessage(createMessage("key_source"));
- validateGrouping(Arrays.asList("map.key", "map.value"),
- "all(group(map{attribute(key_source)}) each(output(count())))");
+ try {
+ validateGrouping(List.of("map.key", "map.value"),
+ "all(group(map{attribute(key_source)}) each(output(count())))");
+ fail("Expected exception");
+ }
+ catch (UnavailableAttributeException e) {
+ assertEquals(createMessage("key_source"), e.getMessage());
+ }
}
@Test
public void key_source_attribute_with_mismatching_data_type_throws() {
- thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Grouping request references key source attribute 'key_source' with data type 'INT32' " +
- "that is different than data type 'STRING' of key attribute 'map.key'");
-
- validateGrouping(setupMismatchingKeySourceAttribute(false),
- "all(group(map{attribute(key_source)}) each(output(count())))");
+ try {
+ validateGrouping(setupMismatchingKeySourceAttribute(false),
+ "all(group(map{attribute(key_source)}) each(output(count())))");
+ fail("Expected exception");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("Grouping request references key source attribute 'key_source' with data type 'INT32' " +
+ "that is different than data type 'STRING' of key attribute 'map.key'",
+ e.getMessage());
+ }
}
@Test
public void key_source_attribute_with_multi_value_collection_type_throws() {
- thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Grouping request references key source attribute 'key_source' which is not of single value type");
-
- validateGrouping(setupMismatchingKeySourceAttribute(true),
- "all(group(map{attribute(key_source)}) each(output(count())))");
+ try {
+ validateGrouping(setupMismatchingKeySourceAttribute(true),
+ "all(group(map{attribute(key_source)}) each(output(count())))");
+ fail("Expected exception");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("Grouping request references key source attribute 'key_source' which is not of single value type",
+ e.getMessage());
+ }
}
private static AttributesConfig setupMismatchingKeySourceAttribute(boolean matchingDataType) {
diff --git a/container-search/src/test/java/com/yahoo/search/grouping/UniqueGroupingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/grouping/UniqueGroupingSearcherTestCase.java
index c5b608db4e2..3b95e44ad70 100644
--- a/container-search/src/test/java/com/yahoo/search/grouping/UniqueGroupingSearcherTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/grouping/UniqueGroupingSearcherTestCase.java
@@ -20,6 +20,7 @@ import org.junit.Test;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
@@ -49,11 +50,9 @@ public class UniqueGroupingSearcherTestCase {
fail("Above statement should throw");
} catch (IllegalArgumentException e) {
// As expected.
- assertThat(
- Exceptions.toMessageString(e),
- containsString(
- "Could not set 'ranking.sorting' to '-1': " +
- "Illegal attribute name '1' for sorting. Requires '[\\[]*[a-zA-Z_][\\.a-zA-Z0-9_-]*[\\]]*'"));
+ assertTrue(Exceptions.toMessageString(e).contains("Could not set 'ranking.sorting' to '-1': " +
+ "Illegal attribute name '1' for sorting. " +
+ "Requires '[\\[]*[a-zA-Z_][\\.a-zA-Z0-9_-]*[\\]]*'"));
}
}
diff --git a/container-search/src/test/java/com/yahoo/search/grouping/request/MathFunctionsTestCase.java b/container-search/src/test/java/com/yahoo/search/grouping/request/MathFunctionsTestCase.java
index 522e72d31b9..d22c2dee7b6 100644
--- a/container-search/src/test/java/com/yahoo/search/grouping/request/MathFunctionsTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/grouping/request/MathFunctionsTestCase.java
@@ -3,65 +3,63 @@ package com.yahoo.search.grouping.request;
import org.junit.Test;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.sameInstance;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
/**
- * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
- * @since 5.1.9
+ * @author Einar M R Rosenvinge
*/
public class MathFunctionsTestCase {
+
@Test
public void testMathFunctions() {
//if this fails, update the count AND add a test in each of the two blocks below
- assertThat(MathFunctions.Function.values().length, is(21));
+ assertEquals(21, MathFunctions.Function.values().length);
+ assertSame(MathFunctions.Function.create(0), MathFunctions.Function.EXP);
+ assertSame(MathFunctions.Function.create(1), MathFunctions.Function.POW);
+ assertSame(MathFunctions.Function.create(2), MathFunctions.Function.LOG);
+ assertSame(MathFunctions.Function.create(3), MathFunctions.Function.LOG1P);
+ assertSame(MathFunctions.Function.create(4), MathFunctions.Function.LOG10);
+ assertSame(MathFunctions.Function.create(5), MathFunctions.Function.SIN);
+ assertSame(MathFunctions.Function.create(6), MathFunctions.Function.ASIN);
+ assertSame(MathFunctions.Function.create(7), MathFunctions.Function.COS);
+ assertSame(MathFunctions.Function.create(8), MathFunctions.Function.ACOS);
+ assertSame(MathFunctions.Function.create(9), MathFunctions.Function.TAN);
+ assertSame(MathFunctions.Function.create(10), MathFunctions.Function.ATAN);
+ assertSame(MathFunctions.Function.create(11), MathFunctions.Function.SQRT);
+ assertSame(MathFunctions.Function.create(12), MathFunctions.Function.SINH);
+ assertSame(MathFunctions.Function.create(13), MathFunctions.Function.ASINH);
+ assertSame(MathFunctions.Function.create(14), MathFunctions.Function.COSH);
+ assertSame(MathFunctions.Function.create(15), MathFunctions.Function.ACOSH);
+ assertSame(MathFunctions.Function.create(16), MathFunctions.Function.TANH);
+ assertSame(MathFunctions.Function.create(17), MathFunctions.Function.ATANH);
+ assertSame(MathFunctions.Function.create(18), MathFunctions.Function.CBRT);
+ assertSame(MathFunctions.Function.create(19), MathFunctions.Function.HYPOT);
+ assertSame(MathFunctions.Function.create(20), MathFunctions.Function.FLOOR);
- assertThat(MathFunctions.Function.create(0), sameInstance(MathFunctions.Function.EXP));
- assertThat(MathFunctions.Function.create(1), sameInstance(MathFunctions.Function.POW));
- assertThat(MathFunctions.Function.create(2), sameInstance(MathFunctions.Function.LOG));
- assertThat(MathFunctions.Function.create(3), sameInstance(MathFunctions.Function.LOG1P));
- assertThat(MathFunctions.Function.create(4), sameInstance(MathFunctions.Function.LOG10));
- assertThat(MathFunctions.Function.create(5), sameInstance(MathFunctions.Function.SIN));
- assertThat(MathFunctions.Function.create(6), sameInstance(MathFunctions.Function.ASIN));
- assertThat(MathFunctions.Function.create(7), sameInstance(MathFunctions.Function.COS));
- assertThat(MathFunctions.Function.create(8), sameInstance(MathFunctions.Function.ACOS));
- assertThat(MathFunctions.Function.create(9), sameInstance(MathFunctions.Function.TAN));
- assertThat(MathFunctions.Function.create(10), sameInstance(MathFunctions.Function.ATAN));
- assertThat(MathFunctions.Function.create(11), sameInstance(MathFunctions.Function.SQRT));
- assertThat(MathFunctions.Function.create(12), sameInstance(MathFunctions.Function.SINH));
- assertThat(MathFunctions.Function.create(13), sameInstance(MathFunctions.Function.ASINH));
- assertThat(MathFunctions.Function.create(14), sameInstance(MathFunctions.Function.COSH));
- assertThat(MathFunctions.Function.create(15), sameInstance(MathFunctions.Function.ACOSH));
- assertThat(MathFunctions.Function.create(16), sameInstance(MathFunctions.Function.TANH));
- assertThat(MathFunctions.Function.create(17), sameInstance(MathFunctions.Function.ATANH));
- assertThat(MathFunctions.Function.create(18), sameInstance(MathFunctions.Function.CBRT));
- assertThat(MathFunctions.Function.create(19), sameInstance(MathFunctions.Function.HYPOT));
- assertThat(MathFunctions.Function.create(20), sameInstance(MathFunctions.Function.FLOOR));
-
-
- assertThat(MathFunctions.newInstance(MathFunctions.Function.EXP, null, null), instanceOf(MathExpFunction.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.POW, null, null), instanceOf(MathPowFunction.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.LOG, null, null), instanceOf(MathLogFunction.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.LOG1P, null, null), instanceOf(MathLog1pFunction.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.LOG10, null, null), instanceOf(MathLog10Function.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.SIN, null, null), instanceOf(MathSinFunction.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.ASIN, null, null), instanceOf(MathASinFunction.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.COS, null, null), instanceOf(MathCosFunction.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.ACOS, null, null), instanceOf(MathACosFunction.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.TAN, null, null), instanceOf(MathTanFunction.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.ATAN, null, null), instanceOf(MathATanFunction.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.SQRT, null, null), instanceOf(MathSqrtFunction.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.SINH, null, null), instanceOf(MathSinHFunction.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.ASINH, null, null), instanceOf(MathASinHFunction.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.COSH, null, null), instanceOf(MathCosHFunction.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.ACOSH, null, null), instanceOf(MathACosHFunction.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.TANH, null, null), instanceOf(MathTanHFunction.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.ATANH, null, null), instanceOf(MathATanHFunction.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.CBRT, null, null), instanceOf(MathCbrtFunction.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.HYPOT, null, null), instanceOf(MathHypotFunction.class));
- assertThat(MathFunctions.newInstance(MathFunctions.Function.FLOOR, null, null), instanceOf(MathFloorFunction.class));
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.EXP, null, null) instanceof MathExpFunction);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.POW, null, null) instanceof MathPowFunction);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.LOG, null, null) instanceof MathLogFunction);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.LOG1P, null, null) instanceof MathLog1pFunction);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.LOG10, null, null) instanceof MathLog10Function);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.SIN, null, null) instanceof MathSinFunction);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.ASIN, null, null) instanceof MathASinFunction);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.COS, null, null) instanceof MathCosFunction);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.ACOS, null, null) instanceof MathACosFunction);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.TAN, null, null) instanceof MathTanFunction);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.ATAN, null, null) instanceof MathATanFunction);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.SQRT, null, null) instanceof MathSqrtFunction);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.SINH, null, null) instanceof MathSinHFunction);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.ASINH, null, null) instanceof MathASinHFunction);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.COSH, null, null) instanceof MathCosHFunction);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.ACOSH, null, null) instanceof MathACosHFunction);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.TANH, null, null) instanceof MathTanHFunction);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.ATANH, null, null) instanceof MathATanHFunction);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.CBRT, null, null) instanceof MathCbrtFunction);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.HYPOT, null, null) instanceof MathHypotFunction);
+ assertTrue(MathFunctions.newInstance(MathFunctions.Function.FLOOR, null, null) instanceof MathFloorFunction);
}
+
}
diff --git a/container-search/src/test/java/com/yahoo/search/handler/SearchHandlerTest.java b/container-search/src/test/java/com/yahoo/search/handler/SearchHandlerTest.java
index e1987aa50ca..b1354106f19 100644
--- a/container-search/src/test/java/com/yahoo/search/handler/SearchHandlerTest.java
+++ b/container-search/src/test/java/com/yahoo/search/handler/SearchHandlerTest.java
@@ -37,14 +37,11 @@ import java.net.URI;
import java.util.concurrent.Executors;
import static com.yahoo.yolean.Exceptions.uncheckInterrupted;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -222,9 +219,9 @@ public class SearchHandlerTest {
RequestHandlerTestDriver.MockResponseHandler responseHandler =
testDriver.sendRequest("http://localhost/search/?query=status_code%3A0&hits=20&offset=-20");
String response = responseHandler.readAll();
- assertThat(responseHandler.getStatus(), is(400));
- assertThat(response, containsString("offset"));
- assertThat(response, containsString("\"code\":" + com.yahoo.container.protect.Error.ILLEGAL_QUERY.code));
+ assertEquals(400, responseHandler.getStatus());
+ assertTrue(response.contains("offset"));
+ assertTrue(response.contains("\"code\":" + com.yahoo.container.protect.Error.ILLEGAL_QUERY.code));
}
@Test
@@ -246,7 +243,7 @@ public class SearchHandlerTest {
driver.sendRequest("http://localhost/search/?query=web_service_status_code");
String response = responseHandler.readAll();
assertEquals(406, responseHandler.getStatus());
- assertThat(response, containsString("\"code\":" + 406));
+ assertTrue(response.contains("\"code\":" + 406));
}
@Test
diff --git a/container-search/src/test/java/com/yahoo/search/handler/test/JSONSearchHandlerTestCase.java b/container-search/src/test/java/com/yahoo/search/handler/test/JSONSearchHandlerTestCase.java
index 48dfa98768a..7811336823d 100644
--- a/container-search/src/test/java/com/yahoo/search/handler/test/JSONSearchHandlerTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/handler/test/JSONSearchHandlerTestCase.java
@@ -31,13 +31,10 @@ import java.util.HashMap;
import java.util.Map;
import static com.yahoo.jdisc.http.HttpRequest.Method.GET;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/**
@@ -102,9 +99,9 @@ public class JSONSearchHandlerTestCase {
String json = "Not a valid JSON-string";
RequestHandlerTestDriver.MockResponseHandler responseHandler = driver.sendRequest(uri, com.yahoo.jdisc.http.HttpRequest.Method.POST, json, JSON_CONTENT_TYPE);
String response = responseHandler.readAll();
- assertThat(responseHandler.getStatus(), is(400));
- assertThat(response, containsString("errors"));
- assertThat(response, containsString("\"code\":" + Error.ILLEGAL_QUERY.code));
+ assertEquals(400, responseHandler.getStatus());
+ assertTrue(response.contains("errors"));
+ assertTrue(response.contains("\"code\":" + Error.ILLEGAL_QUERY.code));
}
@Test
@@ -158,7 +155,7 @@ public class JSONSearchHandlerTestCase {
json.put("yql", "selectz * from foo where bar > 1453501295");
RequestHandlerTestDriver.MockResponseHandler responseHandler = newDriver.sendRequest(uri, com.yahoo.jdisc.http.HttpRequest.Method.POST, json.toString(), JSON_CONTENT_TYPE);
responseHandler.readAll();
- assertThat(responseHandler.getStatus(), is(400));
+ assertEquals(400, responseHandler.getStatus());
}
}
@@ -178,9 +175,9 @@ public class JSONSearchHandlerTestCase {
RequestHandlerTestDriver.MockResponseHandler responseHandler =
testDriver.sendRequest(uri, com.yahoo.jdisc.http.HttpRequest.Method.POST, json.toString(), JSON_CONTENT_TYPE);
String response = responseHandler.readAll();
- assertThat(responseHandler.getStatus(), is(400));
- assertThat(response, containsString("offset"));
- assertThat(response, containsString("\"code\":" + com.yahoo.container.protect.Error.ILLEGAL_QUERY.code));
+ assertEquals(400, responseHandler.getStatus());
+ assertTrue(response.contains("offset"));
+ assertTrue(response.contains("\"code\":" + com.yahoo.container.protect.Error.ILLEGAL_QUERY.code));
}
@Test
@@ -212,8 +209,8 @@ public class JSONSearchHandlerTestCase {
RequestHandlerTestDriver.MockResponseHandler responseHandler =
driver.sendRequest(uri, com.yahoo.jdisc.http.HttpRequest.Method.POST, json.toString(), JSON_CONTENT_TYPE);
String response = responseHandler.readAll();
- assertThat(responseHandler.getStatus(), is(406));
- assertThat(response, containsString("\"code\":" + 406));
+ assertEquals(406, responseHandler.getStatus());
+ assertTrue(response.contains("\"code\":" + 406));
}
@Test
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NativePropertiesTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NativePropertiesTestCase.java
index 85015bee851..606d1fdd306 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NativePropertiesTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NativePropertiesTestCase.java
@@ -11,6 +11,7 @@ import org.junit.Test;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
@@ -39,9 +40,7 @@ public class NativePropertiesTestCase {
fail("Above statement should throw");
} catch (IllegalArgumentException e) {
// As expected.
- assertThat(
- Exceptions.toMessageString(e),
- containsString(
+ assertTrue(Exceptions.toMessageString(e).contains(
"Could not set 'notnative' to '5':"
+ " 'notnative' is not declared in query profile type 'strict', and the type is strict"));
}
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java
index 44e8147c09b..2e88c9fd0a4 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java
@@ -26,10 +26,8 @@ import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
-import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -96,13 +94,13 @@ public class QueryProfileTypeTestCase {
@Test
public void testTypedOfPrimitivesAssignmentNonStrict() {
- QueryProfile profile=new QueryProfile("test");
+ QueryProfile profile = new QueryProfile("test");
profile.setType(testtype);
registry.register(profile);
- profile.set("myString","anyValue", registry);
+ profile.set("myString", "anyValue", registry);
profile.set("nontypedString", "anyValueToo", registry); // legal because this is not strict
- assertWrongType(profile,"integer","myInteger","notInteger");
+ assertWrongType(profile,"integer", "myInteger","notInteger");
assertWrongType(profile, "integer", "myInteger", "1.5");
profile.set("myInteger", 3, registry);
assertWrongType(profile,"long","myLong","notLong");
@@ -137,7 +135,7 @@ public class QueryProfileTypeTestCase {
assertEquals("anyValueToo", properties.get("nontypedString"));
assertEquals(3, properties.get("myInteger"));
assertEquals(3, properties.get("Int"));
- assertEquals(4000000000000l, properties.get("myLong"));
+ assertEquals(4000000000000L, properties.get("myLong"));
assertEquals(3.14f, properties.get("myFloat"));
assertEquals(2.18, properties.get("myDouble"));
assertEquals(true, properties.get("myBoolean"));
@@ -163,7 +161,7 @@ public class QueryProfileTypeTestCase {
@Test
public void testTypedOfPrimitivesAssignmentStrict() {
- QueryProfile profile=new QueryProfile("test");
+ QueryProfile profile = new QueryProfile("test");
profile.setType(testtypeStrict);
profile.set("myString", "anyValue", registry);
@@ -173,13 +171,13 @@ public class QueryProfileTypeTestCase {
profile.set("myInteger", 3, registry);
assertWrongType(profile,"long","myLong","notLong");
assertWrongType(profile, "long", "myLong", "1.5");
- profile.set("myLong", 4000000000000l, registry);
+ profile.set("myLong", 4000000000000L, registry);
assertWrongType(profile, "float", "myFloat", "notFloat");
profile.set("myFloat", 3.14f, registry);
assertWrongType(profile, "double", "myDouble", "notDouble");
profile.set("myDouble",2.18, registry);
- profile.set("myQueryProfile.anyString","value1", registry);
- profile.set("myQueryProfile.anyDouble",8.76, registry);
+ profile.set("myQueryProfile.anyString", "value1", registry);
+ profile.set("myQueryProfile.anyDouble", 8.76, registry);
profile.set("myUserQueryProfile.myUserString", "value2", registry);
assertNotPermitted(profile, "myUserQueryProfile.anyString", "value3"); // Illegal because this is strict
assertWrongType(profile, "integer", "myUserQueryProfile.myUserInteger", "notInteger");
@@ -191,7 +189,7 @@ public class QueryProfileTypeTestCase {
assertEquals("anyValue", cprofile.get("myString"));
assertNull(cprofile.get("nontypedString"));
assertEquals(3, cprofile.get("myInteger"));
- assertEquals(4000000000000l, cprofile.get("myLong"));
+ assertEquals(4000000000000L, cprofile.get("myLong"));
assertEquals(3.14f, cprofile.get("myFloat"));
assertEquals(2.18, cprofile.get("myDouble"));
assertEquals("value1", cprofile.get("myQueryProfile.anyString"));
@@ -205,25 +203,25 @@ public class QueryProfileTypeTestCase {
/** Tests assigning a subprofile directly */
@Test
public void testTypedAssignmentOfQueryProfilesNonStrict() {
- QueryProfile profile=new QueryProfile("test");
+ QueryProfile profile = new QueryProfile("test");
profile.setType(testtype);
QueryProfile map1=new QueryProfile("myMap1");
- map1.set("key1","value1", registry);
+ map1.set("key1", "value1", registry);
QueryProfile map2=new QueryProfile("myMap2");
- map2.set("key2","value2", registry);
+ map2.set("key2", "value2", registry);
QueryProfile myUser=new QueryProfile("myUser");
myUser.setType(user);
- myUser.set("myUserString","userValue1", registry);
- myUser.set("myUserInteger",442, registry);
+ myUser.set("myUserString", "userValue1", registry);
+ myUser.set("myUserInteger", 442, registry);
assertWrongType(profile,"reference to a query profile","myQueryProfile","aString");
- profile.set("myQueryProfile",map1, registry);
- profile.set("someMap",map2, registry); // Legal because this is not strict
- assertWrongType(profile,"reference to a query profile of type 'user'","myUserQueryProfile",map1);
- profile.set("myUserQueryProfile",myUser, registry);
+ profile.set("myQueryProfile", map1, registry);
+ profile.set("someMap", map2, registry); // Legal because this is not strict
+ assertWrongType(profile, "reference to a query profile of type 'user'", "myUserQueryProfile", map1);
+ profile.set("myUserQueryProfile", myUser, registry);
CompiledQueryProfile cprofile = profile.compile(null);
@@ -236,25 +234,25 @@ public class QueryProfileTypeTestCase {
/** Tests assigning a subprofile directly */
@Test
public void testTypedAssignmentOfQueryProfilesStrict() {
- QueryProfile profile=new QueryProfile("test");
+ QueryProfile profile = new QueryProfile("test");
profile.setType(testtypeStrict);
QueryProfile map1=new QueryProfile("myMap1");
- map1.set("key1","value1", registry);
+ map1.set("key1", "value1", registry);
QueryProfile map2=new QueryProfile("myMap2");
- map2.set("key2","value2", registry);
+ map2.set("key2", "value2", registry);
- QueryProfile myUser=new QueryProfile("myUser");
+ QueryProfile myUser = new QueryProfile("myUser");
myUser.setType(userStrict);
- myUser.set("myUserString","userValue1", registry);
- myUser.set("myUserInteger",442, registry);
+ myUser.set("myUserString", "userValue1", registry);
+ myUser.set("myUserInteger", 442, registry);
assertWrongType(profile,"reference to a query profile","myQueryProfile","aString");
- profile.set("myQueryProfile",map1, registry);
- assertNotPermitted(profile,"someMap",map2);
- assertWrongType(profile,"reference to a query profile of type 'userStrict'","myUserQueryProfile",map1);
- profile.set("myUserQueryProfile",myUser, registry);
+ profile.set("myQueryProfile", map1, registry);
+ assertNotPermitted(profile,"someMap", map2);
+ assertWrongType(profile,"reference to a query profile of type 'userStrict'", "myUserQueryProfile", map1);
+ profile.set("myUserQueryProfile", myUser, registry);
CompiledQueryProfile cprofile = profile.compile(null);
@@ -271,15 +269,15 @@ public class QueryProfileTypeTestCase {
profile.setType(testtype);
QueryProfile map1 = new QueryProfile("myMap1");
- map1.set("key1","value1", registry);
+ map1.set("key1", "value1", registry);
QueryProfile map2 = new QueryProfile("myMap2");
- map2.set("key2","value2", registry);
+ map2.set("key2", "value2", registry);
QueryProfile myUser = new QueryProfile("myUser");
myUser.setType(user);
- myUser.set("myUserString","userValue1", registry);
- myUser.set("myUserInteger",442, registry);
+ myUser.set("myUserString", "userValue1", registry);
+ myUser.set("myUserInteger", 442, registry);
registry.register(profile);
registry.register(map1);
@@ -311,18 +309,18 @@ public class QueryProfileTypeTestCase {
*/
@Test
public void testTypedOverridingOfQueryProfileReferencesNonStrictThroughQuery() {
- QueryProfile profile=new QueryProfile("test");
+ QueryProfile profile = new QueryProfile("test");
profile.setType(testtype);
QueryProfile myUser=new QueryProfile("myUser");
myUser.setType(user);
- myUser.set("myUserString","userValue1", registry);
- myUser.set("myUserInteger",442, registry);
+ myUser.set("myUserString", "userValue1", registry);
+ myUser.set("myUserInteger", 442, registry);
- QueryProfile newUser=new QueryProfile("newUser");
+ QueryProfile newUser = new QueryProfile("newUser");
newUser.setType(user);
- newUser.set("myUserString","newUserValue1", registry);
- newUser.set("myUserInteger",845, registry);
+ newUser.set("myUserString", "newUserValue1", registry);
+ newUser.set("myUserInteger", 845, registry);
QueryProfileRegistry registry = new QueryProfileRegistry();
registry.register(profile);
@@ -331,7 +329,9 @@ public class QueryProfileTypeTestCase {
CompiledQueryProfileRegistry cRegistry = registry.compile();
CompiledQueryProfile cprofile = cRegistry.getComponent("test");
- Query query = new Query(HttpRequest.createTestRequest("?myUserQueryProfile=newUser", com.yahoo.jdisc.http.HttpRequest.Method.GET), cprofile);
+ Query query = new Query(HttpRequest.createTestRequest("?myUserQueryProfile=newUser",
+ com.yahoo.jdisc.http.HttpRequest.Method.GET),
+ cprofile);
assertEquals(0, query.errors().size());
@@ -500,8 +500,8 @@ public class QueryProfileTypeTestCase {
fail("Above statement should throw");
} catch (IllegalArgumentException e) {
// As expected.
- assertThat(Exceptions.toMessageString(e),
- containsString("Could not set 'myUserQueryProfile.nondeclared' to 'someValue': 'nondeclared' is not declared in query profile type 'userStrict', and the type is strict"));
+ assertTrue(Exceptions.toMessageString(e).contains(
+ "Could not set 'myUserQueryProfile.nondeclared' to 'someValue': 'nondeclared' is not declared in query profile type 'userStrict', and the type is strict"));
}
}
@@ -615,8 +615,8 @@ public class QueryProfileTypeTestCase {
fail("Above statement should throw");
} catch (IllegalArgumentException e) {
// As expected.
- assertThat(Exceptions.toMessageString(e),
- containsString("Could not set 'subMap.typeProfile.someValue' to 'value': 'someValue' is not declared in query profile type 'testtypeStrict', and the type is strict"));
+ assertTrue(Exceptions.toMessageString(e).contains(
+ "Could not set 'subMap.typeProfile.someValue' to 'value': 'someValue' is not declared in query profile type 'testtypeStrict', and the type is strict"));
}
}
diff --git a/container-search/src/test/java/com/yahoo/search/query/textserialize/item/test/ParseItemTestCase.java b/container-search/src/test/java/com/yahoo/search/query/textserialize/item/test/ParseItemTestCase.java
index 4da2edf8306..aa0d692ec92 100644
--- a/container-search/src/test/java/com/yahoo/search/query/textserialize/item/test/ParseItemTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/textserialize/item/test/ParseItemTestCase.java
@@ -1,7 +1,19 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query.textserialize.item.test;
-import com.yahoo.prelude.query.*;
+import com.yahoo.prelude.query.AndItem;
+import com.yahoo.prelude.query.ExactStringItem;
+import com.yahoo.prelude.query.IntItem;
+import com.yahoo.prelude.query.NearItem;
+import com.yahoo.prelude.query.NotItem;
+import com.yahoo.prelude.query.ONearItem;
+import com.yahoo.prelude.query.OrItem;
+import com.yahoo.prelude.query.PhraseItem;
+import com.yahoo.prelude.query.PrefixItem;
+import com.yahoo.prelude.query.RankItem;
+import com.yahoo.prelude.query.SubstringItem;
+import com.yahoo.prelude.query.SuffixItem;
+import com.yahoo.prelude.query.WordItem;
import com.yahoo.search.query.textserialize.item.ItemContext;
import com.yahoo.search.query.textserialize.item.ItemFormHandler;
import com.yahoo.search.query.textserialize.parser.ParseException;
@@ -10,10 +22,9 @@ import org.junit.Test;
import java.io.StringReader;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
/**
* @author Tony Vaagenes
@@ -29,50 +40,50 @@ public class ParseItemTestCase {
@Test
public void parse_and() throws ParseException {
- assertThat(parse("(AND)"), instanceOf(AndItem.class));
+ assertTrue(parse("(AND)") instanceof AndItem);
}
@Test
public void parse_and_with_children() throws ParseException {
AndItem andItem = (AndItem) parse("(AND (WORD 'first') (WORD 'second'))");
- assertThat(andItem.getItemCount(), is(2));
- assertThat(getWord(andItem.getItem(0)), is("first"));
+ assertEquals(2, andItem.getItemCount());
+ assertEquals("first", getWord(andItem.getItem(0)));
}
@Test
public void parse_or() throws ParseException {
- assertThat(parse("(OR)"), instanceOf(OrItem.class));
+ assertTrue(parse("(OR)") instanceof OrItem);
}
@Test
public void parse_and_not_rest() throws ParseException {
- assertThat(parse("(AND-NOT-REST)"), instanceOf(NotItem.class));
+ assertTrue(parse("(AND-NOT-REST)") instanceof NotItem);
}
@Test
public void parse_and_not_rest_with_children() throws ParseException {
NotItem notItem = (NotItem) parse("(AND-NOT-REST (WORD 'positive') (WORD 'negative'))");
- assertThat(getWord(notItem.getPositiveItem()), is("positive"));
- assertThat(getWord(notItem.getItem(1)), is("negative"));
+ assertEquals("positive", getWord(notItem.getPositiveItem()));
+ assertEquals("negative", getWord(notItem.getItem(1)));
}
@Test
public void parse_and_not_rest_with_only_negated_children() throws ParseException {
NotItem notItem = (NotItem) parse("(AND-NOT-REST null (WORD 'negated-item'))");
assertNull(notItem.getPositiveItem());
- assertThat(notItem.getItem(1), instanceOf(WordItem.class));
+ assertTrue(notItem.getItem(1) instanceof WordItem);
}
@Test
public void parse_rank() throws ParseException {
- assertThat(parse("(RANK (WORD 'first'))"), instanceOf(RankItem.class));
+ assertTrue(parse("(RANK (WORD 'first'))") instanceof RankItem);
}
@Test
public void parse_word() throws ParseException {
WordItem wordItem = (WordItem) parse("(WORD 'text')");
- assertThat(wordItem.getWord(), is("text"));
+ assertEquals("text", wordItem.getWord());
}
@Test(expected = IllegalArgumentException.class)
@@ -88,65 +99,65 @@ public class ParseItemTestCase {
@Test
public void parse_int() throws ParseException {
IntItem intItem = (IntItem) parse("(INT '[42;]')");
- assertThat(intItem.getNumber(), is("[42;]"));
+ assertEquals("[42;]", intItem.getNumber());
}
@Test
public void parse_range() throws ParseException {
IntItem intItem = (IntItem) parse("(INT '[42;73]')");
- assertThat(intItem.getNumber(), is("[42;73]"));
+ assertEquals("[42;73]", intItem.getNumber());
}
@Test
public void parse_range_withlimit() throws ParseException {
IntItem intItem = (IntItem) parse("(INT '[42;73;32]')");
- assertThat(intItem.getNumber(), is("[42;73;32]"));
+ assertEquals("[42;73;32]", intItem.getNumber());
}
@Test
public void parse_prefix() throws ParseException {
PrefixItem prefixItem = (PrefixItem) parse("(PREFIX 'word')");
- assertThat(prefixItem.getWord(), is("word"));
+ assertEquals("word", prefixItem.getWord());
}
@Test
public void parse_subString() throws ParseException {
SubstringItem subStringItem = (SubstringItem) parse("(SUBSTRING 'word')");
- assertThat(subStringItem.getWord(), is("word"));
+ assertEquals("word", subStringItem.getWord());
}
@Test
public void parse_exactString() throws ParseException {
ExactStringItem subStringItem = (ExactStringItem) parse("(EXACT 'word')");
- assertThat(subStringItem.getWord(), is("word"));
+ assertEquals("word", subStringItem.getWord());
}
@Test
public void parse_suffix() throws ParseException {
SuffixItem suffixItem = (SuffixItem) parse("(SUFFIX 'word')");
- assertThat(suffixItem.getWord(), is("word"));
+ assertEquals("word", suffixItem.getWord());
}
@Test
public void parse_phrase() throws ParseException {
PhraseItem phraseItem = (PhraseItem) parse("(PHRASE (WORD 'word'))");
- assertThat(phraseItem.getItem(0), instanceOf(WordItem.class));
+ assertTrue(phraseItem.getItem(0) instanceof WordItem);
}
@Test
public void parse_near() throws ParseException {
- assertThat(parse("(NEAR)"), instanceOf(NearItem.class));
+ assertTrue(parse("(NEAR)") instanceof NearItem);
}
@Test
public void parse_onear() throws ParseException {
- assertThat(parse("(ONEAR)"), instanceOf(ONearItem.class));
+ assertTrue(parse("(ONEAR)") instanceof ONearItem);
}
@Test
public void parse_near_with_distance() throws ParseException {
NearItem nearItem = (NearItem) parse("(NEAR {'distance' 42} (WORD 'first'))");
- assertThat(nearItem.getDistance(), is(42));
+ assertEquals(42, nearItem.getDistance());
}
@Test
@@ -154,23 +165,24 @@ public class ParseItemTestCase {
AndItem andItem = (AndItem) parse("(AND (WORD {'id' '1'} 'first') (WORD {'connectivity' ['1' 23.5]} 'second'))");
WordItem secondItem = (WordItem) andItem.getItem(1);
- assertThat(secondItem.getConnectedItem(), is(andItem.getItem(0)));
- assertThat(secondItem.getConnectivity(), is(23.5));
+ assertEquals(andItem.getItem(0), secondItem.getConnectedItem());
+ assertEquals(23.5, secondItem.getConnectivity(), 0.000001);
}
@Test
public void parse_word_with_index() throws ParseException {
WordItem wordItem = (WordItem) parse("(WORD {'index' 'someIndex'} 'text')");
- assertThat(wordItem.getIndexName(), is("someIndex"));
+ assertEquals("someIndex", wordItem.getIndexName());
}
@Test
public void parse_unicode_word() throws ParseException {
WordItem wordItem = (WordItem) parse("(WORD 'trăm')");
- assertThat(wordItem.getWord(), is("trăm"));
+ assertEquals("trăm", wordItem.getWord());
}
public static String getWord(Object item) {
return ((WordItem)item).getWord();
}
+
}
diff --git a/container-search/src/test/java/com/yahoo/search/query/textserialize/serializer/test/SerializeItemTestCase.java b/container-search/src/test/java/com/yahoo/search/query/textserialize/serializer/test/SerializeItemTestCase.java
index c73ec4db588..133382cbe91 100644
--- a/container-search/src/test/java/com/yahoo/search/query/textserialize/serializer/test/SerializeItemTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/textserialize/serializer/test/SerializeItemTestCase.java
@@ -15,44 +15,43 @@ import org.junit.Test;
import static com.yahoo.search.query.textserialize.item.test.ParseItemTestCase.parse;
import static com.yahoo.search.query.textserialize.item.test.ParseItemTestCase.getWord;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsInstanceOf.instanceOf;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
* @author Tony Vaagenes
*/
public class SerializeItemTestCase {
+
@Test
public void serialize_word_item() {
WordItem item = new WordItem("test that \" and \\ works");
item.setIndexName("index\"Name");
WordItem deSerialized = serializeThenParse(item);
- assertThat(deSerialized.getWord(), is(item.getWord()));
- assertThat(deSerialized.getIndexName(), is(item.getIndexName()));
+ assertEquals(item.getWord(), deSerialized.getWord());
+ assertEquals(item.getIndexName(), deSerialized.getIndexName());
}
@Test
- public void serialize_and_item() throws ParseException {
+ public void serialize_and_item() {
AndItem andItem = new AndItem();
andItem.addItem(new WordItem("first"));
andItem.addItem(new WordItem("second"));
AndItem deSerialized = serializeThenParse(andItem);
- assertThat(getWord(deSerialized.getItem(0)), is("first"));
- assertThat(getWord(deSerialized.getItem(1)), is("second"));
- assertThat(deSerialized.getItemCount(), is(2));
+ assertEquals("first", getWord(deSerialized.getItem(0)));
+ assertEquals("second", getWord(deSerialized.getItem(1)));
+ assertEquals(2, deSerialized.getItemCount());
}
@Test
- public void serialize_or_item() throws ParseException {
- assertThat(serializeThenParse(new OrItem()),
- instanceOf(OrItem.class));
+ public void serialize_or_item() {
+ assertTrue(serializeThenParse(new OrItem()) instanceof OrItem);
}
@Test
- public void serialize_not_item() throws ParseException {
+ public void serialize_not_item() {
NotItem notItem = new NotItem();
{
notItem.addItem(new WordItem("first"));
@@ -63,7 +62,7 @@ public class SerializeItemTestCase {
}
@Test
- public void serialize_near_item() throws ParseException {
+ public void serialize_near_item() {
int distance = 23;
NearItem nearItem = new NearItem(distance);
{
@@ -73,8 +72,8 @@ public class SerializeItemTestCase {
NearItem deSerialized = serializeThenParse(nearItem);
- assertThat(deSerialized.getDistance(), is(distance));
- assertThat(deSerialized.getItemCount(), is(2));
+ assertEquals(distance, deSerialized.getDistance());
+ assertEquals(2, deSerialized.getItemCount());
}
@Test
@@ -83,22 +82,22 @@ public class SerializeItemTestCase {
phraseItem.setIndexName("indexName");
PhraseItem deSerialized = serializeThenParse(phraseItem);
- assertThat(deSerialized.getItem(0), is(phraseItem.getItem(0)));
- assertThat(deSerialized.getItem(1), is(phraseItem.getItem(1)));
- assertThat(deSerialized.getIndexName(), is(phraseItem.getIndexName()));
+ assertEquals(phraseItem.getItem(0), deSerialized.getItem(0));
+ assertEquals(phraseItem.getItem(1), deSerialized.getItem(1));
+ assertEquals(phraseItem.getIndexName(), deSerialized.getIndexName());
}
@Test
- public void serialize_equiv_item() throws ParseException {
+ public void serialize_equiv_item() {
EquivItem equivItem = new EquivItem();
equivItem.addItem(new WordItem("first"));
EquivItem deSerialized = serializeThenParse(equivItem);
- assertThat(deSerialized.getItemCount(), is(1));
+ assertEquals(1, deSerialized.getItemCount());
}
@Test
- public void serialize_connectivity() throws ParseException {
+ public void serialize_connectivity() {
OrItem orItem = new OrItem();
{
WordItem first = new WordItem("first");
@@ -113,35 +112,35 @@ public class SerializeItemTestCase {
WordItem first = (WordItem) deSerialized.getItem(0);
Item second = deSerialized.getItem(1);
- assertThat(first.getConnectedItem(), is(second));
- assertThat(first.getConnectivity(), is(3.14));
+ assertEquals(second, first.getConnectedItem());
+ assertEquals(3.14, first.getConnectivity(), 0.0000001);
}
@Test
- public void serialize_significance() throws ParseException {
+ public void serialize_significance() {
EquivItem equivItem = new EquivItem();
equivItem.setSignificance(24.2);
EquivItem deSerialized = serializeThenParse(equivItem);
- assertThat(deSerialized.getSignificance(), is(24.2));
+ assertEquals(24.2, deSerialized.getSignificance(), 0.00000001);
}
@Test
- public void serialize_unique_id() throws ParseException {
+ public void serialize_unique_id() {
EquivItem equivItem = new EquivItem();
equivItem.setUniqueID(42);
EquivItem deSerialized = serializeThenParse(equivItem);
- assertThat(deSerialized.getUniqueID(), is(42));
+ assertEquals(42, deSerialized.getUniqueID());
}
@Test
- public void serialize_weight() throws ParseException {
+ public void serialize_weight() {
EquivItem equivItem = new EquivItem();
equivItem.setWeight(42);
EquivItem deSerialized = serializeThenParse(equivItem);
- assertThat(deSerialized.getWeight(), is(42));
+ assertEquals(42, deSerialized.getWeight());
}
private static String serialize(Item item) {
@@ -156,4 +155,5 @@ public class SerializeItemTestCase {
throw new RuntimeException(e);
}
}
+
}
diff --git a/container-search/src/test/java/com/yahoo/search/searchchain/config/test/SearchChainConfigurerTestCase.java b/container-search/src/test/java/com/yahoo/search/searchchain/config/test/SearchChainConfigurerTestCase.java
index d6e99ec3a44..0f1f77d66b4 100644
--- a/container-search/src/test/java/com/yahoo/search/searchchain/config/test/SearchChainConfigurerTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/searchchain/config/test/SearchChainConfigurerTestCase.java
@@ -5,7 +5,6 @@ import com.yahoo.config.search.IntConfig;
import com.yahoo.config.search.StringConfig;
import com.yahoo.container.core.config.HandlersConfigurerDi;
import com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper;
-import com.yahoo.lang.MutableInteger;
import com.yahoo.search.Query;
import com.yahoo.search.Result;
import com.yahoo.search.Searcher;
@@ -31,18 +30,19 @@ import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertThat;
/**
* @author bratseth
@@ -84,18 +84,18 @@ public class SearchChainConfigurerTestCase {
public synchronized void testConfiguration() {
HandlersConfigurerTestWrapper configurer = new HandlersConfigurerTestWrapper("dir:" + testDir);
- SearchChain simple=getSearchChainRegistryFrom(configurer).getComponent("simple");
+ SearchChain simple = getSearchChainRegistryFrom(configurer).getComponent("simple");
assertNotNull(simple);
- assertThat(getSearcherNumbers(simple), is(Arrays.asList(1, 2, 3)));
+ assertEquals(List.of(1, 2, 3), getSearcherNumbers(simple));
- SearchChain child1=getSearchChainRegistryFrom(configurer).getComponent("child:1");
- assertThat(getSearcherNumbers(child1), is(Arrays.asList(1, 2, 4, 5, 7, 8)));
+ SearchChain child1 = getSearchChainRegistryFrom(configurer).getComponent("child:1");
+ assertEquals(List.of(1, 2, 4, 5, 7, 8), getSearcherNumbers(child1));
- SearchChain child2=getSearchChainRegistryFrom(configurer).getComponent("child");
- assertThat(getSearcherNumbers(child2), is(Arrays.asList(3, 6, 7, 9)));
+ SearchChain child2 = getSearchChainRegistryFrom(configurer).getComponent("child");
+ assertEquals(List.of(3, 6, 7, 9), getSearcherNumbers(child2));
// Verify successful loading of an explicitly declared searcher that takes no user-defined configs.
- //assertNotNull(SearchChainRegistry.get().getSearcherRegistry().getComponent
+ // assertNotNull(SearchChainRegistry.get().getSearcherRegistry().getComponent
// ("com.yahoo.search.searchchain.config.test.SearchChainConfigurerTestCase$DeclaredTestSearcher"));
configurer.shutdown();
}
@@ -137,7 +137,7 @@ public class SearchChainConfigurerTestCase {
assertNotNull(configurable);
Searcher s = configurable.searchers().get(0);
- assertThat(s, instanceOf(ConfigurableSearcher.class));
+ assertTrue(s instanceof ConfigurableSearcher);
ConfigurableSearcher searcher = (ConfigurableSearcher)s;
assertEquals("Value from int.cfg file", 7, searcher.intConfig.intVal());
assertEquals("Value from string.cfg file", "com.yahoo.search.searchchain.config.test", searcher.stringConfig.stringVal());
@@ -164,10 +164,10 @@ public class SearchChainConfigurerTestCase {
HandlersConfigurerTestWrapper configurer = new HandlersConfigurerTestWrapper("dir:" + cfgDir);
SearcherRegistry searchers = getSearchChainRegistryFrom(configurer).getSearcherRegistry();
- assertThat(searchers.getComponentCount(), is(3));
+ assertEquals(3, searchers.getComponentCount());
IntSearcher intSearcher = (IntSearcher)searchers.getComponent(IntSearcher.class.getName());
- assertThat(intSearcher.intConfig.intVal(), is(16));
+ assertEquals(16, intSearcher.intConfig.intVal());
StringSearcher stringSearcher = (StringSearcher)searchers.getComponent(StringSearcher.class.getName());
DeclaredTestSearcher noConfigSearcher =
(DeclaredTestSearcher)searchers.getComponent(DeclaredTestSearcher.class.getName());
@@ -177,20 +177,20 @@ public class SearchChainConfigurerTestCase {
configurer.reloadConfig();
// Registry is rebuilt
- assertThat(getSearchChainRegistryFrom(configurer).getSearcherRegistry(), not(searchers));
+ assertNotEquals(searchers, getSearchChainRegistryFrom(configurer).getSearcherRegistry());
searchers = getSearchChainRegistryFrom(configurer).getSearcherRegistry();
- assertThat(searchers.getComponentCount(), is(3));
+ assertEquals(3, searchers.getComponentCount());
// Searcher with updated config is re-instantiated.
IntSearcher intSearcher2 = (IntSearcher)searchers.getComponent(IntSearcher.class.getName());
- assertThat(intSearcher2, not(sameInstance(intSearcher)));
- assertThat(intSearcher2.intConfig.intVal(), is(17));
+ assertNotSame(intSearcher, intSearcher2);
+ assertEquals(17, intSearcher2.intConfig.intVal());
// Searchers with unchanged config (or that takes no config) are the same as before.
Searcher s = searchers.getComponent(DeclaredTestSearcher.class.getName());
- assertThat(s, sameInstance(noConfigSearcher));
+ assertSame(noConfigSearcher, s);
s = searchers.getComponent(StringSearcher.class.getName());
- assertThat(s, sameInstance(stringSearcher));
+ assertSame(stringSearcher, s);
configurer.shutdown();
cleanup(cfgDir);
@@ -217,11 +217,11 @@ public class SearchChainConfigurerTestCase {
SearchChainRegistry scReg = getSearchChainRegistryFrom(configurer);
SearcherRegistry searchers = scReg.getSearcherRegistry();
- assertThat(searchers.getComponentCount(), is(2));
- assertThat(searchers.getComponent(IntSearcher.class.getName()), instanceOf(IntSearcher.class));
- assertThat(searchers.getComponent(StringSearcher.class.getName()), instanceOf(StringSearcher.class));
- assertThat(searchers.getComponent(ConfigurableSearcher.class.getName()), nullValue());
- assertThat(searchers.getComponent(DeclaredTestSearcher.class.getName()), nullValue());
+ assertEquals(2, searchers.getComponentCount());
+ assertTrue(searchers.getComponent(IntSearcher.class.getName()) instanceof IntSearcher);
+ assertTrue(searchers.getComponent(StringSearcher.class.getName()) instanceof StringSearcher);
+ assertNull(searchers.getComponent(ConfigurableSearcher.class.getName()));
+ assertNull(searchers.getComponent(DeclaredTestSearcher.class.getName()));
IntSearcher intSearcher = (IntSearcher)searchers.getComponent(IntSearcher.class.getName());
@@ -230,16 +230,16 @@ public class SearchChainConfigurerTestCase {
createComponentsConfig(testDir + "chainsConfigUpdate_2.cfg", testDir + "handlers.cfg", cfgDir + "/components.cfg");
configurer.reloadConfig();
- assertThat(getSearchChainRegistryFrom(configurer), not(scReg));
+ assertNotEquals(scReg, getSearchChainRegistryFrom(configurer));
// In the new registry, the correct searchers are removed and added
- assertThat(getSearchChainRegistryFrom(configurer).getSearcherRegistry(), not(searchers));
+ assertNotEquals(searchers, getSearchChainRegistryFrom(configurer).getSearcherRegistry());
searchers = getSearchChainRegistryFrom(configurer).getSearcherRegistry();
- assertThat(searchers.getComponentCount(), is(3));
- assertThat(searchers.getComponent(IntSearcher.class.getName()), sameInstance(intSearcher));
- assertThat(searchers.getComponent(ConfigurableSearcher.class.getName()), instanceOf(ConfigurableSearcher.class));
- assertThat(searchers.getComponent(DeclaredTestSearcher.class.getName()), instanceOf(DeclaredTestSearcher.class));
- assertThat(searchers.getComponent(StringSearcher.class.getName()), nullValue());
+ assertEquals(3, searchers.getComponentCount());
+ assertSame(intSearcher, searchers.getComponent(IntSearcher.class.getName()));
+ assertTrue(searchers.getComponent(ConfigurableSearcher.class.getName()) instanceof ConfigurableSearcher);
+ assertTrue(searchers.getComponent(DeclaredTestSearcher.class.getName()) instanceof DeclaredTestSearcher);
+ assertNull(searchers.getComponent(StringSearcher.class.getName()));
configurer.shutdown();
cleanup(cfgDir);
}
@@ -297,8 +297,8 @@ public class SearchChainConfigurerTestCase {
* Copies src file to dst file. If the dst file does not exist, it is created.
*/
public static void copyFile(String srcName, String dstName) throws IOException {
- InputStream src = new FileInputStream(new File(srcName));
- OutputStream dst = new FileOutputStream(new File(dstName));
+ InputStream src = new FileInputStream(srcName);
+ OutputStream dst = new FileOutputStream(dstName);
byte[] buf = new byte[1024];
int len;
while ((len = src.read(buf)) > 0) {
diff --git a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java
index abea2b0f259..f6273fdf723 100644
--- a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java
@@ -45,6 +45,7 @@ import org.junit.Test;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@@ -76,7 +77,6 @@ public class QueryTestCase {
assertEquals("", q.properties().get("aParameter"));
assertNull(q.properties().get("notSetParameter"));
- Query query = q;
String body = "a bb. ccc??!";
Linguistics linguistics = new SimpleLinguistics();
@@ -85,7 +85,7 @@ public class QueryTestCase {
if (token.isIndexable())
and.addItem(new WordItem(token.getTokenString(), "body"));
}
- query.getModel().getQueryTree().setRoot(and);
+ q.getModel().getQueryTree().setRoot(and);
}
// TODO: YQL work in progress (jon)
@@ -142,15 +142,11 @@ public class QueryTestCase {
@Test
public void testCloneWithConnectivity() {
- List<String> l = new ArrayList();
- l.add("a");
- l.add("b");
- l.add("c");
- l.add("a");
+ List<String> l = List.of("a", "b", "c", "a");
printIt(l.stream().filter(i -> isA(i)).collect(Collectors.toList()));
printIt(l.stream().filter(i -> ! isA(i)).collect(Collectors.toList()));
- Query q = new Query();
+ Query q = new Query();
WordItem a = new WordItem("a");
WordItem b = new WordItem("b");
WordItem c = new WordItem("c");
@@ -497,7 +493,7 @@ public class QueryTestCase {
assertTrue(q.getGroupingSessionCache());
}
- public class TestClass {
+ public static class TestClass {
private int testInt = 0;
@@ -1157,17 +1153,12 @@ public class QueryTestCase {
* be written as a single string.
*/
public static String httpEncode(String s) {
- try {
- if (s == null) return null;
- String encoded = URLEncoder.encode(s, "utf-8");
- encoded = encoded.replaceAll("%3F", "?");
- encoded = encoded.replaceAll("%3D", "=");
- encoded = encoded.replaceAll("%26", "&");
- return encoded;
- }
- catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
+ if (s == null) return null;
+ String encoded = URLEncoder.encode(s, StandardCharsets.UTF_8);
+ encoded = encoded.replaceAll("%3F", "?");
+ encoded = encoded.replaceAll("%3D", "=");
+ encoded = encoded.replaceAll("%26", "&");
+ return encoded;
}
}
diff --git a/container-search/src/test/java/com/yahoo/search/yql/YqlParserTestCase.java b/container-search/src/test/java/com/yahoo/search/yql/YqlParserTestCase.java
index c652c299b08..55fb53b4460 100644
--- a/container-search/src/test/java/com/yahoo/search/yql/YqlParserTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/yql/YqlParserTestCase.java
@@ -329,6 +329,13 @@ public class YqlParserTestCase {
}
@Test
+ public void testValuesCanBeQuoted() {
+ assertEquals("merkelapp",
+ getRootWord("select foo from bar where baz contains " +
+ "( {label: \"merkelapp\"} \"colors\");").getLabel());
+ }
+
+ @Test
public void testSameElement() {
assertParse("select foo from bar where baz contains sameElement(f1 contains \"a\", f2 contains \"b\")",
"baz:{f1:a f2:b}");