Getting NullPointerException in my mock dependence
<p>I have this test:</p>

<pre><code>@RunWith(MockitoJUnitRunner.class)
public class MainClassTest {

@Mock
Dependence dependence;

@InjectMocks
MainClass mainClassTester;

}
</code></pre>

<p>And this test:</p>

<pre><code>  @Test
    public void testA() {
    when(dependence.getStatus()).thenReturn(true);
    mainClassTester.startStatusOperation(); 

    }
</code></pre>

<p>My MainClass class looks like:</p>

<pre><code>public class MainClass{

 private Dependence dependence = new Dependence() ;

 public boolean startStatusOperation(){
   boolean status = dependence.getStatus();
   [...]
 }
}
</code></pre>

<p>Im getting NullPointer in this line:</p>

<pre><code>boolean status = dependence.getStatus();
</code></pre>

<p>Why doesn't the mock "dependence" work? This code always worked when I used @inject, but can't use in this one.</p>