ShadowDialogFragment?

794 views
Skip to first unread message

Colin Miller

unread,
Oct 30, 2013, 7:47:02 PM10/30/13
to robol...@googlegroups.com
The current version of robolectric doesn't seem to have a shadow for DialogFragment. Has anyone been interacting with DialogFragments in a way I'm just unaware of? I basically need a button on a dialogFragment to be pressed to test some behavior.

Thanks,
~Colin

Erich Douglass

unread,
Oct 30, 2013, 8:39:10 PM10/30/13
to robol...@googlegroups.com
DialogFragments should work - I used one with Robolectric in a previous project.  Are you using fragments from the SDK or the support library?  We typically only create shadows for classes where we need a method that's not available in the underlying Android SDK.  In a perfect world, we wouldn't need to shadow anything.


--
You received this message because you are subscribed to the Google Groups "Robolectric" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robolectric...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Colin Miller

unread,
Oct 31, 2013, 5:00:43 PM10/31/13
to robol...@googlegroups.com
Alright, well I was able to get the DialogFragment from the FragmentManager and the real dialog from that fragment, however when trying to click on a button via a ShadowDialog, I get an NPE.

java.lang.NullPointerException
	at android.view.LayoutInflater.from(LayoutInflater.java:210)
	at org.robolectric.shadows.ShadowDialog.clickOnText(ShadowDialog.java:105

Looking at the robolectric code, it's using a context in ShadowDialog that never seems to be set as far as I can tell. If I modify robolectric to make that context public and set it to my activity (created with Robolectric), instead of getting an NPE I'll get a Resources.NotFoundException:

android.content.res.Resources$NotFoundException: unknown resource 0
	at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:258)
	at org.robolectric.shadows.ShadowAssetManager.getResourceValue(ShadowAssetManager.java:85)
	at android.content.res.AssetManager.getResourceValue(AssetManager.java)
	at android.content.res.Resources.getValue(Resources.java:1009)
	at android.content.res.Resources.loadXmlResourceParser(Resources.java:2098)
	at android.content.res.Resources.getLayout(Resources.java:852)
	at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
	at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
	at org.robolectric.shadows.ShadowDialog.clickOnText(ShadowDialog.java:105)

At this point I'm pretty stumped. I'm not sure how to get the ShadowDialog to be able to click on the button that I need to have clicked.
Reply all
Reply to author
Forward
0 new messages