When trying to use Mockito with Spring, by creating the Mock object via a bean declaration...
The simple answer is:
when you write Mockito.when(object.fooMethod()).then()
then fooMethod()
is actually called.
Another point is that we can't observe it first time, because it called on mocked object. But when we write when
for the second time then we have some behavior for fooMethod()
(we set it previously, in your case it Exception).
To check this better you can spy
object:
Bar spyBar = Mockito.spy(Bar.class)
when(spyBar.fooMethod()).then()...
and fooMethod()
will be actually called.