01: package net.sf.mockcreator;
02:
03: import java.lang.reflect.Field;
04:
05: public class MockCore {
06: public static void reset() {
07: MockKernel.reset();
08: }
09:
10: public static void startBlock() {
11: MockKernel.startBlock();
12: }
13:
14: public static void endBlock() {
15: MockKernel.endBlock();
16: }
17:
18: /**
19: * Set level of tolerance when comparing java.util.Date objects
20: * @param milliseconds Maximum difference two dates are allowed to mismatch to be considered the same.
21: */
22: public static void setTimeTolerance(long milliseconds) {
23: MockKernel.setTimeTolerance(milliseconds);
24: }
25:
26: public static void verify() {
27: MockKernel.verify();
28: }
29:
30: /**
31: * Injects a mock into private/protected field of an object.
32: * @param to Object to store the mock.
33: * @param fieldName Name of the field.
34: * @param mock Mock object.
35: */
36: public static void injectMock(Object to, String fieldName,
37: Object mock) throws Exception {
38: Field f = to.getClass().getDeclaredField(fieldName);
39: if (!f.isAccessible())
40: f.setAccessible(true);
41: f.set(to, mock);
42: }
43: }
|