Return a specific mock from a mocked constructor with Mockito

Viewed 236

Is there a way with mockConstruction/MockedConstruction to return a specific mock object (i.e. a precreated mock) or alternatively get the mock object to use in the rest of the test?

The reason for this is to allow the constructed mock to be used in other stubs as arguments for matching purposes.

constructed() doesn't work as this requires the constructor to have been called and, even if the mock is retrieved, the next call will get a different mock

It was easy to do this with PowerMock as it allowed a specific mock to be directly return when the constructor was called.

Any ideas what the solution is here for Mockito?

0 Answers
Related