如何替换弃用的方法Mockit.setUpMock?

时间:2016-07-25 12:30:32

标签: java unit-testing mocking jmockit

我有一些代码,它使用旧版本的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));
} 

2 个答案:

答案 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    
}