Starting with version 3.5.0 of Mockito and using the InlineMockMaker
, you can now mock object constructions:
try (MockedConstruction mocked = mockConstruction(A.class)) {
A a = new A();
when(a.check()).thenReturn("bar");
}
Inside the try-with-resources
construct all object constructions are returning a mock.