问题
I am replacing PowerMock with JMockit in old unit testing case. Below is the PowerMock sample code which mock the File.class constructors with any argument .
Can JMockit mock constructors with any argument like it ?
The situation is this:myFile is a mock. And I want to simulate returning myFile when calling any constructor in the File class..So What is the code like.
// PowerMock
whenNew(File.class).withAnyArguments().thenReturn(myfile);
// JMockit
new Expectations() {{
new File(anyString);
result = myfile;
minTimes = 0;
}};
来源:https://stackoverflow.com/questions/53646563/can-jmockit-mock-constructors-with-any-argument