Search in sources :

Example 16 with Post

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

the class FeedModelTest method loadFeedOfUser.

@Test
public void loadFeedOfUser() {
    long now = System.currentTimeMillis();
    Post p1 = TestUtil.createDummyPost();
    User u1 = TestUtil.createDummyUser();
    p1.setUserId(u1.getId());
    p1.setCreated(now);
    Post p2 = TestUtil.createDummyPost();
    User u2 = TestUtil.createDummyUser();
    p2.setUserId(u2.getId());
    p2.setCreated(now + 2);
    Post p3 = TestUtil.createDummyPost();
    p3.setUserId(u1.getId());
    p3.setCreated(now - 2);
    mPostModel.save(p1);
    mPostModel.save(p2);
    mPostModel.save(p3);
    mUserModel.save(u1);
    mUserModel.save(u2);
    assertThat(mFeedModel.loadFeed(0, null).size(), is(3));
    assertThat(mFeedModel.loadFeed(0, u1.getId()).size(), is(2));
    assertThat(mFeedModel.loadFeed(0, u2.getId()).size(), is(1));
    assertThat(mFeedModel.loadFeed(now, null).size(), is(1));
    assertThat(mFeedModel.loadFeed(now - 1, null).size(), is(2));
    assertThat(mFeedModel.loadFeed(now - 4, null).size(), is(3));
    assertThat(mFeedModel.loadFeed(now, u1.getId()).size(), is(0));
    assertThat(mFeedModel.loadFeed(now - 1, u1.getId()).size(), is(1));
    assertThat(mFeedModel.loadFeed(now - 4, u1.getId()).size(), is(2));
}
Also used : User(com.android.example.devsummit.archdemo.vo.User) Post(com.android.example.devsummit.archdemo.vo.Post) Test(org.junit.Test) BaseTest(com.android.example.devsummit.archdemo.BaseTest)

Example 17 with Post

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

the class PostModelTest method loadPostsOfUser.

@Test
public void loadPostsOfUser() {
    long created = System.nanoTime();
    Post p1 = TestUtil.createDummyPost();
    Post p2 = TestUtil.createDummyPost();
    p1.setCreated(created);
    p1.setUserId(1);
    p2.setCreated(created);
    p2.setUserId(2);
    mPostModel.save(p1);
    mPostModel.save(p2);
    assertThat(mPostModel.loadPostsSince(0).size(), is(2));
    assertThat(mPostModel.loadPostsOfUser(1, created - 1).size(), is(1));
    assertThat(mPostModel.loadPostsOfUser(2, created - 1).size(), is(1));
    assertThat(mPostModel.loadPostsOfUser(3, 0).size(), is(0));
    assertThat(mPostModel.loadPostsOfUser(2, created).size(), is(0));
    p1.setUserId(2);
    mPostModel.save(p1);
    assertThat(mPostModel.loadPostsOfUser(1, 0).size(), is(0));
    assertThat(mPostModel.loadPostsOfUser(2, 0).size(), is(2));
}
Also used : Post(com.android.example.devsummit.archdemo.vo.Post) Test(org.junit.Test) BaseTest(com.android.example.devsummit.archdemo.BaseTest)

Example 18 with Post

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

the class PostModelTest method delete.

@Test
public void delete() {
    Post post = TestUtil.createDummyPost();
    final long id = post.getId();
    mPostModel.save(post);
    mPostModel.delete(post);
    assertThat(mPostModel.load(id), nullValue());
}
Also used : Post(com.android.example.devsummit.archdemo.vo.Post) Test(org.junit.Test) BaseTest(com.android.example.devsummit.archdemo.BaseTest)

Example 19 with Post

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

the class PostModelTest method addLoad.

@Test
public void addLoad() {
    Post post = new Post();
    post.setId(1);
    post.setText("bla");
    post.setClientId("abc");
    post.setUserId(1);
    post.setCreated(System.currentTimeMillis());
    mPostModel.save(post);
    Post loaded = mPostModel.load(1);
    assertThat(loaded, notNullValue());
    assertThat(loaded.getId(), is(1L));
    assertThat(loaded.getText(), is("bla"));
    assertThat(loaded.getClientId(), is("abc"));
    // try to re add
    Post post2 = new Post();
    post2.setClientId("abc");
    post2.setText("xxx");
    post2.setUserId(1);
    post2.setCreated(System.currentTimeMillis());
    mPostModel.save(post2);
    List<Post> posts = mPostModel.loadPostsSince(post2.getCreated() - 1);
    assertThat(posts.size(), is(1));
    Post updatedPost = posts.get(0);
    assertThat(updatedPost.getId(), is(1L));
    assertThat(updatedPost.getText(), is("xxx"));
}
Also used : Post(com.android.example.devsummit.archdemo.vo.Post) Test(org.junit.Test) BaseTest(com.android.example.devsummit.archdemo.BaseTest)

Example 20 with Post

use of com.android.example.devsummit.archdemo.vo.Post 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)

Aggregations

Post (com.android.example.devsummit.archdemo.vo.Post)20 Test (org.junit.Test)11 BaseTest (com.android.example.devsummit.archdemo.BaseTest)9 FeedItem (com.android.example.devsummit.archdemo.vo.FeedItem)5 User (com.android.example.devsummit.archdemo.vo.User)5 FetchedFeedEvent (com.android.example.devsummit.archdemo.event.feed.FetchedFeedEvent)4 FeedResponse (com.android.example.devsummit.archdemo.api.FeedResponse)2 NewPostResponse (com.android.example.devsummit.archdemo.api.NewPostResponse)2 NetworkException (com.android.example.devsummit.archdemo.job.NetworkException)2 FeedModel (com.android.example.devsummit.archdemo.model.FeedModel)2 Nullable (android.support.annotation.Nullable)1 DeletePostEvent (com.android.example.devsummit.archdemo.event.post.DeletePostEvent)1 NewPostEvent (com.android.example.devsummit.archdemo.event.post.NewPostEvent)1 UpdatedPostEvent (com.android.example.devsummit.archdemo.event.post.UpdatedPostEvent)1 TestUtil.createDummyPost (com.android.example.devsummit.archdemo.util.TestUtil.createDummyPost)1 TestUtil.createDummyUser (com.android.example.devsummit.archdemo.util.TestUtil.createDummyUser)1 ArrayList (java.util.ArrayList)1