ChainedHostResolver implements AdvancedHostResolver { @Override public Collection<String> getOriginalHostnames(String remappedHost) { readLock.lock(); try { if (resolvers.isEmpty()) { return emptyList(); } else { return resolvers.get(0).getOriginalHostnames(remappedHost); } } finally { readLock.unlock(); } } ChainedHostResolver(Collection<? extends AdvancedHostResolver> resolvers); Collection<? extends AdvancedHostResolver> getResolvers(); @Override void remapHosts(Map<String, String> hostRemappings); @Override void remapHost(String originalHost, String remappedHost); @Override void removeHostRemapping(String originalHost); @Override void clearHostRemappings(); @Override Map<String, String> getHostRemappings(); @Override Collection<String> getOriginalHostnames(String remappedHost); @Override void clearDNSCache(); @Override void setPositiveDNSCacheTimeout(int timeout, TimeUnit timeUnit); @Override void setNegativeDNSCacheTimeout(int timeout, TimeUnit timeUnit); @Override Collection<InetAddress> resolve(String host);  }
@Test public void testGetterUsesFirstResolver() { AdvancedHostResolver firstResolver = mock(AdvancedHostResolver.class); AdvancedHostResolver secondResolver = mock(AdvancedHostResolver.class); ChainedHostResolver chainResolver = new ChainedHostResolver(ImmutableList.of(firstResolver, secondResolver)); when(firstResolver.getOriginalHostnames("one")).thenReturn(ImmutableList.of("originalOne")); Collection<String> results = chainResolver.getOriginalHostnames("one"); assertNotNull("Resolver should not return null results", results); assertThat("Expected resolver to return a result", results, not(empty())); assertEquals("Resolver returned unexpected result", "originalOne", Iterables.get(results, 0)); verify(secondResolver, never()).getOriginalHostnames(any(String.class)); }