Search in sources :

Example 16 with TestHnItem

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

Example 17 with TestHnItem

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;
        }
    } });
}
Also used : Context(android.content.Context) NonNull(android.support.annotation.NonNull) Intent(android.content.Intent) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) Before(org.junit.Before)

Example 18 with TestHnItem

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);
}
Also used : 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) Test(org.junit.Test)

Example 19 with TestHnItem

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

Example 20 with TestHnItem

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);
}
Also used : Bundle(android.os.Bundle) RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerViewAdapter(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerViewAdapter) 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)

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