ApiAware { public <S> S get(Class<S> serviceClass) { ObjectMapper objectMapper = createDefaultMapper(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(baseUrl) .addConverterFactory(JacksonConverterFactory.create(objectMapper)) .client(httpClient).build(); return retrofit.create(serviceClass); } private  ApiAware(String baseUrl); static ApiAware withUrl(String url); S get(Class<S> serviceClass); String getWebSocketUrl(String endpoint);  }
@Test public void testGet() { ApiAware apiAware = ApiAware.withUrl("http: assertThat(apiAware.get(InstancesApi.class), is(instanceOf(InstancesApi.class))); assertThat(apiAware.get(ImagesApi.class), is(instanceOf(ImagesApi.class))); assertThat(apiAware.get(QueryApi.class), is(instanceOf(QueryApi.class))); assertThat(apiAware.get(ServiceApi.class), is(instanceOf(ServiceApi.class))); }