will_hunting will_hunting - 1 year ago 243
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.

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 Source

Use Mockup

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download