title: Null after @InjectMocks
body: <p>I am having some troubles passing a dependency while unit testing with JUnit.</p>
  <p>Consider these pieces of code:</p>
  <p>This is the dependacy injecton into the class which i want to test, lets call it Controller.</p>
  <pre><code>@Inject private FastPowering fastPowering;  
  </code></pre>
  <p>And this is the unit test:</p>
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  public class ControllerTest {
  
  @Mock
  FastPowering fastPower;
  
  @InjectMocks
  Controller controller;
  
  @Test
  public void test() {
      assertEquals(
              (controller.computeAnswer(new BigDecimal(2), 2)).longValue(),
              (long) Math.pow(2, 2));
      }
  }
  </code></pre>
  <p>It seems that fastPower is null, please explain how to fix that.
  Null pointer exception , because of calling the @injected field (fastPower) inside the .computeAnswer method)</p>
  <p>Edit:</p>
  <p>Solved i should have read about the difference between @Mock and @Spy...</p>
  <p>Due to a lot of comments I am adding some more context to the solution</p>
  <p>The difference is that in mock, you are creating a complete mock or fake object while in spy, there is the real object and you just spying or stubbing specific methods of it. While in spy objects, of course, since it is a real method, when you are not stubbing the method, then it will call the real method behavior.</p>
  <p>If fastPower is annotated as <em>@Mock</em> it's methods are dummy, yet <em>controller.computeAnswer</em> depends on them to compute. One must provide behaviour.</p>
  <p>If spy is used without stubbing then the real implementation of <em>fastPower</em> is being executed which eventually returns desired value.</p>
  <p>Another option is to use a real <em>FastPowering</em> instance</p>
  <p><a href="https://github.com/mockito/mockito/wiki/Using-Spies-(and-Fakes)" rel="noreferrer">https://github.com/mockito/mockito/wiki/Using-Spies-(and-Fakes)</a>
  <a href="https://github.com/mockito/mockito/wiki/Mocking-Object-Creation" rel="noreferrer">https://github.com/mockito/mockito/wiki/Mocking-Object-Creation</a></p>
  <p>And some stackoverflow thread outlining the difference <a href="https://stackoverflow.com/questions/12827580/mocking-vs-spying-in-mocking-frameworks">Mocking vs. Spying in mocking frameworks</a></p>
  <p>Short Answer: Replace <code>@Mock</code> with <code>@Spy</code> and should be working fine</p>