@Test public void fetchOnTime() throws Exception { when(placesApi.placesResult()).thenReturn( Observable.create(subscriber -> { try { Thread.sleep(4900); subscriber.onNext(TestDataUtils.nearByData()); subscriber.onCompleted(); } catch (InterruptedException e) { subscriber.onError(e); } }) ); try { boolean success = placesViewModel.fetchAllPlaces().toBlocking().first(); assertTrue(success); } catch (Exception ignored) { fail("Should be on time"); } }
@Override public Observable<Boolean> fetchAllPlaces() { return mPlacesApi.placesResult() .map(googleSearchResult -> { allPlaces = googleSearchResult.results; mPlaces.onNext(googleSearchResult.results); return true; }) .timeout(TIME_OUT, TimeUnit.SECONDS) .retry(RETRY); }
PlacesViewModel implements IPlacesViewModel { @Override public Observable<Boolean> fetchAllPlaces() { return mPlacesApi.placesResult() .map(googleSearchResult -> { allPlaces = googleSearchResult.results; mPlaces.onNext(googleSearchResult.results); return true; }) .timeout(TIME_OUT, TimeUnit.SECONDS) .retry(RETRY); } }
PlacesViewModel implements IPlacesViewModel { @Override public Observable<Boolean> fetchAllPlaces() { return mPlacesApi.placesResult() .map(googleSearchResult -> { allPlaces = googleSearchResult.results; mPlaces.onNext(googleSearchResult.results); return true; }) .timeout(TIME_OUT, TimeUnit.SECONDS) .retry(RETRY); } PlacesViewModel(@NonNull IPlacesApi placesApi); }
PlacesViewModel implements IPlacesViewModel { @Override public Observable<Boolean> fetchAllPlaces() { return mPlacesApi.placesResult() .map(googleSearchResult -> { allPlaces = googleSearchResult.results; mPlaces.onNext(googleSearchResult.results); return true; }) .timeout(TIME_OUT, TimeUnit.SECONDS) .retry(RETRY); } PlacesViewModel(@NonNull IPlacesApi placesApi); Observable<List<Place>> currentPlaces(); @Override Observable<Boolean> fetchAllPlaces(); @Override void filterPlacesByType(String type); }
PlacesViewModel implements IPlacesViewModel { @Override public Observable<Boolean> fetchAllPlaces() { return mPlacesApi.placesResult() .map(googleSearchResult -> { allPlaces = googleSearchResult.results; mPlaces.onNext(googleSearchResult.results); return true; }) .timeout(TIME_OUT, TimeUnit.SECONDS) .retry(RETRY); } PlacesViewModel(@NonNull IPlacesApi placesApi); Observable<List<Place>> currentPlaces(); @Override Observable<Boolean> fetchAllPlaces(); @Override void filterPlacesByType(String type);  }