title: Robolectric Test an activity launched from a widget
body: <p>I've a simple widget which consists of an image and a button, the button should launch an activity. I'm trying to write a Robolectric test to test that the activity is launched when the button is clicked</p>
  
  <p>I've two problems, firstly I'm getting an NPE when attempting to click the button:</p>
  
  <pre><code>java.lang.NullPointerException: can't get a shadow for null
     at org.robolectric.bytecode.ShadowWrangler.shadowOf(ShadowWrangler.java:415)
     at org.robolectric.Robolectric.shadowOf_(Robolectric.java:1020)
     at org.robolectric.Robolectric.shadowOf(Robolectric.java:671)
     at org.robolectric.shadows.ShadowIntent.fillIn(ShadowIntent.java:454)
     at android.content.Intent.fillIn(Intent.java)
     at org.robolectric.shadows.ShadowPendingIntent.send(ShadowPendingIntent.java:48)
     at android.app.PendingIntent.send(PendingIntent.java)
     at org.robolectric.shadows.ShadowRemoteViews$2$1.onClick(ShadowRemoteViews.java:61)
     at android.view.View.performClick(View.java:4084)
  </code></pre>
  
  <p>Also I'm not sure how to get a reference to the activity launched via the button click.</p>
  
  <p>Code for test:</p>
  
  <pre><code>@Test
  public void buttonShouldLaunchActivity() throws Exception {
      int widgetId = shadowAppWidgetManager.createWidget(HelloWidgetProvider.class, R.layout.hellowidget_layout);
      View helloWidgetView = shadowAppWidgetManager.getViewFor(widgetId);
      Button quickButton = (Button) helloWidgetView.findViewById(R.id.quick_add_button);
      quickButton.performClick();
  
      // Not sure how to get a handle of the activity started from a widget, this is what I have for an activity launched from another activity.
      Intent intent = Robolectric.shadowOf(activity).peekNextStartedActivity();
      assertEquals(QuickAddActivity.class.getCanonicalName(), intent.getComponent().getClassName());
  }
  </code></pre>
  
  <p>Any thoughts would be apreciated, the actual widget is working (the activity is launched) but I'd just like to have a test for it.</p>