Search in sources :

Example 1 with FeedModel

use of com.android.example.devsummit.archdemo.model.FeedModel in project dev-summit-architecture-demo by yigit.

the class FeedActivityTest method refreshFeedWithOlderItems.

@Test
public void refreshFeedWithOlderItems() throws Throwable {
    FeedModel mockFeedModel = mock(FeedModel.class);
    when(mComponent.feedModel()).thenReturn(mockFeedModel);
    FeedItem feedItem1 = TestUtil.createDummyFeedItem();
    FeedItem feedItem2 = TestUtil.createDummyFeedItem();
    List<FeedItem> items = Collections.singletonList(feedItem1);
    List<FeedItem> items2 = Arrays.asList(feedItem1, feedItem2);
    Post post1 = feedItem1.getPost();
    final Post post2 = feedItem2.getPost();
    post1.setCreated(10L);
    post2.setCreated(2L);
    //noinspection unchecked
    when(mockFeedModel.loadFeed(0L, null)).thenReturn(items);
    when(mockFeedModel.loadFeed(1L, null)).thenReturn(items2);
    getActivity();
    onView(atAdapterPosition(getActivity().mBinding.list, 0)).check(matches(withChild(withText(post1.getText())))).check(matches(withChild(withText(feedItem1.getUser().getName()))));
    runTestOnUiThread(new Runnable() {

        @Override
        public void run() {
            getActivity().onEventMainThread(new FetchedFeedEvent(true, null, post2));
        }
    });
    onItemAt(0).check(matches(withChild(withText(post1.getText())))).check(matches(withChild(withText(feedItem1.getUser().getName()))));
    onItemAt(1).check(matches(withChild(withText(post2.getText())))).check(matches(withChild(withText(feedItem2.getUser().getName()))));
}
Also used : FeedModel(com.android.example.devsummit.archdemo.model.FeedModel) FeedItem(com.android.example.devsummit.archdemo.vo.FeedItem) Post(com.android.example.devsummit.archdemo.vo.Post) FetchedFeedEvent(com.android.example.devsummit.archdemo.event.feed.FetchedFeedEvent) Test(org.junit.Test)

Example 2 with FeedModel

use of com.android.example.devsummit.archdemo.model.FeedModel in project dev-summit-architecture-demo by yigit.

the class FetchFeedJobTest method testSinceForUserFeed.

@Test
public void testSinceForUserFeed() {
    ArgumentCaptor<Long> userIdCaptor = ArgumentCaptor.forClass(long.class);
    ArgumentCaptor<Long> sinceCaptor = ArgumentCaptor.forClass(long.class);
    FetchFeedJob job = new FetchFeedJob(BaseJob.BACKGROUND, 101L);
    FeedModel spyFeedModel = spy(mFeedModel);
    doReturn(123L).when(spyFeedModel).getLatestTimestamp(101L);
    job.inject(getTestComponent());
    job.mFeedModel = spyFeedModel;
    //noinspection ThrowableResultOfMethodCallIgnored
    safeRun(job);
    verify(mApiService).userFeed(userIdCaptor.capture(), sinceCaptor.capture());
    assertThat(userIdCaptor.getValue(), is(101L));
    assertThat(sinceCaptor.getValue(), is(123L));
}
Also used : FeedModel(com.android.example.devsummit.archdemo.model.FeedModel) BaseTest(com.android.example.devsummit.archdemo.BaseTest) Test(org.junit.Test)

Example 3 with FeedModel

use of com.android.example.devsummit.archdemo.model.FeedModel in project dev-summit-architecture-demo by yigit.

the class FetchFeedJobTest method testSinceForCommonFeed.

@Test
public void testSinceForCommonFeed() {
    ArgumentCaptor<Long> sinceCaptor = ArgumentCaptor.forClass(long.class);
    FetchFeedJob job = new FetchFeedJob(BaseJob.BACKGROUND, null);
    FeedModel spyFeedModel = spy(mFeedModel);
    doReturn(124L).when(spyFeedModel).getLatestTimestamp(null);
    job.inject(getTestComponent());
    job.mFeedModel = spyFeedModel;
    //noinspection ThrowableResultOfMethodCallIgnored
    safeRun(job);
    verify(mApiService).feed(sinceCaptor.capture());
    assertThat(sinceCaptor.getValue(), is(124L));
}
Also used : FeedModel(com.android.example.devsummit.archdemo.model.FeedModel) BaseTest(com.android.example.devsummit.archdemo.BaseTest) Test(org.junit.Test)

Example 4 with FeedModel

use of com.android.example.devsummit.archdemo.model.FeedModel in project dev-summit-architecture-demo by yigit.

the class FeedActivityTest method refreshFeedWithNewItems.

@Test
public void refreshFeedWithNewItems() throws Throwable {
    FeedModel mockFeedModel = mock(FeedModel.class);
    when(mComponent.feedModel()).thenReturn(mockFeedModel);
    FeedItem feedItem1 = TestUtil.createDummyFeedItem();
    FeedItem feedItem2 = TestUtil.createDummyFeedItem();
    List<FeedItem> items = Collections.singletonList(feedItem1);
    List<FeedItem> items2 = Arrays.asList(feedItem1, feedItem2);
    Post post1 = feedItem1.getPost();
    final Post post2 = feedItem2.getPost();
    post1.setCreated(1L);
    post2.setCreated(2L);
    //noinspection unchecked
    when(mockFeedModel.loadFeed(0L, null)).thenReturn(items);
    when(mockFeedModel.loadFeed(post1.getCreated(), null)).thenReturn(items2);
    getActivity();
    onView(atAdapterPosition(getActivity().mBinding.list, 0)).check(matches(withChild(withText(post1.getText())))).check(matches(withChild(withText(feedItem1.getUser().getName()))));
    runTestOnUiThread(new Runnable() {

        @Override
        public void run() {
            getActivity().onEventMainThread(new FetchedFeedEvent(true, null, post2));
        }
    });
    onItemAt(0).check(matches(withChild(withText(post2.getText())))).check(matches(withChild(withText(feedItem2.getUser().getName()))));
    onItemAt(1).check(matches(withChild(withText(post1.getText())))).check(matches(withChild(withText(feedItem1.getUser().getName()))));
}
Also used : FeedModel(com.android.example.devsummit.archdemo.model.FeedModel) FeedItem(com.android.example.devsummit.archdemo.vo.FeedItem) Post(com.android.example.devsummit.archdemo.vo.Post) FetchedFeedEvent(com.android.example.devsummit.archdemo.event.feed.FetchedFeedEvent) Test(org.junit.Test)

Example 5 with FeedModel

use of com.android.example.devsummit.archdemo.model.FeedModel in project dev-summit-architecture-demo by yigit.

the class FeedActivityTest method loadFeed.

@Test
public void loadFeed() {
    FeedModel mockFeedModel = mock(FeedModel.class);
    when(mComponent.feedModel()).thenReturn(mockFeedModel);
    List<FeedItem> items = Collections.singletonList(TestUtil.createDummyFeedItem());
    when(mockFeedModel.loadFeed(0L, null)).thenReturn(items);
    getActivity();
    onView(withId(R.id.user_name)).check(matches(withText(items.get(0).getUser().getName())));
    onView(withId(R.id.post_text)).check(matches(withText(items.get(0).getPost().getText())));
}
Also used : FeedModel(com.android.example.devsummit.archdemo.model.FeedModel) FeedItem(com.android.example.devsummit.archdemo.vo.FeedItem) Test(org.junit.Test)

Aggregations

FeedModel (com.android.example.devsummit.archdemo.model.FeedModel)5 Test (org.junit.Test)5 FeedItem (com.android.example.devsummit.archdemo.vo.FeedItem)3 BaseTest (com.android.example.devsummit.archdemo.BaseTest)2 FetchedFeedEvent (com.android.example.devsummit.archdemo.event.feed.FetchedFeedEvent)2 Post (com.android.example.devsummit.archdemo.vo.Post)2