Permalink
Browse files

add ShadowDialog.getShownDialogs()

  • Loading branch information...
1 parent d743325 commit 5190218f8335eae061cfe0234526c2d510a8bf56 Glenn Jahnke & Ryan Richard committed Dec 13, 2011
@@ -382,6 +382,7 @@ public static void resetStaticState() {
ShadowLog.reset();
ShadowContext.clearFilesAndCache();
ShadowLooper.resetThreadLoopers();
+ ShadowDialog.reset();
}
public static <T> T directlyOn(T shadowedObject) {
@@ -16,6 +16,8 @@
import com.xtremelabs.robolectric.tester.android.view.TestWindow;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
import static com.xtremelabs.robolectric.Robolectric.shadowOf;
@@ -38,9 +40,11 @@
private Activity ownerActivity;
private boolean isCancelable = true;
private boolean hasShownBefore;
-
+ private static final ArrayList<Dialog> shownDialogs = new ArrayList<Dialog>();
+
public static void reset() {
setLatestDialog(null);
+ shownDialogs.clear();
}
public static Dialog getLatestDialog() {
@@ -114,6 +118,7 @@ public void show() {
}
hasShownBefore = true;
setLatestDialog(this);
+ shownDialogs.add(realDialog);
}
@Implementation
@@ -238,4 +243,8 @@ private boolean clickOnText(View view, String text) {
}
return false;
}
+
+ public static List<Dialog> getShownDialogs() {
+ return shownDialogs;
+ }
}
@@ -9,9 +9,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNull;
-import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.*;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.core.IsEqual.equalTo;
@@ -116,6 +114,31 @@ public void getLatestDialog_shouldReturnARealDialog() throws Exception {
assertThat(ShadowDialog.getLatestDialog(), sameInstance(dialog));
}
+ @Test
+ public void shouldKeepListOfOpenedDialogs() throws Exception {
+ assertEquals(0, ShadowDialog.getShownDialogs().size());
+
+ TestDialog dialog = new TestDialog();
+ dialog.show();
+
+ assertEquals(1, ShadowDialog.getShownDialogs().size());
+ assertEquals(dialog, ShadowDialog.getShownDialogs().get(0));
+
+ TestDialog dialog2 = new TestDialog();
+ dialog2.show();
+
+ assertEquals(2, ShadowDialog.getShownDialogs().size());
+ assertEquals(dialog2, ShadowDialog.getShownDialogs().get(1));
+
+ dialog.dismiss();
+
+ assertEquals(2, ShadowDialog.getShownDialogs().size());
+
+ ShadowDialog.reset();
+
+ assertEquals(0, ShadowDialog.getShownDialogs().size());
+ }
+
private static class TestDialog extends Dialog {
boolean onStartCalled = false;
boolean wasDismissed = false;

0 comments on commit 5190218

Please sign in to comment.