use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.
the class WebFragmentLocalTest method testMenu.
@Test
public void testMenu() {
TestWebItem item = new TestWebItem() {
@NonNull
@Override
public String getType() {
return STORY_TYPE;
}
@Override
public String getId() {
return "1";
}
@Override
public String getUrl() {
return String.format(HackerNewsClient.WEB_ITEM_PATH, "1");
}
@Override
public String getDisplayedTitle() {
return "Ask HN";
}
};
Intent intent = new Intent();
intent.putExtra(WebActivity.EXTRA_ITEM, item);
controller.withIntent(intent).create().start().resume().visible();
verify(itemManager).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), listener.capture());
listener.getValue().onResponse(new TestItem() {
@Override
public String getText() {
return "text";
}
});
Fragment fragment = activity.getSupportFragmentManager().findFragmentByTag(WebFragment.class.getName());
assertTrue(fragment.hasOptionsMenu());
fragment.onOptionsItemSelected(new RoboMenuItem(R.id.menu_font_options));
assertNotNull(ShadowDialog.getLatestDialog());
PreferenceManager.getDefaultSharedPreferences(activity).edit().putString(activity.getString(R.string.pref_readability_font), "DroidSans.ttf").apply();
WebView webView = (WebView) activity.findViewById(R.id.web_view);
ShadowWebView shadowWebView = shadowOf(webView);
shadowWebView.getWebViewClient().onPageFinished(webView, "about:blank");
assertThat(shadowWebView.getLastLoadDataWithBaseURL().data).contains("text").contains("DroidSans.ttf");
}
use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.
the class WebFragmentLocalTest method testComment.
@Test
public void testComment() {
TestItem item = new TestItem() {
@NonNull
@Override
public String getType() {
return COMMENT_TYPE;
}
@Override
public String getId() {
return "1";
}
@Override
public String getUrl() {
return String.format(HackerNewsClient.WEB_ITEM_PATH, "1");
}
@Override
public String getText() {
return "comment";
}
};
Intent intent = new Intent();
intent.putExtra(WebActivity.EXTRA_ITEM, item);
controller.withIntent(intent).create().start().resume().visible();
WebView webView = (WebView) activity.findViewById(R.id.web_view);
ShadowWebView shadowWebView = shadowOf(webView);
shadowWebView.getWebViewClient().onPageFinished(webView, "about:blank");
assertThat(shadowWebView.getLastLoadDataWithBaseURL().data).contains("comment");
}
use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.
the class HackerNewsItemTest method testPopulate.
@Test
public void testPopulate() {
item.populate(new TestItem() {
@Override
public String getTitle() {
return "title";
}
@Override
public String getRawType() {
return "rawType";
}
@Override
public String getRawUrl() {
return "rawUrl";
}
@Override
public long[] getKids() {
return new long[] { 1l };
}
@Override
public String getBy() {
return "by";
}
@Override
public long getTime() {
return 1234l;
}
@Override
public String getText() {
return "text";
}
@Override
public String getParent() {
return "1";
}
@Override
public boolean isDead() {
return true;
}
@Override
public boolean isDeleted() {
return true;
}
@Override
public int getDescendants() {
return 1;
}
@Override
public int getScore() {
return 5;
}
});
assertEquals("title", item.getTitle());
assertEquals("text", item.getText());
assertEquals("rawType", item.getRawType());
assertEquals("rawUrl", item.getRawUrl());
assertEquals("by", item.getBy());
assertEquals(1234l, item.getTime());
assertEquals(1, item.getDescendants());
assertEquals(1, item.getLastKidCount());
assertEquals(5, item.getScore());
assertTrue(item.isDead());
assertTrue(item.isDeleted());
assertThat(item.getDisplayedAuthor(RuntimeEnvironment.application, true, 0)).contains(" - by");
assertThat(item.getDisplayedTime(RuntimeEnvironment.application)).isNotEmpty();
assertThat(item.getKids()).hasSize(1);
assertEquals(1, item.getKidItems()[0].getLevel());
}
use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.
the class HackerNewsItemTest method testKidCountNoDescendants.
@Test
public void testKidCountNoDescendants() {
item.populate(new TestItem() {
@Override
public long[] getKids() {
return new long[] { 1l, 2l };
}
});
assertEquals(2, item.getKidCount());
}
use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.
the class HackerNewsItemTest method testGetUrlStory.
@Test
public void testGetUrlStory() {
item.populate(new TestItem() {
@Override
public String getRawType() {
return "story";
}
@Override
public String getRawUrl() {
return "http://example.com";
}
});
assertEquals("http://example.com", item.getUrl());
}
Aggregations