@Test public void testNullResponse() { verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), listener.capture()); listener.getValue().onResponse(null); assertThat((TextView) holder.itemView.findViewById(R.id.title)) .hasText(R.string.loading_text); }
@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); }
@Test public void testErrorResponse() { verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), listener.capture()); listener.getValue().onError(null); assertThat((TextView) holder.itemView.findViewById(R.id.title)) .hasText(R.string.loading_text); }
@Test public void testHelp() { ((PreferencesActivity.SettingsFragment) activity.getSupportFragmentManager() .findFragmentByTag(PreferencesActivity.SettingsFragment.class.getName())) .getPreferenceScreen() .findPreference(activity.getString(R.string.pref_volume_help)) .performClick(); Dialog dialog = ShadowDialog.getLatestDialog(); assertNotNull(dialog); assertThat((TextView) dialog.findViewById(R.id.alertTitle)) .hasText(R.string.pref_volume_title); }
@Test public void testLazyLoadHelp() { ((PreferencesActivity.SettingsFragment) activity.getSupportFragmentManager() .findFragmentByTag(PreferencesActivity.SettingsFragment.class.getName())) .getPreferenceScreen() .findPreference(activity.getString(R.string.pref_lazy_load_help)) .performClick(); Dialog dialog = ShadowDialog.getLatestDialog(); assertNotNull(dialog); assertThat((TextView) dialog.findViewById(R.id.alertTitle)) .hasText(R.string.pref_lazy_load_title); }
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();
@Test public void testNoExistingAccount() { assertThat(drawerAccount).hasText(R.string.login); assertThat(drawerLogout).isNotVisible(); assertThat(drawerUser).isNotVisible(); Preferences.setUsername(activity, "username"); assertThat(drawerAccount).hasText("username"); assertThat(drawerLogout).isVisible(); assertThat(drawerUser).isVisible(); drawerLogout.performClick(); AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog(); assertNotNull(alertDialog); alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick(); assertThat(drawerAccount).hasText(R.string.login); assertThat(drawerLogout).isNotVisible(); }
@Test public void testExistingAccount() { AccountManager.get(activity).addAccountExplicitly(new Account("existing", BuildConfig.APPLICATION_ID), "password", null); drawerAccount.performClick(); AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog(); assertNotNull(alertDialog); assertThat(alertDialog.getListView().getAdapter()).hasCount(1); shadowOf(alertDialog).clickOnItem(0); alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick(); assertThat(alertDialog).isNotShowing(); assertThat(drawerAccount).hasText("existing"); assertThat(drawerLogout).isVisible(); drawerAccount.performClick(); alertDialog = ShadowAlertDialog.getLatestAlertDialog(); assertThat(alertDialog.getListView().getAdapter()).hasCount(1); }
@Test public void testCreateDirectoryDialogDisallowFolderNameModification() { final String directoryName = "mydir"; final DirectoryChooserFragment fragment = DirectoryChooserFragment.newInstance( DirectoryChooserConfig.builder() .newDirectoryName(directoryName) .initialDirectory("") .allowReadOnlyDirectory(false) .allowNewDirectoryNameModification(false) .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).isGone(); }