### Question:
ProxyMappings { public ProxyMapping getProxyFor(String hostname) { Objects.requireNonNull(hostname, "hostname"); if (hostnameToProxyCache.containsKey(hostname)) { return hostnameToProxyCache.get(hostname); } ProxyMapping proxyMapping = entries.stream() .filter(e -> e.matches(hostname)) .findFirst() .orElse(null); if (proxyMapping == null) { proxyMapping = new ProxyMapping(null, null, null); } hostnameToProxyCache.put(hostname, proxyMapping); return proxyMapping; } ProxyMappings(List<ProxyMapping> entries); static ProxyMappings valueOf(List<String> proxyMappings); static ProxyMappings valueOf(String... proxyMappings); boolean isEmpty(); ProxyMapping getProxyFor(String hostname); static void clearCache();  }### Answer:
@Test public void shouldReturnProxy1ForConfiguredProxyMappingAlternative() { ProxyMapping proxy = proxyMappings.getProxyFor("www.googleapis.com"); assertThat(proxy.getProxyHost(), is(notNullValue())); assertThat(proxy.getProxyHost().getHostName(), is("proxy1")); }
@Test public void shouldReturnProxy1ForConfiguredProxyMappingWithSubDomain() { ProxyMapping proxy = proxyMappings.getProxyFor("awesome.account.google.com"); assertThat(proxy.getProxyHost(), is(notNullValue())); assertThat(proxy.getProxyHost().getHostName(), is("proxy1")); }
@Test public void shouldReturnProxy2ForConfiguredProxyMapping() { ProxyMapping proxy = proxyMappings.getProxyFor("login.facebook.com"); assertThat(proxy.getProxyHost(), is(notNullValue())); assertThat(proxy.getProxyHost().getHostName(), is("proxy2")); }
@Test public void shouldReturnNoProxyForUnknownHost() { ProxyMapping proxy = proxyMappings.getProxyFor("login.microsoft.com"); assertThat(proxy.getProxyHost(), is(nullValue())); }
@Test public void shouldRejectNull() { expectedException.expect(NullPointerException.class); expectedException.expectMessage("hostname"); proxyMappings.getProxyFor(null); }
@Test public void shouldReturnProxy1ForConfiguredProxyMapping() { ProxyMapping proxy = proxyMappings.getProxyFor("account.google.com"); assertThat(proxy.getProxyHost(), is(notNullValue())); assertThat(proxy.getProxyHost().getHostName(), is("proxy1")); }