### Question:
EndpointDiscovery { public Optional<String> discover() throws IOException { List<DiscoveryResult> discoveryResults = discoverApiUrls(apiUrls()); return discoveryResults .stream() .sorted(Comparator.comparingLong(o -> o.duration)) .map(DiscoveryResult::getEndpoint) .findFirst(); } EndpointDiscovery(@NonNull final String myUserAgent); Optional<String> discover();  }### Answer:
@Test public void discover(@Mocked Client clientMock, @Mocked ClientBuilder clientBuilderMock, @Mocked WebTarget webTargetMock, @Mocked InetAddress inetAddressMock) throws IOException { new Expectations() {{ ClientBuilder.newBuilder(); result = clientBuilderMock; clientBuilderMock.build(); result = clientMock; clientMock.target("https: InetAddress.getAllByName(EndpointDiscovery.DNS_API_ADDRESS); result = new InetAddress[] {inetAddressMock}; inetAddressMock.getCanonicalHostName(); result = "127.0.0.1"; }}; Optional<String> name = endpointDiscovery.discover(); assertThat(name.isPresent(), is(true)); }