Mockito - thenCallRealMethod() on void function : <p>Hello I have been ran into a problem when trying to write a JUnit test case and am relatively new to Mockito.</p>

<p>I have a function of a class that I am mocking, this function happens to be of a void return type. When calling this function from my mocked class it is my understanding (and debugging experience) that it does NOT call the original function. In order to overcome this I have attempted to use a "when" with a "thenCallRealMethod()".</p>

<pre><code>    when(instance.voidFunction()).thenCallRealMethod();
</code></pre>

<p>The "voidFunction" is full of logic that I do NOT want to fire. I have extracted these into when statements to avoid that. I have read that I should use the format of <code>doReturn().when().voidFunction()</code>, however doing this does not call the real method.</p>

<p>It was also my understanding that I could not use a Spy here, due to the fact that I do not want the voidFunction() called before the "when" statements. Any help is appreciated I apologize if this is a very easy solution as my understanding of mockito isn't very great despite reading quite a bit. Thanks!</p>
