@Test public void fetchExceedRetry() throws Exception { AtomicInteger atomicInteger = new AtomicInteger(0); when(placesApi.placesResult()).thenReturn( Observable.create(subscriber -> { if (atomicInteger.getAndIncrement() < 4) { subscriber.onError(new Exception()); } else { subscriber.onNext(TestDataUtils.nearByData()); subscriber.onCompleted(); } }) ); try { placesViewModel.fetchAllPlaces().toBlocking().first(); fail("Should be out of retry"); } catch (Exception ignored) { } }
@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);  }