### Question:
HostResolver { String resolveName(final String host) { if (allHosts.contains(host)) { return host; } final List<String> matches = findPrefixMatches(host); if (matches.isEmpty()) { return host; } if (matches.size() == 1) { return matches.iterator().next(); } final List<ScoredHost> scored = scoreMatches(matches); final List<ScoredHost> sorted = sortScoredHosts(scored); final List<String> minScoreHosts = findMatchesWithLowestScore(sorted); if (minScoreHosts.size() > 1) { return host; } return minScoreHosts.get(0); } HostResolver(final Set<String> allHosts,
               final Name[] searchPath); List<String> getSortedMatches(final String hostName);  }### Answer:
@Test public void test() throws Exception { final HostResolver resolver = new HostResolver(ALL_HOSTS, new Name[]{}); assertEquals("host1.bar.com", resolver.resolveName("host1.bar.com")); assertEquals("whee.bar.com", resolver.resolveName("whee.bar.com")); assertEquals("host1.bar.com", resolver.resolveName("host1.bar")); assertEquals("host1.bar.com", resolver.resolveName("host1.b")); assertEquals("host1", resolver.resolveName("host1")); }
@Test public void testWithSearchPathDisambiguation() throws Exception { final HostResolver resolver = new HostResolver(ALL_HOSTS, SEARCH_PATH); assertEquals("host1.bar.com", resolver.resolveName("host1")); assertEquals("host1.bar.com", resolver.resolveName("ho")); }
@Test public void testAmbiguousWithSearchPathDisambiguation() throws Exception { final HostResolver resolver = new HostResolver( ImmutableSet.of("host1.foo.com", "host2.foo.com"), SEARCH_PATH); assertEquals("ho", resolver.resolveName("ho")); }