Hi Stephan,
Sorry I completely forgot about you, it was a bit hectic at work.
So well, actually as you are running the mock in thread before stubbing I believe this is the root cause of your problems. Stubbing should be done before any multithreading use.
Here's what could be happening :
The working scenario
JUnit thread | Executor thread
=> setUp(submit the runnable) |
=> begin the test method |
| => enter the run method
=> call someAction.getOneThing() |
=> stub the registered call |
| => call someAction.doOtherThings()
... | ...
The failing scenario
JUnit thread | Executor thread
=> setUp(submit the runnable) |
=> begin the test method |
| => enter the run method
=> call someAction.getOneThing() |
| => call someAction.doOtherThings()
=> stub the registered call |
... | ...
Now you noticed that the message says that void method cannot be stubbed with a return value, that is because the stubbing syntax uses the last call made to the mock, and because the used stubbing syntax is for value returning methods.
I'm not sure this behavior of mockito should be changed, to only stub calls made in the same thread, though that would seam reasonable, but I'd like the advice and feedback of the users working with multithreaded code.
I'm not sure what you are trying to achieve in your test, but I would make that any stubbed behavior happens before any other usage of the mock in another thread.