Skip to content

Commit

Permalink
Added findViewById support to ShadowAlertDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Moore, Phil Goodwin & Rick Kawala committed Jul 30, 2011
1 parent 8e17a98 commit 6a89c2a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Expand Up @@ -48,7 +48,7 @@ public static AlertDialog getLatestAlertDialog() {
@Implementation @Implementation
public View findViewById(int viewId) { public View findViewById(int viewId) {
if(view == null) { if(view == null) {
return null; return super.findViewById(viewId);
} }


return view.findViewById(viewId); return view.findViewById(viewId);
Expand Down
Expand Up @@ -11,12 +11,14 @@
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;


import static com.xtremelabs.robolectric.Robolectric.resetStaticState;
import static com.xtremelabs.robolectric.Robolectric.shadowOf; import static com.xtremelabs.robolectric.Robolectric.shadowOf;
import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertNull;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;


@RunWith(WithTestDefaultsRunner.class) @RunWith(WithTestDefaultsRunner.class)
Expand Down Expand Up @@ -175,7 +177,19 @@ public void shouldFindViewsByIdIfAViewIsSet() throws Exception {


assertThat(dialog.findViewById(66), nullValue()); 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 static class TestDialogOnClickListener implements DialogInterface.OnClickListener {
private DialogInterface dialog; private DialogInterface dialog;
private int clickedItem; private int clickedItem;
Expand Down

0 comments on commit 6a89c2a

Please sign in to comment.