I am trying to update the existing code to remove PowerMockito and replace it with Mockito now that Mockito supports mocking static and mocking construction.
I get that you can do the follow:
assertEquals("foo", new Foo().method());
try (MockedConstruction mocked = mockConstruction(Foo.class)) {
Foo foo = new Foo();
when(foo.method()).thenReturn("bar");
assertEquals("bar", foo.method());
verify(foo).method();
}
assertEquals("foo", new Foo().method());
and the Foo is a new mocked object. But with PowerMockito's whenNew, you can return a specific mocked object.
PowerMockito.whenNew(Foo.class).withAnyArguments().thenReturn(mockedFoo);
Is there a way to specify what mocked object I want to be returned from Mockito.mockConstruction?