Java Code Examples for org.robolectric.shadows.ShadowAlertDialog#getLatestAlertDialog()

The following examples show how to use org.robolectric.shadows.ShadowAlertDialog#getLatestAlertDialog() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FavoriteActivityTest.java    From materialistic with Apache License 2.0 6 votes vote down vote up
@Test
public void testOptionsMenuClear() {
    assertTrue(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_clear).isVisible());
    shadowOf(activity).clickMenuItem(R.id.menu_clear);
    AlertDialog dialog = ShadowAlertDialog.getLatestAlertDialog();
    dialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();
    assertEquals(2, adapter.getItemCount());

    shadowOf(activity).clickMenuItem(R.id.menu_clear);
    dialog = ShadowAlertDialog.getLatestAlertDialog();
    dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    verify(favoriteManager).clear(any(Context.class), any());
    when(favoriteManager.getSize()).thenReturn(0);
    observerCaptor.getValue().onChanged();
    assertEquals(0, adapter.getItemCount());
}
 
Example 2
Source File: FavoriteActivityTest.java    From materialistic with Apache License 2.0 6 votes vote down vote up
@Test
public void testDelete() {
    RecyclerView.ViewHolder holder = shadowAdapter.getViewHolder(0);
    holder.itemView.performLongClick();

    ActionMode actionMode = mock(ActionMode.class);
    activity.actionModeCallback.onActionItemClicked(actionMode, new RoboMenuItem(R.id.menu_clear));
    AlertDialog dialog = ShadowAlertDialog.getLatestAlertDialog();
    dialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();
    assertEquals(2, adapter.getItemCount());

    activity.actionModeCallback.onActionItemClicked(actionMode, new RoboMenuItem(R.id.menu_clear));
    dialog = ShadowAlertDialog.getLatestAlertDialog();
    dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    verify(favoriteManager).remove(any(Context.class), selection.capture());
    assertThat(selection.getValue()).contains("1");
    verify(actionMode).finish();

    when(favoriteManager.getSize()).thenReturn(1);
    observerCaptor.getValue().onChanged();
    assertEquals(1, adapter.getItemCount());
}
 
Example 3
Source File: DrawerActivityLoginTest.java    From materialistic with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 4
Source File: DrawerActivityLoginTest.java    From materialistic with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 5
Source File: DrawerActivityLoginTest.java    From materialistic with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddAccount() {
    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);
    alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();
    assertThat(alertDialog).isNotShowing();
    ((ShadowSupportDrawerLayout) Shadow.extract(activity.findViewById(R.id.drawer_layout)))
            .getDrawerListeners().get(0)
            .onDrawerClosed(activity.findViewById(R.id.drawer));
    assertThat(shadowOf(activity).getNextStartedActivity())
            .hasComponent(activity, LoginActivity.class);
}
 
Example 6
Source File: TestActivityTest.java    From Awesome-WanAndroid with Apache License 2.0 6 votes vote down vote up
@Test
public void showDialog() {
    AlertDialog latestAlertDialog = ShadowAlertDialog.getLatestAlertDialog();
    Assert.assertNull(latestAlertDialog);

    Button button = (Button) mTestActivity.findViewById(R.id.button3);
    button.performClick();

    latestAlertDialog = ShadowAlertDialog.getLatestAlertDialog();
    Assert.assertNotNull(latestAlertDialog);

    ShadowAlertDialog shadowAlertDialog = Shadows.shadowOf(latestAlertDialog);
    Assert.assertEquals("Dialog", shadowAlertDialog.getTitle());
    ShadowLog.d("dialog_tag", (String) shadowAlertDialog.getMessage());
    Assert.assertEquals("showDialog", shadowAlertDialog.getMessage());
}
 
Example 7
Source File: SubmitActivityTest.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@Test
public void testOnBackPressed() {
    shadowOf(activity).clickMenuItem(android.R.id.home);
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    assertThat(activity).isFinishing();
}
 
Example 8
Source File: DialogWithBlurredBackgroundLauncherTest.java    From fogger with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldShowGivenDialog() {
    //when
    mDialogWithBlurredBackgroundLauncher.showDialog(dialog);

    //then
    AlertDialog alert = ShadowAlertDialog.getLatestAlertDialog();
    assertThat(dialog).isEqualTo(alert);
}
 
Example 9
Source File: LegacyUriRedirectHandlerTest.java    From rides-android-sdk with MIT License 5 votes vote down vote up
private void assertDialogShown() {
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertThat(alertDialog.isShowing()).isTrue();
    assertThat(shadowOf(alertDialog).getTitle())
            .isEqualTo(alertTitle);
    assertThat(shadowOf(alertDialog).getMessage())
            .isEqualTo(alertMessage);
}
 
Example 10
Source File: SettingsActivityTest.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@Test
public void testReset() {
    PreferenceManager.getDefaultSharedPreferences(activity)
            .edit()
            .putBoolean(activity.getString(R.string.pref_color_code), false)
            .apply();
    assertFalse(Preferences.colorCodeEnabled(activity));
    assertNotNull(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_reset));
    shadowOf(activity).clickMenuItem(R.id.menu_reset);
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    assertTrue(Preferences.colorCodeEnabled(activity));
}
 
Example 11
Source File: SettingsActivityTest.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@Test
public void testClearRecentSearches() {
    ShadowSearchRecentSuggestions.historyClearCount = 0;
    assertNotNull(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_clear_recent));
    shadowOf(activity).clickMenuItem(R.id.menu_clear_recent);
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    assertEquals(1, ShadowSearchRecentSuggestions.historyClearCount);
}
 
Example 12
Source File: ComposeActivityTest.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@Test
public void testExitDiscardDraft() {
    ((EditText) activity.findViewById(R.id.edittext_body)).setText("Reply");
    shadowOf(activity).clickMenuItem(android.R.id.home);
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();
    assertThat(activity).isFinishing();
    assertThat(Preferences.getDraft(activity, "1")).isNullOrEmpty();
}
 
Example 13
Source File: ComposeActivityTest.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@Test
public void testExitSaveDraft() {
    ((EditText) activity.findViewById(R.id.edittext_body)).setText("Reply");
    shadowOf(activity).clickMenuItem(android.R.id.home);
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    assertThat(activity).isFinishing();
    assertThat(Preferences.getDraft(activity, "1")).contains("Reply");
}
 
Example 14
Source File: SignInDialogTest.java    From Inside_Android_Testing with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldShowAlertDialogWhenUnSuccessfullySignedIn() throws Exception {
    usernameEditText.setText("Spongebob");
    passwordEditText.setText("squidward");
    clickOn(signInButton);

    apiGateway.simulateResponse(401, "Access Denied");

    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertThat(alertDialog.isShowing(), equalTo(true));
    assertThat(((String) shadowOf(alertDialog).getTitle()), equalTo("Error"));
    assertThat(((String) shadowOf(alertDialog).getMessage()), equalTo("Username/Password combination is not recognized."));
    assertNotNull(alertDialog.getButton(AlertDialog.BUTTON_POSITIVE));
}
 
Example 15
Source File: SubmitActivityTest.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubmitText() {
    ((EditText) activity.findViewById(R.id.edittext_title)).setText("title");
    ((EditText) activity.findViewById(R.id.edittext_content)).setText("content");
    shadowOf(activity).clickMenuItem(R.id.menu_send);
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    assertEquals(activity.getString(R.string.confirm_submit_question),
            shadowOf(alertDialog).getMessage());
}
 
Example 16
Source File: DrawerActivityLoginTest.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@Config(sdk = 21)
@Test
public void testRemoveAccount() {
    AccountManager.get(activity).addAccountExplicitly(new Account("existing",
            BuildConfig.APPLICATION_ID), "password", null);
    Preferences.setUsername(activity, "existing");
    drawerAccount.performClick();
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    assertThat(alertDialog.getListView().getAdapter()).hasCount(1);
    alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL).performClick();
    assertThat(alertDialog).isNotShowing();
    assertThat(AccountManager.get(activity).getAccounts()).isEmpty();
}
 
Example 17
Source File: NoInternetActivityTest.java    From ello-android with MIT License 5 votes vote down vote up
@Test
public void tapRefreshShowsAlertWhenInternetNotPresent()
{
    when(reachability.isNetworkConnected()).thenReturn(false);

    button.performClick();
    AlertDialog alert = ShadowAlertDialog.getLatestAlertDialog();
    ShadowAlertDialog sAlert = shadowOf(alert);

    assertThat(sAlert.getTitle().toString(),
            equalTo(activity.getString(R.string.error)));
    assertThat(sAlert.getMessage().toString(),
            equalTo(activity.getString(R.string.couldnt_connect_error)));
}
 
Example 18
Source File: Assert.java    From fyber_mobile_offers with MIT License 4 votes vote down vote up
public static void assertAlertDialogIsShown(@StringRes int title, @StringRes int message) {
    AlertDialog alert = ShadowAlertDialog.getLatestAlertDialog();
    ShadowAlertDialog shadowAlertDialog = shadowOf(alert);
    assertThat(shadowAlertDialog.getTitle().toString(), equalTo(getString(title)));
    assertThat(shadowAlertDialog.getMessage().toString(), equalTo(getString(message)));
}
 
Example 19
Source File: Assert.java    From marvel with MIT License 4 votes vote down vote up
public static void assertAlertDialogIsShown(@StringRes int title, @StringRes int message) {
    AlertDialog alert = ShadowAlertDialog.getLatestAlertDialog();
    ShadowAlertDialog shadowAlertDialog = shadowOf(alert);
    assertThat(shadowAlertDialog.getTitle().toString(), equalTo(getString(title)));
    assertThat(shadowAlertDialog.getMessage().toString(), equalTo(getString(message)));
}
 
Example 20
Source File: LegacyUriRedirectHandlerTest.java    From rides-android-sdk with MIT License 4 votes vote down vote up
private void assertNoDialogShown() {
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertThat(alertDialog).isNull();
}