Search in sources :

Example 6 with TestHnItem

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));
}
Also used : ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) ShadowItemTouchHelper(io.github.hidroh.materialistic.test.shadow.ShadowItemTouchHelper) Bundle(android.os.Bundle) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) HackerNewsClient(io.github.hidroh.materialistic.data.HackerNewsClient) ListActivity(io.github.hidroh.materialistic.test.ListActivity) Before(org.junit.Before)

Example 7 with TestHnItem

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");
}
Also used : ShadowSwipeRefreshLayout(io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) TextView(android.widget.TextView) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 8 with TestHnItem

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");
}
Also used : ShadowSwipeRefreshLayout(io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) TextView(android.widget.TextView) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 9 with TestHnItem

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();
}
Also used : TestListActivity(io.github.hidroh.materialistic.test.TestListActivity) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) View(android.view.View) TextView(android.widget.TextView) PopupMenu(io.github.hidroh.materialistic.widget.PopupMenu) Test(org.junit.Test)

Example 10 with TestHnItem

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());
}
Also used : TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) View(android.view.View) TextView(android.widget.TextView) PopupMenu(io.github.hidroh.materialistic.widget.PopupMenu) Test(org.junit.Test)

Aggregations

TestHnItem (io.github.hidroh.materialistic.data.TestHnItem)35 Test (org.junit.Test)31 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)23 RecyclerView (android.support.v7.widget.RecyclerView)12 TextView (android.widget.TextView)9 Intent (android.content.Intent)8 Bundle (android.os.Bundle)8 NonNull (android.support.annotation.NonNull)8 ShadowRecyclerView (io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView)8 ShadowSwipeRefreshLayout (io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout)6 Context (android.content.Context)5 TestItem (io.github.hidroh.materialistic.test.TestItem)5 Before (org.junit.Before)4 Fragment (android.support.v4.app.Fragment)3 View (android.view.View)3 HackerNewsClient (io.github.hidroh.materialistic.data.HackerNewsClient)3 Item (io.github.hidroh.materialistic.data.Item)3 WebItem (io.github.hidroh.materialistic.data.WebItem)3 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)3 ShadowContentObserver (org.robolectric.shadows.ShadowContentObserver)3