will_hunting will_hunting - 4 months ago 47
Java Question

How can I replace deprecated method Mockit.setUpMock?

I have some code, which is using old version of jmockit library. I find out that setUpMock method of Mockit class is deprecated, but I cann't find on Jmockit API documentation explanation, how can I replace code like below.

@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));
}

Answer

Use Mockup

new MockUp<Tool>() {
    @Mock int someMethod(int i) { assertTrue(i > 0); return 123; }

 };
Comments