org.robolectric.shadows.ShadowAlertDialog Java Examples

The following examples show how to use org.robolectric.shadows.ShadowAlertDialog. 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: AppUtilsTest.java    From materialistic with Apache License 2.0 6 votes vote down vote up
@Test
public void testOpenExternalComment() {
    ActivityController<TestListActivity> controller = Robolectric.buildActivity(TestListActivity.class);
    TestListActivity activity = controller.create().start().resume().get();
    AppUtils.openExternal(activity, mock(PopupMenu.class),
            new View(activity), new TestHnItem(1), null);
    assertNull(ShadowAlertDialog.getLatestAlertDialog());
    AppUtils.openExternal(activity, mock(PopupMenu.class),
            new View(activity), new TestHnItem(1) {
                @Override
                public String getUrl() {
                    return String.format(HackerNewsClient.WEB_ITEM_PATH, "1");
                }
            }, null);
    assertNull(ShadowAlertDialog.getLatestAlertDialog());
    controller.destroy();
}
 
Example #2
Source File: UTest.java    From Taskbar with Apache License 2.0 6 votes vote down vote up
private void testShowPermissionDialog(boolean hasAndroidTVSettings,
                                      String message,
                                      int buttonTextResId) throws Exception {
    RunnableHooker onError = new RunnableHooker();
    RunnableHooker onFinish = new RunnableHooker();
    PowerMockito.spy(U.class);
    when(U.class, "hasAndroidTVSettings", context).thenReturn(hasAndroidTVSettings);
    AlertDialog dialog = U.showPermissionDialog(context, new Callbacks(onError, onFinish));
    ShadowAlertDialog shadowDialog = Shadows.shadowOf(dialog);
    Resources resources = context.getResources();
    assertEquals(
            resources.getString(R.string.tb_permission_dialog_title),
            shadowDialog.getTitle()
    );
    assertEquals(message, shadowDialog.getMessage());
    Button positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
    assertEquals(resources.getString(buttonTextResId), positiveButton.getText());
    assertFalse(shadowDialog.isCancelable());
    positiveButton.performClick();
    assertTrue(onFinish.hasRun());
    assertFalse(onError.hasRun());
}
 
Example #3
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 #4
Source File: DirectoryChooserFragmentTest.java    From droid-stealth with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testCreateDirectoryDialog() {
	final String directoryName = "mydir";
	final DirectoryChooserFragment fragment = DirectoryChooserFragment.newInstance(
			directoryName, null);

	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 = Robolectric.shadowOf(dialog);
	assertEquals(shadowAlertDialog.getTitle(), "Create folder");
	assertEquals(shadowAlertDialog.getMessage(), "Create new folder with name \"mydir\"?");
}
 
Example #5
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 #6
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 #7
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 #8
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 #9
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 #10
Source File: SubmitActivityTest.java    From materialistic with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubmitError() {
    ((EditText) activity.findViewById(R.id.edittext_title)).setText("title");
    ((EditText) activity.findViewById(R.id.edittext_content)).setText("http://example.com");
    shadowOf(activity).clickMenuItem(R.id.menu_send);
    ShadowAlertDialog.getLatestAlertDialog().getButton(DialogInterface.BUTTON_POSITIVE)
            .performClick();
    verify(userServices).submit(any(Context.class), eq("title"), eq("http://example.com"),
            eq(true), submitCallback.capture());
    Uri redirect = Uri.parse(BuildConfig.APPLICATION_ID + "://item?id=1234");
    UserServices.Exception exception = new UserServices.Exception(R.string.item_exist);
    exception.data = redirect;
    submitCallback.getValue().onError(exception);
    assertEquals(activity.getString(R.string.item_exist), ShadowToast.getTextOfLatestToast());
    assertThat(shadowOf(activity).getNextStartedActivity())
            .hasAction(Intent.ACTION_VIEW)
            .hasData(redirect);
}
 
Example #11
Source File: AppUtilsTest.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@Test
public void testShareComment() {
    AppUtils.share(context, mock(PopupMenu.class),
            new View(context), new TestHnItem(1));
    assertNull(ShadowAlertDialog.getLatestAlertDialog());
    AppUtils.share(context, mock(PopupMenu.class),
            new View(context), new TestHnItem(1) {
                @Override
                public String getUrl() {
                    return String.format(HackerNewsClient.WEB_ITEM_PATH, "1");
                }
            });
    assertNull(ShadowAlertDialog.getLatestAlertDialog());
}
 
Example #12
Source File: SubmitActivityTest.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubmitDelayedFailed() {
    ((EditText) activity.findViewById(R.id.edittext_title)).setText("title");
    ((EditText) activity.findViewById(R.id.edittext_content)).setText("http://example.com");
    shadowOf(activity).clickMenuItem(R.id.menu_send);
    ShadowAlertDialog.getLatestAlertDialog().getButton(DialogInterface.BUTTON_POSITIVE)
            .performClick();
    verify(userServices).submit(any(Context.class), eq("title"), eq("http://example.com"),
            eq(true), submitCallback.capture());
    shadowOf(activity).clickMenuItem(android.R.id.home);
    ShadowAlertDialog.getLatestAlertDialog().getButton(DialogInterface.BUTTON_POSITIVE)
            .performClick();
    submitCallback.getValue().onDone(false);
    assertNull(shadowOf(activity).getNextStartedActivity());
}
 
Example #13
Source File: AppUtilsTest.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoginShowChooser() {
    TestApplication.applicationGraph.inject(this);
    shadowOf(AccountManager.get(context))
            .addAccount(new Account("username", BuildConfig.APPLICATION_ID));
    AppUtils.showLogin(context, alertDialogBuilder);
    assertNotNull(ShadowAlertDialog.getLatestAlertDialog());
}
 
Example #14
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 #15
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 #16
Source File: RideRequestActivityTest.java    From rides-android-sdk with MIT License 5 votes vote down vote up
@Test
public void onLoad_whenLoginErrorOccurs_shouldReturnErrorResultIntent() {
    ShadowActivity shadowActivity = shadowOf(activity);
    activity.onLoginError(AuthenticationError.MISMATCHING_REDIRECT_URI);
    ShadowAlertDialog shadowAlertDialog = shadowOf(activity.authenticationErrorDialog);

    String message = "There was a problem authenticating you.";
    assertEquals(message, shadowAlertDialog.getMessage());
    activity.authenticationErrorDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick();

    Assert.assertNotNull(shadowActivity.getResultIntent());
    assertEquals(shadowActivity.getResultCode(), Activity.RESULT_CANCELED);
    assertEquals(AuthenticationError.MISMATCHING_REDIRECT_URI, shadowActivity.getResultIntent().getSerializableExtra
            (RideRequestActivity.AUTHENTICATION_ERROR));
}
 
Example #17
Source File: RideRequestActivityTest.java    From rides-android-sdk with MIT License 5 votes vote down vote up
@Test
public void onLoad_whenSomeRideRequestViewErrorOccurs_shouldReturnResultIntentError() {
    ShadowActivity shadowActivity = shadowOf(activity);
    activity.onErrorReceived(RideRequestViewError.UNKNOWN);
    ShadowAlertDialog shadowAlertDialog = shadowOf(activity.rideRequestErrorDialog);

    String message = "The Ride Request Widget encountered a problem.";
    assertEquals(message, shadowAlertDialog.getMessage());
    activity.rideRequestErrorDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick();

    assertNotNull(shadowActivity.getResultIntent());
    assertEquals(Activity.RESULT_CANCELED, shadowActivity.getResultCode());
    assertEquals(RideRequestViewError.UNKNOWN, shadowActivity.getResultIntent().getSerializableExtra
            (RideRequestActivity.RIDE_REQUEST_ERROR));
}
 
Example #18
Source File: RideRequestActivityTest.java    From rides-android-sdk with MIT License 5 votes vote down vote up
@Test
public void onLoad_whenErrorOccursAndUserHitsBackWhenAlertShows_shouldReturnResultIntentError() {
    ShadowActivity shadowActivity = shadowOf(activity);
    activity.onErrorReceived(RideRequestViewError.UNKNOWN);
    ShadowAlertDialog shadowAlertDialog = shadowOf(activity.rideRequestErrorDialog);

    String message = "The Ride Request Widget encountered a problem.";
    assertEquals(message, shadowAlertDialog.getMessage());
    activity.rideRequestErrorDialog.onBackPressed();

    assertNotNull(shadowActivity.getResultIntent());
    assertEquals(Activity.RESULT_CANCELED, shadowActivity.getResultCode());
    assertEquals(RideRequestViewError.UNKNOWN, shadowActivity.getResultIntent().getSerializableExtra
            (RideRequestActivity.RIDE_REQUEST_ERROR));
}
 
Example #19
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 #20
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 #21
Source File: AboutFragmentTest.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
private void validateAlertDialogClickListener(int viewId, int titleId, int messageId) {
    // setup
    View view = fixture.getView().findViewById(viewId);
    String expectedTitle = mainActivity.getApplicationContext().getString(titleId);
    String expectedMessage = FileUtils.readFile(mainActivity.getResources(), messageId);
    // execute
    view.performClick();
    // validate
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    ShadowAlertDialog shadowAlertDialog = Shadows.shadowOf(alertDialog);
    assertEquals(expectedTitle, shadowAlertDialog.getTitle().toString());
    assertEquals(expectedMessage, shadowAlertDialog.getMessage().toString());
}
 
Example #22
Source File: FilterTest.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testTitle() {
    // setup
    String expected = mainActivity.getResources().getString(R.string.filter_title);
    ShadowAlertDialog shadowAlertDialog = shadowOf(alertDialog);
    // execute
    CharSequence actual = shadowAlertDialog.getTitle();
    // validate
    assertEquals(expected, actual.toString());
}
 
Example #23
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 #24
Source File: DirectoryChooserFragmentTest.java    From Android-DirectoryChooser with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #25
Source File: DirectoryChooserFragmentTest.java    From Android-DirectoryChooser with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #26
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 #27
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 #28
Source File: UTest.java    From Taskbar with Apache License 2.0 5 votes vote down vote up
@Test
public void testShowErrorDialog() {
    RunnableHooker onFinish = new RunnableHooker();
    String appOpCommand = "app-op-command";
    AlertDialog dialog =
            ReflectionHelpers.callStaticMethod(
                    U.class,
                    "showErrorDialog",
                    from(Context.class, context),
                    from(String.class, appOpCommand),
                    from(Callbacks.class, new Callbacks(null, onFinish))
            );
    ShadowAlertDialog shadowDialog = Shadows.shadowOf(dialog);
    Resources resources = context.getResources();
    assertEquals(
            resources.getString(R.string.tb_error_dialog_title),
            shadowDialog.getTitle()
    );
    assertEquals(
            resources.getString(
                    R.string.tb_error_dialog_message,
                    context.getPackageName(),
                    appOpCommand
            ),
            shadowDialog.getMessage()
    );
    Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
    assertEquals(resources.getString(R.string.tb_action_ok), button.getText());
    assertFalse(shadowDialog.isCancelable());
    button.performClick();
    assertTrue(onFinish.hasRun());
}
 
Example #29
Source File: VaultManagerActivityUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
private static androidx.appcompat.app.AlertDialog getDeleteConfirmationDialog() {
    // ShadowAlertDialog#getLatestDialog does not return
    // the support AlertDialog.
    //
    // This allows us to return the first (and only) v7 alert dialog
    return (androidx.appcompat.app.AlertDialog) ShadowAlertDialog.getShownDialogs().get(0);
}
 
Example #30
Source File: JSExceptionCatcherTest.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
@Test
public void catchException() throws Exception {
    String fakeErrCode = "fake_error_code";
    String fakeMsg = "fake_msg";
    AlertDialog dialog = JSExceptionCatcher.catchException(RuntimeEnvironment.application,null,null,fakeErrCode,fakeMsg);

    assertNotNull(dialog);
    ShadowAlertDialog shadowAlertDialog = shadowOf(dialog);
    assertEquals(dialog.isShowing(),true);
    assertEquals(ShadowAlertDialog.getLatestAlertDialog(),dialog);

    assertEquals("WeexAnalyzer捕捉到异常",shadowAlertDialog.getTitle());
}