| package com.xtremelabs.robolectric.shadows; |
| |
| import android.app.AlertDialog; |
| import android.content.ContextWrapper; |
| import com.xtremelabs.robolectric.WithTestDefaultsRunner; |
| import org.junit.Test; |
| import org.junit.runner.RunWith; |
| |
| import static com.xtremelabs.robolectric.Robolectric.shadowOf; |
| import static org.hamcrest.CoreMatchers.equalTo; |
| import static org.hamcrest.CoreMatchers.sameInstance; |
| import static org.junit.Assert.assertThat; |
| |
| @RunWith(WithTestDefaultsRunner.class) |
| public class AlertDialogTest { |
| |
| @Test |
| public void testBuilder() throws Exception { |
| AlertDialog.Builder builder = new AlertDialog.Builder(new ContextWrapper(null)); |
| builder.setTitle("title") |
| .setMessage("message"); |
| AlertDialog alert = builder.create(); |
| alert.show(); |
| |
| assertThat(alert.isShowing(), equalTo(true)); |
| |
| ShadowAlertDialog shadowAlertDialog = shadowOf(alert); |
| assertThat(shadowAlertDialog.getTitle(), equalTo("title")); |
| assertThat(shadowAlertDialog.getMessage(), equalTo("message")); |
| assertThat(ShadowAlertDialog.getLatestAlertDialog(), sameInstance(shadowAlertDialog)); |
| } |
| } |