Author: techfox9
jMock resources..
Thursday, August 4th, 2011 @ 12:34 am
http://www.jmock.org
http://www.jmock.org/articles.html
http://www.jmock.org/cheat-sheet.html
http://www.jmock.org/cookbook.html
http://www.jmock.org/yoga.html
http://www.jmock.org/mocking-classes.html
This article explains how the mock setup class works
(I have been looking for this for at least 5 hours over 2 days..)
http://dancing-devil.blogspot.com/2011/04/mocking-java-system-class-and.html
To mock System.class and override the currentTimeMillis() method, do this:
Note: this works for protected methods.
Mockit.setUpMock(new MockSystem()); ... @MockClass(realClass = System.class) public class MockSystem { @Mock public long currentTimeMillis() { .... return ....; } }
To redefine methods using another way, including mocking static methods, use this:
public void setUp() throws Exception { super.setUp(); Mockit.redefineMethods(MyClass.class, MockMyClass.class); ... } .... public static class MockMyClass { @Mock public static Something doSomething(...) { return Something ...; } }