title: Mocking static fields with Mockito
body: <p>I have something like this (it is a third party library so I have to work with this design):</p>
  
  <pre><code>ClassA.conn1.getObjectA().getIntValue()
  </code></pre>
  
  <p>ClassA is a normal class, and inside it there is a public static field (conn1). This conn1 is a class which have a connection and some other values which are used in the application (in my case that ObjectA).</p>
  
  <p>This value is passed as parameter in the dao I am mocking. That value is mocked as  Matchers.anyInt() but I get a NullPointerException because conn1 is null (not the expected int)</p>
  
  <p>I tried some things PowerMockito, the WhiteBox, but without success. Now I have done this, but I get the same NullPointerException</p>
  
  <pre><code>Mockito.when(ClassA.conn1.getObjectA()).thenReturn(new ObjectA(2));
  </code></pre>
  
  <p>The question is, how can I mock it to get the ObjectA or the int value of the ObjectA</p>