PlaceAutocompletePresenter { void onResponse(Response<Result> response) { Feature feature = response.body().getFeatures().get(0); Properties properties = feature.properties; String gid = properties.gid; if (gid.isEmpty()) { Place place = featureConverter.getFetchedPlace(feature); String details = featureConverter.getDetails(feature); detailFetchListener.onFetchSuccess(place, details); } else { detailFetcher.fetchDetails(gid, detailFetchListener); } } PlaceAutocompletePresenter(PlaceDetailFetcher detailFetcher,
      PeliasFeatureConverter featureConverter,
      OnPlaceDetailsFetchedListener detailFetchListener, FilterMapper filterMapper);   }
@Test public void onResponse_shouldFetchPlaceDetails() throws Exception { Response<Result> response = getTestResponse(); presenter.onResponse(response); verify(detailFetcher).fetchDetails("123abc", detailFetchListener); }
@Test public void onResponse_noGid_shouldNotFetchDetails() throws Exception { Response<Result> response = getTestResponseNoGid(); presenter.onResponse(response); verify(detailFetcher, times(0)).fetchDetails("123abc", detailFetchListener); }
@Test public void onResponse_noGid_shouldReturnPlaceFromResponse() throws Exception { Response<Result> response = getTestResponseNoGid(); Place place = mock(Place.class); String details = "Test detail"; Feature feature = response.body().getFeatures().get(0); when(featureConverter.getFetchedPlace(feature)).thenReturn(place); when(featureConverter.getDetails(feature)).thenReturn(details); presenter.onResponse(response); verify(detailFetchListener).onFetchSuccess(place, details); }