### Question:
EndpointDiscovery { Stats getStats(final String endpoint, final int timeout) { if (timeout <= 0) { throw new IllegalArgumentException( "timeout must be > 0, but is " + timeout); } Client client = ClientBuilder.newBuilder() .register(JacksonFeature.class) .build(); client.property(ClientProperties.CONNECT_TIMEOUT, timeout); client.property(ClientProperties.READ_TIMEOUT, timeout); WebTarget webTarget = client.target(endpoint); return webTarget.path("json/stats") .request(MediaType.APPLICATION_JSON_TYPE) .accept(MediaType.APPLICATION_JSON_TYPE) .header("User-Agent", userAgent) .get(Stats.class); } EndpointDiscovery(@NonNull final String myUserAgent); Optional<String> discover();  }### Answer:
@Test public void getStats(@Mocked Client clientMock, @Mocked ClientBuilder clientBuilderMock, @Mocked WebTarget webTargetMock, @Mocked Invocation.Builder invocationBuilderMock) { Stats myStats = new Stats(); new Expectations() {{ ClientBuilder.newBuilder(); result = clientBuilderMock; clientBuilderMock.build(); result = clientMock; clientMock.target(RadioBrowser.DEFAULT_API_URL); result = webTargetMock; invocationBuilderMock.get(Stats.class); result = myStats; }}; Stats stats = endpointDiscovery.getStats(RadioBrowser.DEFAULT_API_URL, 5000); assertThat(stats, is(myStats)); }