Can JMockit mock constructors with any argument?

淺唱寂寞╮ 提交于 2021-01-29 13:46:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!