@Test public void testTrimHtmlWhitespaces() { TextView textView = new TextView(context); textView.setText(AppUtils.fromHtml("<p>paragraph</p><p><br/><br/><br/></p>")); assertThat(textView).hasTextString("paragraph"); textView.setText(AppUtils.fromHtml("")); assertThat(textView).hasTextString(""); textView.setText(AppUtils.fromHtml("paragraph")); assertThat(textView).hasTextString("paragraph"); }
@Test public void testStory() { item.setIsViewed(true); verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture()); itemListener.getValue().onResponse(item); RecyclerView.ViewHolder holder = adapter.getViewHolder(0); assertThat((View) holder.itemView.findViewById(R.id.bookmarked)).isNotVisible(); assertThat((TextView) holder.itemView.findViewById(R.id.rank)).hasTextString("46"); assertThat((TextView) holder.itemView.findViewById(R.id.title)).hasTextString("title"); assertThat((TextView) holder.itemView.findViewById(R.id.comment)) .isVisible() .isEmpty(); assertViewed(); }
@Test public void testBinding() { verify(userManager).getUser(eq("username"), userCaptor.capture()); userCaptor.getValue().onResponse(user); assertThat((TextView) activity.findViewById(R.id.title)).hasTextString("username (2,016)"); assertThat((TextView) activity.findViewById(R.id.about)).hasTextString("about"); assertEquals(activity.getResources().getQuantityString(R.plurals.submissions_count, 2, 2), ((TabLayout) activity.findViewById(R.id.tab_layout)).getTabAt(0).getText()); assertEquals(2, (((RecyclerView) activity.findViewById(R.id.recycler_view)).getAdapter()) .getItemCount()); shadowOf(activity).recreate(); assertThat((TextView) activity.findViewById(R.id.title)).hasTextString("username (2,016)"); }
@Test public void testQuote() { assertTrue(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_quote).isVisible()); ((EditText) activity.findViewById(R.id.edittext_body)).setText("Reply"); shadowOf(activity).clickMenuItem(R.id.menu_quote); assertThat((EditText) activity.findViewById(R.id.edittext_body)) .hasTextString("> Paragraph 1\n\n> Paragraph 2\n\nReply"); }
@Test public void testDeriveTitleAndUrl() { controller.pause().stop().destroy(); controller = Robolectric.buildActivity(SubmitActivity.class, new Intent().putExtra(Intent.EXTRA_TEXT, "title - http://example.com")); activity = controller .create().start().resume().visible().get(); assertThat((EditText) activity.findViewById(R.id.edittext_title)).hasTextString("title"); assertThat((EditText) activity.findViewById(R.id.edittext_content)).hasTextString("http://example.com"); shadowOf(activity).recreate(); assertThat((EditText) activity.findViewById(R.id.edittext_title)).hasTextString("title"); assertThat((EditText) activity.findViewById(R.id.edittext_content)).hasTextString("http://example.com"); }
@Test public void testCommentBinding() { 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 String getText() { return "content"; } @Override public String getParent() { return "2"; } }); RecyclerView.ViewHolder viewHolder = customShadowOf(recyclerView.getAdapter()).getViewHolder(0); assertThat((View) viewHolder.itemView.findViewById(R.id.title)).isNotVisible(); assertThat((TextView) viewHolder.itemView.findViewById(R.id.text)) .isVisible() .hasTextString("content"); viewHolder.itemView.findViewById(R.id.comment).performClick(); assertThat(shadowOf(activity).getNextStartedActivity()) .hasComponent(activity, ThreadPreviewActivity.class) .hasExtra(ThreadPreviewActivity.EXTRA_ITEM); }
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())
RecyclerView.ViewHolder viewHolder = CustomShadows.customShadowOf(recyclerView.getAdapter()) .getViewHolder(0); assertThat((TextView) viewHolder.itemView.findViewById(R.id.text)).hasTextString("text"); assertThat((View) viewHolder.itemView.findViewById(R.id.comment)).isVisible(); viewHolder.itemView.findViewById(R.id.comment).performClick();
@Test public void testDeriveEmptyTitle() { controller.pause().stop().destroy(); controller = Robolectric.buildActivity(SubmitActivity.class, new Intent().putExtra(Intent.EXTRA_TEXT, " : http://example.com")); activity = controller .create().start().resume().visible().get(); assertThat((EditText) activity.findViewById(R.id.edittext_title)).isEmpty(); assertThat((EditText) activity.findViewById(R.id.edittext_content)).hasTextString("http://example.com"); }
@Test public void testDeriveNoMatches() { controller.pause().stop().destroy(); controller = Robolectric.buildActivity(SubmitActivity.class, new Intent().putExtra(Intent.EXTRA_TEXT, "title - http://example.com blah blah")); activity = controller .create().start().resume().visible().get(); assertThat((EditText) activity.findViewById(R.id.edittext_title)).isEmpty(); assertThat((EditText) activity.findViewById(R.id.edittext_content)) .hasTextString("title - http://example.com blah blah"); }
@Test public void testToggle() { assertThat((View) activity.findViewById(R.id.toggle)).isVisible(); assertThat((View) activity.findViewById(R.id.text)).isNotVisible(); activity.findViewById(R.id.toggle).performClick(); assertThat((View) activity.findViewById(R.id.text)).isVisible(); assertThat((TextView) activity.findViewById(R.id.text)) .hasTextString("Paragraph 1\n\nParagraph 2"); activity.findViewById(R.id.toggle).performClick(); assertThat((View) activity.findViewById(R.id.text)).isNotVisible(); }
@Test public void testCreateDirectoryDialogAllowFolderNameModification() { final String directoryName = "mydir"; final DirectoryChooserFragment fragment = DirectoryChooserFragment.newInstance( DirectoryChooserConfig.builder() .newDirectoryName(directoryName) .initialDirectory("") .allowReadOnlyDirectory(false) .allowNewDirectoryNameModification(true) .build()); startFragment(fragment, DirectoryChooserActivityMock.class); fragment.onOptionsItemSelected(new TestMenuItem() { @Override public int getItemId() { return R.id.new_folder_item; } }); final AlertDialog dialog = (AlertDialog) ShadowDialog.getLatestDialog(); final ShadowAlertDialog shadowAlertDialog = Shadows.shadowOf(dialog); assertThat(shadowAlertDialog.getTitle()).isEqualTo("Create folder"); assertThat(ShadowDialog.getShownDialogs()).contains(dialog); final TextView msgView = (TextView) dialog.findViewById(R.id.msgText); assertThat(msgView).hasText("Create new folder with name \"mydir\"?"); final EditText editText = (EditText) dialog.findViewById(R.id.editText); assertThat(editText).isVisible(); assertThat(editText).hasTextString(directoryName); }