use of io.github.hidroh.materialistic.data.TestFavorite in project materialistic by hidroh.
the class FavoriteActivityTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
TestApplication.applicationGraph.inject(this);
reset(favoriteManager);
reset(userServices);
reset(keyDelegate);
reset(actionViewResolver.getActionView(mock(MenuItem.class)));
controller = Robolectric.buildActivity(TestFavoriteActivity.class);
when(favoriteManager.getSize()).thenReturn(2);
when(favoriteManager.getItem(eq(0))).thenReturn(new TestFavorite("1", "http://example.com", "title", System.currentTimeMillis()));
when(favoriteManager.getItem(eq(1))).thenReturn(new TestFavorite("2", "http://example.com", "ask HN", System.currentTimeMillis()));
// skip menu due to search view
activity = controller.create().postCreate(null).start().resume().visible().get();
recyclerView = (RecyclerView) activity.findViewById(R.id.recycler_view);
adapter = recyclerView.getAdapter();
shadowAdapter = customShadowOf(adapter);
fragment = activity.getSupportFragmentManager().findFragmentById(android.R.id.list);
verify(keyDelegate).attach(any(Activity.class));
verify(favoriteManager).attach(any(Context.class), any(LoaderManager.class), observerCaptor.capture(), any());
}
use of io.github.hidroh.materialistic.data.TestFavorite in project materialistic by hidroh.
the class FavoriteActivityTest method testSearchView.
@Test
public void testSearchView() {
SearchView searchView = (SearchView) actionViewResolver.getActionView(mock(MenuItem.class));
verify(searchView, atLeastOnce()).setOnSearchClickListener(searchViewClickListener.capture());
verify(searchView, atLeastOnce()).setOnCloseListener(searchViewCloseListener.capture());
searchViewClickListener.getAllValues().get(searchViewClickListener.getAllValues().size() - 1).onClick(searchView);
assertFalse(((FavoriteFragment) fragment).startActionMode(null));
SearchView.OnCloseListener closeListener = searchViewCloseListener.getAllValues().get(searchViewCloseListener.getAllValues().size() - 1);
closeListener.onClose();
assertEquals(2, adapter.getItemCount());
((FavoriteFragment) fragment).filter("ask");
verify(favoriteManager, times(2)).attach(any(Context.class), any(LoaderManager.class), observerCaptor.capture(), any());
when(favoriteManager.getSize()).thenReturn(1);
when(favoriteManager.getItem(eq(0))).thenReturn(new TestFavorite("2", "http://example.com", "ask HN", System.currentTimeMillis()));
observerCaptor.getValue().onChanged();
assertEquals(1, adapter.getItemCount());
reset(searchView);
closeListener.onClose();
verify(searchView).setQuery(eq(FavoriteActivity.EMPTY_QUERY), eq(true));
}
Aggregations