Permalink
Browse files

Added findViewById support to ShadowAlertDialog

  • Loading branch information...
Joe Moore, Phil Goodwin & Rick Kawala
Joe Moore, Phil Goodwin & Rick Kawala committed Jul 30, 2011
1 parent 8e17a98 commit 6a89c2aeb7fd6ad6abea8614ef54a450cb0a5211
@@ -48,7 +48,7 @@ public static AlertDialog getLatestAlertDialog() {
@Implementation
public View findViewById(int viewId) {
if(view == null) {
- return null;
+ return super.findViewById(viewId);
}
return view.findViewById(viewId);
@@ -11,12 +11,14 @@
import org.junit.Test;
import org.junit.runner.RunWith;
+import static com.xtremelabs.robolectric.Robolectric.resetStaticState;
import static com.xtremelabs.robolectric.Robolectric.shadowOf;
import static junit.framework.Assert.assertNull;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
@RunWith(WithTestDefaultsRunner.class)
@@ -175,7 +177,19 @@ public void shouldFindViewsByIdIfAViewIsSet() throws Exception {
assertThat(dialog.findViewById(66), nullValue());
}
-
+
+ @Test
+ public void shouldDelegateToDialogFindViewByIdIfViewIsNull() {
+ AlertDialog dialog = new AlertDialog(Robolectric.application) {
+ };
+
+ assertThat(dialog.findViewById(99), nullValue());
+
+ dialog.setContentView(R.layout.main);
+ assertNotNull(dialog.findViewById(R.id.title));
+ }
+
+
private static class TestDialogOnClickListener implements DialogInterface.OnClickListener {
private DialogInterface dialog;
private int clickedItem;

0 comments on commit 6a89c2a

Please sign in to comment.