title: Spurious Test Failures using Picasso and Robolectric
body: <p>I just upgraded to Robolectric 2.1.1 and integrated Picasso today. I now have two test cases that fail randomly (one of these fragments doesn't even use Picasso). If I keep running the tests, everything usually ends up passing (might take a few tries).</p>
  
  <p><strong>Test</strong></p>
  
  <pre><code>@Before
  public void setUp() throws Exception
  {
      detailActivity = Robolectric.buildActivity( ActivityUnderTest.class )
                                  .withIntent( createIntent() )
                                  .create()
                                  .start()
                                  .resume()
                                  .get();
  
      // Note: The other test case doesn't use the fancy withIntent() doohickey
  }
  
  public static Intent createIntent()
  {
      Bundle bundle = DetailFragment.createBundle( getTestData() );
      Intent intent = new Intent( new ActivityUnderTest(), Activity.class );
      intent.putExtras( bundle );
      return intent;
  }
  
  @Test
  public void shouldNotBeNull() throws Exception
  {
      assertNotNull( detailActivity );
  }
  </code></pre>
  
  <p><strong>Codez</strong></p>
  
  <p>I am sending in a bundle of information to the activity, which is basically an empty shell. The activity displays a Fragment via XML. In my Fragment, I get the data from the bundle using <code>getActivity().getIntent().getExtras()</code>.</p>
  
  <p><strong>Lying Warning</strong></p>
  
  <p>[WARN] You're instantiating an activity (com.colabug.project.singlepanel.ActivityUnderTest) directly; consider using Robolectric.buildActivity() instead.</p>
  
  <p><strong>Stacktrace</strong></p>
  
  <pre><code>java.lang.RuntimeException: An unexpected exception occurred
  at com.squareup.picasso.Request$1.run(Request.java:114)
  at org.robolectric.util.Scheduler$PostedRunnable.run(Scheduler.java:162)
  at org.robolectric.util.Scheduler.runOneTask(Scheduler.java:107)
  at org.robolectric.util.Scheduler.advanceTo(Scheduler.java:92)
  at org.robolectric.util.Scheduler.advanceToLastPostedRunnable(Scheduler.java:68)
  at org.robolectric.util.Scheduler.unPause(Scheduler.java:25)
  at org.robolectric.shadows.ShadowLooper.unPause(ShadowLooper.java:219)
  at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:258)
  at org.robolectric.util.ActivityController.invokeWhilePaused(ActivityController.java:202)
  at org.robolectric.util.ActivityController.start(ActivityController.java:144)
  at com.colabug.project.singlepanel.DetailActivityTest.setUp(DetailActivityTest.java:32)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
  at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
  at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:241)
  at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
  at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
  at org.junit.runners.Suite.runChild(Suite.java:128)
  at org.junit.runners.Suite.runChild(Suite.java:24)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
  at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
  at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
  at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
  at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
  Caused by: java.lang.NullPointerException: Bitmap config was null.
  at org.robolectric.shadows.ShadowBitmap.getBytesPerPixel(ShadowBitmap.java:338)
  at org.robolectric.shadows.ShadowBitmap.getRowBytes(ShadowBitmap.java:225)
  at org.robolectric.shadows.ShadowBitmap.getByteCount(ShadowBitmap.java:230)
  at android.graphics.Bitmap.getByteCount(Bitmap.java)
  at com.squareup.picasso.Utils$BitmapHoneycombMR1.getByteCount(Utils.java:250)
  at com.squareup.picasso.Utils.getBitmapBytes(Utils.java:65)
  at com.squareup.picasso.Stats.processBitmap(Stats.java:64)
  at com.squareup.picasso.Stats.bitmapDecoded(Stats.java:40)
  at com.squareup.picasso.Picasso.loadFromType(Picasso.java:365)
  at com.squareup.picasso.Picasso.resolveRequest(Picasso.java:215)
  at com.squareup.picasso.Picasso.run(Picasso.java:197)
  at com.squareup.picasso.Request.run(Request.java:108)
  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
  at java.util.concurrent.FutureTask.run(FutureTask.java:138)
  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
  at java.lang.Thread.run(Thread.java:680)
  at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:244)
  </code></pre>
  
  <p><strong>pom.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project
      xmlns="http://maven.apache.org/POM/4.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;com.colabug&lt;/groupId&gt;
      &lt;artifactId&gt;Project&lt;/artifactId&gt;
      &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;apk&lt;/packaging&gt;
      &lt;name&gt;Project&lt;/name&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.google.android&lt;/groupId&gt;
              &lt;artifactId&gt;android&lt;/artifactId&gt;
              &lt;version&gt;2.2.1&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Make sure this is below the android dependencies --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.8.2&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.robolectric&lt;/groupId&gt;
              &lt;artifactId&gt;robolectric&lt;/artifactId&gt;
              &lt;version&gt;2.1.1&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.squareup.picasso&lt;/groupId&gt;
              &lt;artifactId&gt;picasso&lt;/artifactId&gt;
              &lt;version&gt;1.0.2&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;finalName&gt;${project.artifactId}&lt;/finalName&gt;
  
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;!-- See http://code.google.com/p/maven-android-plugin/ --&gt;
                  &lt;groupId&gt;com.jayway.maven.plugins.android.generation2&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-android-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.8.3&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;sdk&gt;
                          &lt;platform&gt;17&lt;/platform&gt;
                      &lt;/sdk&gt;
                  &lt;/configuration&gt;
                  &lt;extensions&gt;true&lt;/extensions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Any ideas? IntelliJ might be the cause since it shows up in the stacktrace. I have used <code>mvn clean</code> and manually cleaned up auto generated files on the command line and rebuilt the project in IntelliJ.</p>