use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.
the class WidgetServiceTest method testAdapter.
@Test
public void testAdapter() {
when(itemManager.getStories(any(), anyInt())).thenReturn(new Item[] { new TestHnItem(1L) });
when(itemManager.getItem(any(), anyInt())).thenReturn(new TestHnItem(1L) {
@Override
public String getDisplayedTitle() {
return "title";
}
@Override
public int getScore() {
return 100;
}
});
viewFactory.onDataSetChanged();
verify(itemManager).getStories(any(), anyInt());
assertThat(viewFactory.hasStableIds()).isTrue();
assertThat(viewFactory.getCount()).isEqualTo(1);
assertThat(viewFactory.getLoadingView()).isNotNull();
assertThat(viewFactory.getViewTypeCount()).isEqualTo(1);
assertThat(viewFactory.getItemId(0)).isEqualTo(1L);
assertThat(viewFactory.getViewAt(0)).isNotNull();
verify(itemManager).getItem(eq("1"), anyInt());
}
use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.
the class UserActivityTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
TestApplication.applicationGraph.inject(this);
reset(userManager);
reset(itemManager);
reset(keyDelegate);
controller = Robolectric.buildActivity(UserActivity.class);
Intent intent = new Intent();
intent.putExtra(UserActivity.EXTRA_USERNAME, "username");
activity = controller.withIntent(intent).create().start().resume().visible().get();
user = mock(UserManager.User.class);
when(user.getId()).thenReturn("username");
when(user.getCreated(any(Context.class))).thenReturn("May 01 2015");
when(user.getKarma()).thenReturn(2016L);
when(user.getAbout()).thenReturn("about");
when(user.getItems()).thenReturn(new Item[] { new TestHnItem(1L) {
@NonNull
@Override
public String getType() {
return COMMENT_TYPE;
}
}, new TestHnItem(2L) {
@NonNull
@Override
public String getType() {
return STORY_TYPE;
}
} });
}
use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.
the class UserActivityTest method testStoryBinding.
@Test
public void testStoryBinding() {
verify(userManager).getUser(eq("username"), userCaptor.capture());
userCaptor.getValue().onResponse(user);
RecyclerView recyclerView = (RecyclerView) activity.findViewById(R.id.recycler_view);
verify(itemManager).getItem(eq("2"), eq(ItemManager.MODE_DEFAULT), itemCaptor.capture());
itemCaptor.getValue().onResponse(new TestHnItem(2L) {
@Override
public String getTitle() {
return "title";
}
@Override
public String getText() {
return "content";
}
@Override
public int getScore() {
return 46;
}
});
RecyclerView.ViewHolder viewHolder = customShadowOf(recyclerView.getAdapter()).getViewHolder(1);
assertThat((TextView) viewHolder.itemView.findViewById(R.id.posted)).containsText(activity.getResources().getQuantityString(R.plurals.score, 46, 46));
assertThat((TextView) viewHolder.itemView.findViewById(R.id.title)).isVisible().hasTextString("title");
assertThat((TextView) viewHolder.itemView.findViewById(R.id.text)).isVisible().hasTextString("content");
viewHolder.itemView.findViewById(R.id.comment).performClick();
assertThat(shadowOf(activity).getNextStartedActivity()).hasComponent(activity, ItemActivity.class).hasExtra(ItemActivity.EXTRA_ITEM);
}
use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.
the class UserActivityTest method testDeletedItemBinding.
@Test
public void testDeletedItemBinding() {
verify(userManager).getUser(eq("username"), userCaptor.capture());
userCaptor.getValue().onResponse(user);
RecyclerView recyclerView = (RecyclerView) activity.findViewById(R.id.recycler_view);
verify(itemManager).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), itemCaptor.capture());
itemCaptor.getValue().onResponse(new TestHnItem(1L) {
@Override
public boolean isDeleted() {
return true;
}
});
RecyclerView.ViewHolder viewHolder = customShadowOf(recyclerView.getAdapter()).getViewHolder(0);
assertThat(viewHolder.itemView.findViewById(R.id.comment)).isNotVisible();
}
use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.
the class ListFragmentViewHolderEdgeTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
TestApplication.applicationGraph.inject(this);
reset(itemManager);
controller = Robolectric.buildActivity(ListActivity.class).create().start().resume().visible();
ListActivity activity = controller.get();
Bundle args = new Bundle();
args.putString(ListFragment.EXTRA_ITEM_MANAGER, HackerNewsClient.class.getName());
args.putString(ListFragment.EXTRA_FILTER, ItemManager.TOP_FETCH_MODE);
activity.getSupportFragmentManager().beginTransaction().add(android.R.id.content, Fragment.instantiate(activity, ListFragment.class.getName(), args)).commit();
verify(itemManager).getStories(any(), eq(ItemManager.MODE_DEFAULT), storiesListener.capture());
storiesListener.getValue().onResponse(new Item[] { new TestHnItem(1L) });
RecyclerView recyclerView = (RecyclerView) activity.findViewById(R.id.recycler_view);
ShadowRecyclerViewAdapter shadowAdapter = customShadowOf(recyclerView.getAdapter());
holder = shadowAdapter.getViewHolder(0);
}
Aggregations