WordsApiDataProvider implements DataProvider { @Override public Observable<Pair<String, Response<RhymesResponse>>> rhymes(final String word) { return apiService.rhymes(word) .map(new Func1<Response<RhymesResponse>, Pair<String, Response<RhymesResponse>>>() { @Override public Pair<String, Response<RhymesResponse>> call(Response<RhymesResponse> rhymesResponse) { return new Pair<>(word, rhymesResponse); } }); } WordsApiDataProvider(ApiService apiService); @Override Observable<Pair<String, Response<RhymesResponse>>> rhymes(final String word);  }
@Test public void testRhymesWithSuccess() { Response<RhymesResponse> response = Response.success(new RhymesResponse(new Rhymes( Arrays.asList("hi", "bye", "sigh")))); String word = "high"; when(apiService.rhymes(word)).thenReturn(Observable.just(response)); Pair<String, Response<RhymesResponse>> pair = wordsApiDataProvider.rhymes(word).toBlocking().single(); assertNotNull(pair); assertEquals(word, pair.first); assertEquals(3, pair.second.body().rhymesObject().list().size()); }
@Test public void testRhymesWithNon200Response() { Response<RhymesResponse> response = Response.error(500, null); String word = "high"; when(apiService.rhymes(word)).thenReturn(Observable.just(response)); Pair<String, Response<RhymesResponse>> pair = wordsApiDataProvider.rhymes(word).toBlocking().single(); assertNotNull(pair); assertFalse(pair.second.isSuccess()); }