### Question:
Endpoints { public static Supplier<List<Endpoint>> of(final Supplier<List<URI>> uriSupplier) { return of(uriSupplier, DEFAULT_DNS_RESOLVER); } private  Endpoints(); static Supplier<List<Endpoint>> of(final Supplier<List<URI>> uriSupplier); static List<Endpoint> of(final List<URI> uris);  }### Answer:
@Test public void testSupplierFactory() throws Exception { final DnsResolver resolver = mock(DnsResolver.class); when(resolver.resolve("example.com")).thenReturn(IPS_1); when(resolver.resolve("example.net")).thenReturn(IPS_2); final Supplier<List<URI>> uriSupplier = Suppliers.ofInstance(uris); final Supplier<List<Endpoint>> endpointSupplier = Endpoints.of(uriSupplier, resolver); final List<Endpoint> endpoints = endpointSupplier.get(); assertThat(endpoints.size(), equalTo(4)); assertThat(endpoints.get(0).getUri(), equalTo(uri1)); assertThat(endpoints.get(0).getIp(), equalTo(IP_A)); assertThat(endpoints.get(1).getUri(), equalTo(uri1)); assertThat(endpoints.get(1).getIp(), equalTo(IP_B)); assertThat(endpoints.get(2).getUri(), equalTo(uri2)); assertThat(endpoints.get(2).getIp(), equalTo(IP_C)); assertThat(endpoints.get(3).getUri(), equalTo(uri2)); assertThat(endpoints.get(3).getIp(), equalTo(IP_D)); }
@Test public void testFactory() throws Exception { final DnsResolver resolver = mock(DnsResolver.class); when(resolver.resolve("example.com")).thenReturn(IPS_1); when(resolver.resolve("example.net")).thenReturn(IPS_2); final List<Endpoint> endpoints = Endpoints.of(uris, resolver); assertThat(endpoints.size(), equalTo(4)); assertThat(endpoints.get(0).getUri(), equalTo(uri1)); assertThat(endpoints.get(0).getIp(), equalTo(IP_A)); assertThat(endpoints.get(1).getUri(), equalTo(uri1)); assertThat(endpoints.get(1).getIp(), equalTo(IP_B)); assertThat(endpoints.get(2).getUri(), equalTo(uri2)); assertThat(endpoints.get(2).getIp(), equalTo(IP_C)); assertThat(endpoints.get(3).getUri(), equalTo(uri2)); assertThat(endpoints.get(3).getIp(), equalTo(IP_D)); }
@Test public void testUnableToResolve() throws Exception { final DnsResolver resolver = mock(DnsResolver.class); when(resolver.resolve("example.com")).thenThrow(new UnknownHostException()); when(resolver.resolve("example.net")).thenThrow(new UnknownHostException()); final List<Endpoint> endpoints = Endpoints.of(uris, resolver); assertThat(endpoints.size(), equalTo(0)); }
@Test public void testInvalidUri_NoScheme() throws Exception { final DnsResolver resolver = mock(DnsResolver.class); when(resolver.resolve("example.com")).thenReturn(IPS_1); exception.expect(IllegalArgumentException.class); Endpoints.of(ImmutableList.of(new URI(null, "example.com", null, null)), resolver); }
@Test public void testInvalidUri_NoPort() throws Exception { final DnsResolver resolver = mock(DnsResolver.class); when(resolver.resolve("example.com")).thenReturn(IPS_1); exception.expect(IllegalArgumentException.class); Endpoints.of(ImmutableList.of(new URI("http", "example.com", null, null)), resolver); }