title: EasyMock with Robolectric: EasyMock is not working as expected
body: <p>This is CustomAdapter (btw: really old code, should be improved some day):</p>
  
  <pre><code>public class CustomAdapter extends BaseAdapter{
  
      private SortedSet&lt;Integer&gt; mHiddenItems = new TreeSet&lt;&gt;();     
  
      @Override
      public final int getCount(){
          return mHiddenItems.size();
      }
  
      ...
  }
  </code></pre>
  
  <p>This is my test class CustomAdapterTest (and everything works well here):</p>
  
  <pre><code>public class CustomAdapterTest extends TestCase{
  
      private static final int ITEMS_IN_ADAPTER = 10;
      private CustomAdapter mCustomAdapter;
  
      @Override
      public void setUp() throws Exception{
          super.setUp();
  
          mCustomAdapter = EasyMock.createMockBuilder(CustomAdapter.class)
              .addMockedMethod("method1")
              .addMockedMethod("method2")
              .createMock();
  
          expect(mCustomAdapter.method2()).andReturn(ITEMS_IN_ADAPTER).anyTimes();
      }
  
      public void testOne(){
          EasyMock.replay(mCustomAdapter);
          assertEquals(ITEMS_IN_ADAPTER,mCustomAdapter.getTotalCount());
          .....
      }
  
      ......
  
  }
  </code></pre>
  
  <p>Attempting to use Robolectric, and after fixing one bug, this is how CustomAdapterTest looks like:</p>
  
  <pre><code>@RunWith(RoboelectricGradleTestRunner.class)
  @Config(constants = BuildConfig.class , packageName="my.package.name")
  public class CustomAdapterTest{
  
      private static final int ITEMS_IN_ADAPTER = 10;
      private CustomAdapter mCustomAdapter;
  
      @Before
      public void setUp(){
          System.setProperty("dexmaker.dexcache",RuntimeEnvironment.application.getCacheDir().getPath())
  
          mCustomAdapter = EasyMock.createMockBuilder(CustomAdapter.class)
              .addMockedMethod("method1")
              .addMockedMethod("method2")
              .createMock();
  
          expect(mCustomAdapter.method2()).andReturn(ITEMS_IN_ADAPTER).anyTimes();
      }
  
      public void testOne(){
          EasyMock.replay(mCustomAdapter);
          assertEquals(ITEMS_IN_ADAPTER,mCustomAdapter.getTotalCount());
          .....
      }
  
      ......
  
  }
  </code></pre>
  
  <p>When I run the CustomAdapterTest#testOne() using Robolectric, I don't know why but <code>mCustomAdapter.mHiddenItems</code> is null, causing a NPE when mCustomAdapter.getCount() is called. This is not happening on the first version of CustomAdapterTest. <br/> <br/> 1) Why when using RobolectricGradleTestRunner <code>private SortedSet mHiddenItems = new TreeSet&lt;>();</code> is not executed ? <br/> <br/> 2) How to fix this? I want it to execute <code>private SortedSet mHiddenItems = new TreeSet&lt;>();</code> as expected.</p>