Search in sources :

Example 41 with AlertDialog

use of android.app.AlertDialog in project robolectric by robolectric.

the class ShadowAlertDialogTest method clickingPositiveButtonDismissesDialog.

@Test
public void clickingPositiveButtonDismissesDialog() throws Exception {
    AlertDialog alertDialog = new AlertDialog.Builder(application).setPositiveButton("Positive", null).create();
    alertDialog.show();
    assertTrue(alertDialog.isShowing());
    alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick();
    assertFalse(alertDialog.isShowing());
}
Also used : AlertDialog(android.app.AlertDialog) Test(org.junit.Test)

Example 42 with AlertDialog

use of android.app.AlertDialog in project robolectric by robolectric.

the class ShadowAlertDialogTest method shouldOnlyCreateRequestedButtons.

@Test
public void shouldOnlyCreateRequestedButtons() throws Exception {
    AlertDialog.Builder builder = new AlertDialog.Builder(application);
    builder.setPositiveButton("OK", null);
    AlertDialog dialog = builder.create();
    dialog.show();
    assertThat(dialog.getButton(AlertDialog.BUTTON_POSITIVE).getVisibility()).isEqualTo(View.VISIBLE);
    assertThat(dialog.getButton(AlertDialog.BUTTON_NEGATIVE).getVisibility()).isEqualTo(View.GONE);
}
Also used : AlertDialog(android.app.AlertDialog) Test(org.junit.Test)

Example 43 with AlertDialog

use of android.app.AlertDialog in project robolectric by robolectric.

the class ShadowAlertDialogTest method shouldSetView_withLayoutId.

@Test
@Config(minSdk = LOLLIPOP)
public void shouldSetView_withLayoutId() throws Exception {
    AlertDialog.Builder builder = new AlertDialog.Builder(application);
    builder.setView(R.layout.custom_layout);
    AlertDialog alert = builder.create();
    View view = shadowOf(alert).getView();
    assertThat(view.getClass()).isEqualTo(CustomView.class);
}
Also used : AlertDialog(android.app.AlertDialog) View(android.view.View) CustomView(org.robolectric.android.CustomView) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 44 with AlertDialog

use of android.app.AlertDialog in project robolectric by robolectric.

the class ShadowAlertDialogTest method shouldAllowNullButtonListeners.

@Test
public void shouldAllowNullButtonListeners() throws Exception {
    AlertDialog.Builder builder = new AlertDialog.Builder(application);
    builder.setPositiveButton("OK", null);
    AlertDialog dialog = builder.create();
    dialog.show();
    ShadowView.clickOn(dialog.getButton(AlertDialog.BUTTON_POSITIVE));
}
Also used : AlertDialog(android.app.AlertDialog) Test(org.junit.Test)

Example 45 with AlertDialog

use of android.app.AlertDialog in project robolectric by robolectric.

the class ShadowAlertDialogTest method clickingNeutralButtonDismissesDialog.

@Test
public void clickingNeutralButtonDismissesDialog() throws Exception {
    AlertDialog alertDialog = new AlertDialog.Builder(application).setNeutralButton("Neutral", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
        }
    }).create();
    alertDialog.show();
    assertTrue(alertDialog.isShowing());
    alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL).performClick();
    assertFalse(alertDialog.isShowing());
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Test(org.junit.Test)

Aggregations

AlertDialog (android.app.AlertDialog)368 DialogInterface (android.content.DialogInterface)251 View (android.view.View)93 TextView (android.widget.TextView)70 Intent (android.content.Intent)63 EditText (android.widget.EditText)53 OnClickListener (android.content.DialogInterface.OnClickListener)37 Test (org.junit.Test)33 ListView (android.widget.ListView)30 Context (android.content.Context)29 AdapterView (android.widget.AdapterView)27 LayoutInflater (android.view.LayoutInflater)26 ImageView (android.widget.ImageView)26 SuppressLint (android.annotation.SuppressLint)24 Button (android.widget.Button)24 Activity (android.app.Activity)23 Paint (android.graphics.Paint)20 OnClickListener (android.view.View.OnClickListener)18 KeyEvent (android.view.KeyEvent)16 ArrayList (java.util.ArrayList)16