Robolectric 2.0-rc2 and ActionBarSherlock

230 views
Skip to first unread message

mi...@pivotallabs.com

unread,
May 14, 2013, 7:40:02 PM5/14/13
to robol...@googlegroups.com, Erich Douglass
Hey folks,

We're trying to get a relatively new Android project running on ABS with the latest Robolectric (RC2). We're also trying to use the special sauce found in this gist to get an ABS implementation loaded in tests. But we're getting failures when our Activity under test calls setContentView(). For what it's worth, we're also using roboguice-sherlock as a way to make ABS work with Roboguice view injection. Stack trace below. 

Has anybody got ABS working with Robolectric 2 rc-2 (on Android SDK 16)? 

Thanks,

Mike & Erich at Pivotal

Caused by: java.lang.IllegalStateException: ActionBarView can only be used with android:layout_width="match_parent" (or fill_parent)
at com.actionbarsherlock.internal.widget.ActionBarView.onMeasure(ActionBarView.java:814)
at android.view.View.measure(View.java:15172)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.actionbarsherlock.internal.widget.ActionBarContainer.onMeasure(ActionBarContainer.java:181)
at android.view.View.measure(View.java:15172)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1038)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:576)
at android.view.View.measure(View.java:15172)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15172)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1850)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1102)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1275)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameHandler.handleMessage(Choreographer.java:657)
at org.robolectric.shadows.ShadowHandler.routeMessage(ShadowHandler.java:120)
at org.robolectric.shadows.ShadowHandler.access$100(ShadowHandler.java:25)
at org.robolectric.shadows.ShadowHandler$1.run(ShadowHandler.java:109)
at org.robolectric.util.Scheduler.postDelayed(Scheduler.java:37)
at org.robolectric.shadows.ShadowHandler.postDelayed(ShadowHandler.java:56)
at org.robolectric.shadows.ShadowHandler.sendMessageDelayed(ShadowHandler.java:104)
at org.robolectric.shadows.ShadowHandler.sendMessageAtTime(ShadowHandler.java:155)
at android.os.Handler.sendMessageAtTime(Handler.java)
at android.view.Choreographer.scheduleFrameLocked(Choreographer.java:479)
at org.fest.reflect.method.Invoker.invoke(Invoker.java:112)
at org.robolectric.shadows.ShadowChoreographer.scheduleFrameLocked(ShadowChoreographer.java:45)
at android.view.Choreographer.scheduleFrameLocked(Choreographer.java)
at android.view.Choreographer.postCallbackDelayedInternal(Choreographer.java:309)
at android.view.Choreographer.postCallbackDelayed(Choreographer.java:292)
at android.view.Choreographer.postCallback(Choreographer.java:266)
at android.view.ViewRootImpl$InvalidateOnAnimationRunnable.postIfNeededLocked(ViewRootImpl.java:4329)
at android.view.ViewRootImpl$InvalidateOnAnimationRunnable.addView(ViewRootImpl.java:4263)
at android.view.ViewRootImpl.dispatchInvalidateOnAnimation(ViewRootImpl.java:4349)
at android.view.View.postInvalidateOnAnimation(View.java:10658)
at android.view.View.awakenScrollBars(View.java:10077)
at android.view.View.initialAwakenScrollBars(View.java:9982)
at android.view.View.onWindowVisibilityChanged(View.java:7440)
at android.view.View.dispatchAttachedToWindow(View.java:11772)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2417)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2424)
at android.view.ViewGroup.addViewInner(ViewGroup.java:3417)
at android.view.ViewGroup.addView(ViewGroup.java:3249)
at android.view.ViewGroup.addView(ViewGroup.java:3194)
at android.view.ViewGroup.addView(ViewGroup.java:3170)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.installDecor(ActionBarSherlockCompat.java:907)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.initActionBar(ActionBarSherlockCompat.java:131)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.ensureActionBar(ActionBarSherlockCompat.java:1174)
at com.actionbarsherlock.app.SherlockFragmentActivity.findViewById(SherlockFragmentActivity.java:281)
at roboguice.inject.ViewListener$ViewMembersInjector.reallyInjectMemberViews(ViewListener.java:172)
at roboguice.inject.ViewListener$ViewMembersInjector.reallyInjectMembers(ViewListener.java:138)
at roboguice.inject.ViewListener$ViewMembersInjector.injectViews(ViewListener.java:246)
at roboguice.inject.ContextScopedRoboInjector.injectViewMembers(ContextScopedRoboInjector.java:258)
at com.github.rtyley.android.sherlock.roboguice.activity.RoboSherlockFragmentActivity.onContentChanged(RoboSherlockFragmentActivity.java:100)
at org.robolectric.shadows.ShadowActivity.setContentView(ShadowActivity.java:272)
at ourpackage.ActionBarSherlockRobolectric.setContentView(ActionBarSherlockRobolectric.java:40)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262)
at OurActivity.onCreate(OurActivity.java:48)

Christian Williams

unread,
May 14, 2013, 9:03:47 PM5/14/13
to robol...@googlegroups.com, Erich Douglass
Hey guys, I think that may be due to timing issues with calling onCreate() while the UI scheduler is unpaused.

Try calling Robolectric.pauseMainLooper() before you call onCreate(), then Robolectric.unpauseMainLooper() after.

Even better, use Robolectric.buildActivity(MyActivity.class).create().get() to set up your activity.

Let me know if that helps, or gives you a different error!


--X [typos courtesy of my iPhone]


--
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.
 
 

mi...@pivotallabs.com

unread,
May 15, 2013, 3:55:48 PM5/15/13
to robol...@googlegroups.com, Erich Douglass
Thanks Christian.

Pausing the looper helped; however the buildActivity() method didn't work. In our test we pass an Intent to our Activity, so I tried using 'withIntent()', but when onCreate() was called we couldn't see that intent (it was null).

That being said, just to get to that point we had to hack out a line of code in ActionBarSherlockCompat (a call to loadUiOptionsFromManifest). Inside of there a call to activity.getApplicationInfo().packageName was returning null. 

We're now having other problems, possibly related to view injection. We're using roboguice-sherlock...but anyway we'll keep debugging that and let you know what we find. 

I guess the meta-question is: have you guys (or anybody else you know of) successfully integrated ABS with the latest and greatest Robolectric? 

Mike
Reply all
Reply to author
Forward
0 new messages