For Mockito
/PowerMockito
you can use the whenNew()
function. It would probably look something like this once you expand it out a bit:
PowerMockito.whenNew(File.class).withArguments(directoryPath).thenReturn((File) fileMock)
.
Also, when using Mockito
try using Mockito.mock()
to create the Mock objects (in this case fileMock
.