title: Mockito test case failing
body: <p>I work with mvp pattern and treid to test short presenter method</p>
  
  <p>This is </p>
  
  <pre><code>final public void setOriginPreviewImage() {
  final String path = model.getImageFilePath();
  iActivityAcceptNotAccept.setPreviewImage(path);
  }
  </code></pre>
  
  <p>This method retrieves the path and pass it via interface to view</p>
  
  <p>This is test</p>
  
  <pre><code>public class PresenterActivityAcceptNotAcceptTest {
  
  private PresenterActivityAcceptNotAccept presenter;
  
  @Mock ModelAcceptNotAccept model;
  @Mock IActivityAcceptNotAccept iActivityAcceptNotAccept;
  
  @Before public void setUp() throws Exception {
      MockitoAnnotations.initMocks(this);
      presenter = new PresenterActivityAcceptNotAccept(iActivityAcceptNotAccept);
  }
  
  @Test public void setOriginPreviewImage() throws Exception {
      presenter.setOriginPreviewImage();
      when(model.getImageFilePath()).thenReturn("path");
      String path = model.getImageFilePath();
      verify(iActivityAcceptNotAccept).setPreviewImage(path);
  }
  </code></pre>
  
  <p>here in the first line I invoke the method, then do <code>when()</code> to point that if <code>getImageFilePath()</code> will been invoke then return <code>"path"</code> as a value.</p>
  
  <p>In the third line I invoke <code>getImageFilePath()</code> I expect to get valeu that I had set up prior to this line - <code>"path"</code>.</p>
  
  <p>But instead of this I get such error</p>
  
  <blockquote>
    <p>java.lang.NullPointerException
        at com.fittingroom.newtimezone.tools.cameraTools.ImageSaver.getImageFilePath(ImageSaver.java:37)
        at com.fittingroom.newtimezone.model.ModelAcceptNotAccept.getImageFilePath(ModelAcceptNotAccept.java:14)</p>
  </blockquote>
  
  <p>I get the error during processing <code>model.getImageFilePath();</code></p>
  
  <p>according to the log file test don't return back the value that I had set up hire </p>
  
  <pre><code>when(model.getImageFilePath()).thenReturn("path");
  </code></pre>
  
  <p>instead of this it is trying to get value from the method, of course there is no value because it is test...</p>
  
  <p>How model assosiated with presenter</p>
  
  <pre><code>public final class PresenterActivityAcceptNotAccept implements IPresenterAcceptNotAccept {
  private IActivityAcceptNotAccept iActivityAcceptNotAccept;
  private ModelAcceptNotAccept model;
  
  public PresenterActivityAcceptNotAccept(IActivityAcceptNotAccept iActivityAcceptNotAccept) {
      this.iActivityAcceptNotAccept = iActivityAcceptNotAccept;
      this.model = new ModelAcceptNotAccept(this);
  }
  </code></pre>
  
  <p>Model code</p>
  
  <pre><code>public class ModelAcceptNotAccept {
  private IPresenterAcceptNotAccept iPresenterAcceptNotAccept;
  
  public ModelAcceptNotAccept(IPresenterAcceptNotAccept iPresenterAcceptNotAccept) {
      this.iPresenterAcceptNotAccept = iPresenterAcceptNotAccept;
  }
  
  public String getImageFilePath(){
      return ImageSaver.getImageFilePath();
  }
  
  }
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>@Test public void setOriginPreviewImage() throws Exception {
      //when(model.getImageFilePath()).thenReturn("path");
      doReturn("path").when(model.getImageFilePath());
      presenter.setOriginPreviewImage();
      String path = model.getImageFilePath();
      verify(iActivityAcceptNotAccept).setPreviewImage(path);
  }
  </code></pre>
  
  <p>give me such errors</p>
  
  <pre><code>org.mockito.exceptions.misusing.UnfinishedStubbingException: 
  Unfinished stubbing detected here:
  -&gt; at   com.fittingroom.newtimezone.presenters.PresenterActivityAcceptNotAcceptTes t.setOriginPreviewImage(PresenterActivityAcceptNotAcceptTest.java:30)
  
  E.g. thenReturn() may be missing.
  Examples of correct stubbing:
  when(mock.isOk()).thenReturn(true);
  when(mock.isOk()).thenThrow(exception);
  doThrow(exception).when(mock).someVoidMethod();
  Hints:
  1. missing thenReturn()
  2. you are trying to stub a final method, you naughty developer!
  3: you are stubbing the behaviour of another mock inside before 'thenReturn' instruction if completed
  
  
   at   com.fittingroom.newtimezone.presenters.PresenterActivityAcceptNotAcceptTest.setOriginPreviewImage(PresenterActivityAcceptNotAcceptTest.java:30)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
  at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
  at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
  at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
  at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
  at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
  at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
  at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
  at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
  at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
  </code></pre>
  
  <p><strong>EDIT2</strong></p>
  
  <p><a href="https://i.stack.imgur.com/5aJcg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5aJcg.png" alt="enter image description here"></a></p>
  
  <p><strong>EDIT3</strong></p>
  
  <p>My test now</p>
  
  <pre><code>@Test public void setOriginPreviewImage() throws Exception {
      presenter.setOriginPreviewImage();
      doReturn("path").when(model).getImageFilePath();
      String path = model.getImageFilePath();
      verify(contractAcceptNotAccept).setPreviewImage(path);
  }
  </code></pre>
  
  <p>Error</p>
  
  <p><a href="https://i.stack.imgur.com/dZD0l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dZD0l.png" alt="enter image description here"></a></p>