use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.
the class HackerNewsItemTest method testGetSource.
@Test
public void testGetSource() {
assertEquals("news.ycombinator.com", item.getSource());
item.populate(new TestItem() {
@Override
public String getRawUrl() {
return "http://example.com";
}
});
assertEquals("example.com", item.getSource());
}
use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.
the class HackerNewsItemTest method testParcelFavorite.
@Test
public void testParcelFavorite() {
Parcel parcel = Parcel.obtain();
item.populate(new TestItem() {
});
item.setFavorite(true);
item.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
assertTrue(HackerNewsItem.CREATOR.createFromParcel(parcel).isFavorite());
}
use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.
the class HackerNewsItemTest method testGetKidItems.
@Test
public void testGetKidItems() {
assertThat(item.getKidItems()).isEmpty();
item.populate(new TestItem() {
@Override
public long[] getKids() {
return new long[] { 1l, 2l };
}
});
assertThat(item.getKidItems()).hasSize(2);
assertEquals(1, item.getKidItems()[0].getRank());
assertEquals(2, item.getKidItems()[1].getRank());
}
use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.
the class ItemActivityTest method testPoll.
@Test
public void testPoll() {
Intent intent = new Intent();
intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() {
@NonNull
@Override
public String getType() {
return POLL_TYPE;
}
@Override
public boolean isStoryType() {
return true;
}
@Override
public String getUrl() {
return "http://example.com";
}
});
controller.withIntent(intent).create().start().resume();
assertThat(activity.findViewById(R.id.source)).isNotVisible();
assertEquals(R.drawable.ic_poll_white_18dp, shadowOf(((TextView) activity.findViewById(R.id.posted)).getCompoundDrawables()[0]).getCreatedFromResId());
}
use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.
the class ItemActivityTest method testJobGivenDeepLink.
@Test
public void testJobGivenDeepLink() {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://news.ycombinator.com/item?id=1"));
controller.withIntent(intent).create().start().resume();
verify(hackerNewsClient).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), listener.capture());
listener.getValue().onResponse(new TestItem() {
@NonNull
@Override
public String getType() {
return JOB_TYPE;
}
@Override
public String getId() {
return "1";
}
@Override
public String getUrl() {
return String.format(HackerNewsClient.WEB_ITEM_PATH, "1");
}
@Override
public String getSource() {
return "http://example.com";
}
@Override
public boolean isStoryType() {
return true;
}
});
assertEquals(R.drawable.ic_work_white_18dp, shadowOf(((TextView) activity.findViewById(R.id.posted)).getCompoundDrawables()[0]).getCreatedFromResId());
assertThat((TextView) activity.findViewById(R.id.source)).hasText("http://example.com");
reset(hackerNewsClient);
shadowOf(activity).recreate();
verify(hackerNewsClient, never()).getItem(any(), eq(ItemManager.MODE_DEFAULT), any(ResponseListener.class));
}
Aggregations