我有一些代码,它使用旧版本的jmockit库。我发现Mockit类的setUpMock方法已被弃用,但我找不到Jmockit API文档说明,如何替换下面的代码。
@Test(expected=IllegalArgumentException.class)
public void updateWithBadRownum() throws Exception
{
Mockit.setUpMock(Tool.class, new MockTool()); //It doesn't support on latest version of jmockit
Mockit.setUpMock(Criteria.class, new MockCriteria());
new TaskInitializer().populateSchemas(cnn, 10);
Map parameters = new HashMap();
parameters.put("ROWNUM", "abc");
Assert.assertTrue(4 == StatusUpdaterImpl.execute(parameters));
}
答案 0 :(得分:3)
使用Mockup
new MockUp<Tool>() {
@Mock int someMethod(int i) { assertTrue(i > 0); return 123; }
};
答案 1 :(得分:-1)
试一试!
替换
带有Mockit.setUpMock(A.class,MockA.class);//old way
的 new MockA();//new way
(我在JUnit new MockA();
方法中调用此setUp()
)
重写
class MockA(){ // old mock class
//Mock methods
}
带
class MockA extends MockUp<A>{ // new mock class
//Mock methods
}