private void stubMockPosts(List<Long> postIds, List<Post> mockPosts) { when(component.getMockHackerNewsService().getTopStories()).thenReturn(Observable.just(postIds)); for (Long id : postIds) { for (Post post : mockPosts) { if (post.id.equals(id)) { when(component.getMockHackerNewsService().getStoryItem(id.toString())) .thenReturn(Observable.just(post)); } } } }
@Test public void testJobPostHasViewButton() throws Exception { List<Long> postIdList = new ArrayList<>(); Post mockPost = MockModelsUtil.createMockJobWithTitle("Post with url"); postIdList.add(mockPost.id); when(component.getMockHackerNewsService().getTopStories()) .thenReturn(Observable.just(postIdList)); when(component.getMockHackerNewsService().getStoryItem(mockPost.id.toString())) .thenReturn(Observable.just(mockPost)); Intent i = new Intent(MainActivity.getStartIntent(InstrumentationRegistry.getTargetContext())); main.launchActivity(i); onView(withId(R.id.text_view_post)).check(matches(isDisplayed())); }