Slide 13
Slide 13 text
Testing the Observable
• Sometimes, we need to chain calls - retrieving a list of items, then fetching
detail about one item
• Here, for example, we get a list of gists, then we retrieve detail for the first
one in the list and expect it to have the same description
• Again, the goal here is not to prove anything about the objects, but to
validate that we’re calling the endpoints successfully
public class GistTest extends BaseApiTest {
@Test
public void testAllGists() {
ServiceLocator.put(OkHttpClient.class, OkHttpClientUtil.getOkHttpClient(null, MockBehavior.MOCK));
Flowable flowable = ServiceInjector.resolve(RxEndpoints.class).getGists();
TestSubscriber testSubscriber = new TestSubscriber<>();
flowable.subscribe(testSubscriber);
testSubscriber.assertComplete();
List gists = testSubscriber.values();
Gist gist = gists.get(0)[0];
Flowable gistFlowable = ServiceInjector.resolve(RxEndpoints.class).getGist(gist.getId());
TestSubscriber gistTestSubscriber = new TestSubscriber<>();
gistFlowable.subscribe(gistTestSubscriber);
Gist detailGist = (Gist) gistTestSubscriber.values().get(0);
assertEquals(detailGist.getDescription(), gist.getDescription());
}
}