diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-01-03 15:20:03 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-01-03 15:20:03 +0100 |
commit | a9e52aa32101dc5ce39c5caa1d80c9cd7aa7684a (patch) | |
tree | 80bd9aa551ee9de7afaffee23130e7fb432488f9 /container-search/src/test/java/com/yahoo/search/federation/sourceref | |
parent | 1f3e5d1003a33d9a7076575eab8059c582611cdb (diff) |
Avoid deprecated APIs
Diffstat (limited to 'container-search/src/test/java/com/yahoo/search/federation/sourceref')
2 files changed, 34 insertions, 35 deletions
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); } + } |