use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.
the class ListFragmentViewHolderTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
TestApplication.applicationGraph.inject(this);
reset(sessionManager);
reset(favoriteManager);
reset(itemManager);
reset(userServices);
item = new TestHnItem(1) {
@Override
public int getRank() {
return 46;
}
@Override
public String getBy() {
return "author";
}
};
controller = Robolectric.buildActivity(ListActivity.class).create().start().resume().visible();
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[] { item });
recyclerView = (RecyclerView) activity.findViewById(R.id.recycler_view);
swipeCallback = (ItemTouchHelper.SimpleCallback) customShadowOf(recyclerView).getItemTouchHelperCallback();
adapter = customShadowOf(recyclerView.getAdapter());
item.populate(new PopulatedStory(1));
}
use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.
the class ListFragmentViewHolderTest method testPromoted.
@Test
public void testPromoted() {
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) {
@Override
public int getRank() {
return 45;
}
} });
verify(itemManager).getItem(any(), eq(ItemManager.MODE_NETWORK), itemListener.capture());
itemListener.getValue().onResponse(new PopulatedStory(1));
RecyclerView.ViewHolder holder = adapter.getViewHolder(0);
assertThat((TextView) holder.itemView.findViewById(R.id.rank)).containsText("+1");
}
use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.
the class ListFragmentViewHolderTest method testPreferenceChange.
@Test
public void testPreferenceChange() {
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(2) {
@Override
public int getRank() {
return 46;
}
} });
verify(itemManager).getItem(any(), eq(ItemManager.MODE_NETWORK), itemListener.capture());
itemListener.getValue().onResponse(new PopulatedStory(2));
RecyclerView.ViewHolder holder = adapter.getViewHolder(0);
assertThat((TextView) holder.itemView.findViewById(R.id.rank)).hasTextString("46*");
PreferenceManager.getDefaultSharedPreferences(activity).edit().putBoolean(activity.getString(R.string.pref_highlight_updated), false).apply();
holder = adapter.getViewHolder(0);
assertThat((TextView) holder.itemView.findViewById(R.id.rank)).hasTextString("46");
}
use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.
the class AppUtilsTest method testOpenExternalComment.
@Test
public void testOpenExternalComment() {
ActivityController<TestListActivity> controller = Robolectric.buildActivity(TestListActivity.class);
TestListActivity activity = controller.create().get();
AppUtils.openExternal(activity, mock(PopupMenu.class), new View(activity), new TestHnItem(1), null);
assertNull(ShadowAlertDialog.getLatestAlertDialog());
AppUtils.openExternal(activity, mock(PopupMenu.class), new View(activity), new TestHnItem(1) {
@Override
public String getUrl() {
return String.format(HackerNewsClient.WEB_ITEM_PATH, "1");
}
}, null);
assertNull(ShadowAlertDialog.getLatestAlertDialog());
controller.destroy();
}
use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.
the class AppUtilsTest method testShareComment.
@Test
public void testShareComment() {
AppUtils.share(RuntimeEnvironment.application, mock(PopupMenu.class), new View(RuntimeEnvironment.application), new TestHnItem(1));
assertNull(ShadowAlertDialog.getLatestAlertDialog());
AppUtils.share(RuntimeEnvironment.application, mock(PopupMenu.class), new View(RuntimeEnvironment.application), new TestHnItem(1) {
@Override
public String getUrl() {
return String.format(HackerNewsClient.WEB_ITEM_PATH, "1");
}
});
assertNull(ShadowAlertDialog.getLatestAlertDialog());
}
Aggregations