Search in sources :

Example 1 with TestFavorite

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());
}
Also used : Context(android.content.Context) LoaderManager(android.support.v4.app.LoaderManager) TestFavoriteActivity(io.github.hidroh.materialistic.test.TestFavoriteActivity) TestFavoriteActivity(io.github.hidroh.materialistic.test.TestFavoriteActivity) Activity(android.app.Activity) TestFavorite(io.github.hidroh.materialistic.data.TestFavorite) Before(org.junit.Before)

Example 2 with TestFavorite

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));
}
Also used : Context(android.content.Context) LoaderManager(android.support.v4.app.LoaderManager) SearchView(android.support.v7.widget.SearchView) TestFavorite(io.github.hidroh.materialistic.data.TestFavorite) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Aggregations

Context (android.content.Context)2 LoaderManager (android.support.v4.app.LoaderManager)2 TestFavorite (io.github.hidroh.materialistic.data.TestFavorite)2 Activity (android.app.Activity)1 SearchView (android.support.v7.widget.SearchView)1 TestFavoriteActivity (io.github.hidroh.materialistic.test.TestFavoriteActivity)1 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)1 Before (org.junit.Before)1 Test (org.junit.Test)1