Search in sources :

Example 1 with ShadowAlertDialog

use of org.robolectric.shadows.ShadowAlertDialog in project android-uploader by nightscout.

the class MainActivityTest method testOnCreate_ShouldNotShowIUnderstandDialogIfAlreadySet.

@Test
public void testOnCreate_ShouldNotShowIUnderstandDialogIfAlreadySet() {
    preferences.setIUnderstand(true);
    // make sure we don't have another alert dialog
    preferences.setAskedForData(true);
    activityController.create().get();
    ShadowAlertDialog alertDialog = getShadowApplication().getLatestAlertDialog();
    assertThat(alertDialog, is(nullValue()));
}
Also used : ShadowAlertDialog(org.robolectric.shadows.ShadowAlertDialog) Test(org.junit.Test)

Example 2 with ShadowAlertDialog

use of org.robolectric.shadows.ShadowAlertDialog in project android-uploader by nightscout.

the class SettingsActivityTest method testAlert_Mongo_InvalidShowsDialog.

@Test
public void testAlert_Mongo_InvalidShowsDialog() {
    EditTextPreference editTextPreference = (EditTextPreference) setUpPreferenceFragment(SettingsActivity.MainPreferenceFragment.class).findPreference(PreferenceKeys.MONGO_URI);
    editTextPreference.getOnPreferenceChangeListener().onPreferenceChange(editTextPreference, "invalidMongo");
    ShadowAlertDialog alertDialog = getShadowApplication().getLatestAlertDialog();
    assertThat(alertDialog, is(not(nullValue())));
    assertThat(alertDialog.getMessage().toString(), is(getContext().getString(R.string.illegal_mongo_uri)));
}
Also used : ShadowAlertDialog(org.robolectric.shadows.ShadowAlertDialog) EditTextPreference(android.preference.EditTextPreference) Test(org.junit.Test)

Example 3 with ShadowAlertDialog

use of org.robolectric.shadows.ShadowAlertDialog in project android-uploader by nightscout.

the class SettingsActivityTest method testAlert_RestApi_InvalidShowsDialog.

@Test
public void testAlert_RestApi_InvalidShowsDialog() {
    EditTextPreference editTextPreference = (EditTextPreference) setUpPreferenceFragment(SettingsActivity.MainPreferenceFragment.class).findPreference(PreferenceKeys.API_URIS);
    editTextPreference.getOnPreferenceChangeListener().onPreferenceChange(editTextPreference, "\\invalidUri");
    ShadowAlertDialog alertDialog = getShadowApplication().getLatestAlertDialog();
    assertThat(alertDialog, is(not(nullValue())));
    assertThat(alertDialog.getMessage().toString(), is(getContext().getString(R.string.invalid_rest_uri, "\\invalidUri")));
}
Also used : ShadowAlertDialog(org.robolectric.shadows.ShadowAlertDialog) EditTextPreference(android.preference.EditTextPreference) Test(org.junit.Test)

Example 4 with ShadowAlertDialog

use of org.robolectric.shadows.ShadowAlertDialog in project android-uploader by nightscout.

the class MainActivityTest method testOnCreate_ShouldShowIUnderstandDialog.

@Test
public void testOnCreate_ShouldShowIUnderstandDialog() {
    preferences.setIUnderstand(false);
    // make sure we don't have another alert dialog
    preferences.setAskedForData(true);
    activityController.create().get();
    ShadowAlertDialog alertDialog = getShadowApplication().getLatestAlertDialog();
    assertThat(alertDialog, is(not(nullValue())));
    assertThat(alertDialog.getTitle(), is(getContext().getText(R.string.pref_title_i_understand)));
}
Also used : ShadowAlertDialog(org.robolectric.shadows.ShadowAlertDialog) Test(org.junit.Test)

Example 5 with ShadowAlertDialog

use of org.robolectric.shadows.ShadowAlertDialog in project scdl by passy.

the class DownloadPreferenceErrorAlertDialogFactoryTest method testDialogCanBeShown.

@Test
public void testDialogCanBeShown() throws Exception {
    final AlertDialog alertDialog = mFactory.newInstance();
    alertDialog.show();
    final AlertDialog dialog = ShadowAlertDialog.getLatestAlertDialog();
    final ShadowAlertDialog shadowAlertDialog = Robolectric.shadowOf(dialog);
    // Maybe too precise, but I want to have a clear indicator that the dialog was
    // actually shown.
    assertThat(shadowAlertDialog.getTitle()).isEqualTo("Your Download failed :(");
}
Also used : AlertDialog(android.app.AlertDialog) ShadowAlertDialog(org.robolectric.shadows.ShadowAlertDialog) ShadowAlertDialog(org.robolectric.shadows.ShadowAlertDialog) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 ShadowAlertDialog (org.robolectric.shadows.ShadowAlertDialog)5 EditTextPreference (android.preference.EditTextPreference)2 AlertDialog (android.app.AlertDialog)1