use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.
the class ItemActivityTest method testItemChanged.
@Test
public void testItemChanged() {
startWithIntent();
TabLayout tabLayout = (TabLayout) activity.findViewById(R.id.tab_layout);
assertEquals(activity.getResources().getQuantityString(R.plurals.comments_count, 0, 0), tabLayout.getTabAt(0).getText());
activity.onItemChanged(new TestHnItem(1L) {
@Override
public int getKidCount() {
return 10;
}
});
assertEquals(activity.getResources().getQuantityString(R.plurals.comments_count, 10, 10), tabLayout.getTabAt(0).getText());
}
use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.
the class ItemActivityTest method testNonFavoriteStory.
@Test
public void testNonFavoriteStory() {
TestHnItem item = new TestHnItem(1L) {
@NonNull
@Override
public String getType() {
return STORY_TYPE;
}
};
Intent intent = new Intent();
intent.putExtra(ItemActivity.EXTRA_ITEM, item);
controller.withIntent(intent).create().start().resume();
assertFalse(item.isFavorite());
activity.findViewById(R.id.bookmarked).performClick();
ShadowContentObserver observer = shadowOf(shadowOf(activity.getContentResolver()).getContentObservers(MaterialisticProvider.URI_FAVORITE).iterator().next());
observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("add").appendPath("1").build());
assertTrue(item.isFavorite());
}
use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.
the class ListFragmentViewHolderTest method testNewComments.
@Test
public void testNewComments() {
reset(itemManager);
ShadowSwipeRefreshLayout shadowSwipeRefreshLayout = (ShadowSwipeRefreshLayout) ShadowExtractor.extract(activity.findViewById(R.id.swipe_layout));
shadowSwipeRefreshLayout.getOnRefreshListener().onRefresh();
verify(itemManager).getStories(any(), eq(ItemManager.MODE_NETWORK), storiesListener.capture());
storiesListener.getValue().onResponse(new Item[] { new TestHnItem(1) });
verify(itemManager).getItem(any(), eq(ItemManager.MODE_NETWORK), itemListener.capture());
itemListener.getValue().onResponse(new PopulatedStory(1) {
@Override
public int getDescendants() {
return 2;
}
@Override
public long[] getKids() {
return new long[] { 2, 3 };
}
});
RecyclerView.ViewHolder holder = adapter.getViewHolder(0);
assertThat((TextView) holder.itemView.findViewById(R.id.comment)).hasTextString("2*");
}
use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.
the class ItemFragmentMultiPageTest method testRefresh.
@Test
public void testRefresh() {
WebItem webItem = mock(WebItem.class);
when(webItem.getId()).thenReturn("1");
Bundle args = new Bundle();
args.putParcelable(ItemFragment.EXTRA_ITEM, webItem);
Fragment fragment = Fragment.instantiate(RuntimeEnvironment.application, ItemFragment.class.getName(), args);
makeVisible(fragment);
ShadowSwipeRefreshLayout shadowSwipeRefreshLayout = (ShadowSwipeRefreshLayout) ShadowExtractor.extract(fragment.getView().findViewById(R.id.swipe_layout));
shadowSwipeRefreshLayout.getOnRefreshListener().onRefresh();
verify(hackerNewsClient).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), listener.capture());
verify(hackerNewsClient).getItem(eq("1"), eq(ItemManager.MODE_NETWORK), listener.capture());
listener.getAllValues().get(1).onResponse(new TestHnItem(1L));
assertThat((SwipeRefreshLayout) fragment.getView().findViewById(R.id.swipe_layout)).isNotRefreshing();
verify(((TestItemActivity) fragment.getActivity()).itemChangedListener).onItemChanged(any(Item.class));
}
use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.
the class ItemFragmentMultiPageTest method testBindRemoteKidData.
@Test
public void testBindRemoteKidData() {
Bundle args = new Bundle();
Item item = new TestHnItem(2L);
item.populate(new TestHnItem(2L) {
@Override
public long[] getKids() {
return new long[] { 1L };
}
});
args.putParcelable(ItemFragment.EXTRA_ITEM, item);
Fragment fragment = Fragment.instantiate(RuntimeEnvironment.application, ItemFragment.class.getName(), args);
makeVisible(fragment);
verify(hackerNewsClient).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), listener.capture());
listener.getValue().onResponse(new TestHnItem(1L) {
@Override
public String getTitle() {
return "title";
}
});
assertEquals(1, item.getKidItems()[0].getLocalRevision());
assertEquals("title", item.getKidItems()[0].getTitle());
}
Aggregations