@Override public void evaluate() throws Throwable { EasyMockSupport.injectMocks(test); originalStatement.evaluate(); } }
/** * Creates a control, order checking is disabled by default. * * @return the control. */ public IMocksControl createControl() { return createControl(MockType.DEFAULT); }
Object mock; if (host instanceof EasyMockSupport) { mock = ((EasyMockSupport) host).createMock(name, mockType, type);
/** * Creates a mock object that implements the given interface, order checking * is disabled by default, and the mock object will return {@code 0}, * {@code null} or {@code false} for unexpected invocations. * * @param <T> * the interface that the mock object should implement. * @param <R> * the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the * caller, we return a different type * @param toMock * the class of the interface that the mock object should * implement. * @return the mock object. * * @since ${project.version} */ public <T, R> R niceMock(Class<T> toMock) { return createNiceControl().createMock(toMock); }
/** * Creates a mock object that implements the given interface, order checking * is enabled by default. * * @param <T> * the interface that the mock object should implement. * @param <R> * the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the * caller, we return a different type * @param toMock * the class of the interface that the mock object should * implement. * @return the mock object. * * @since ${project.version} */ public <T, R> R strictMock(Class<T> toMock) { return createStrictControl().createMock(toMock); }
@Before public void setup() { final URL log4jFile = TestLogging.class.getResource("/log4j.xml"); DOMConfigurator.configure(log4jFile); final Logger root = Logger.getRootLogger(); recordingAppender = new RecordingAppender("%X{track} - %m%n"); root.addAppender(recordingAppender); log = Log.forName("tracker"); req = new MockedHttpServletRequest(); value = UUID.randomUUID(); res = mockSupport.createMock(HttpServletResponse.class); res.setHeader(TrackingFilter.X_NESS_TRACK, value.toString()); EasyMock.expectLastCall().once(); mockSupport.replayAll(); }
/** * Creates a mock object that implements the given interface, order checking * is disabled by default, and the mock object will return {@code 0}, * {@code null} or {@code false} for unexpected invocations. * * @param name * the name of the mock object. * @param toMock * the class of the interface that the mock object should * implement. * * @param <T> * the interface that the mock object should implement. * @param <R> * the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the * caller, we return a different type * @return the mock object. * @throws IllegalArgumentException * if the name is not a valid Java identifier. * * @since ${project.version} */ public <T, R> R niceMock(String name, Class<T> toMock) { return createNiceControl().createMock(name, toMock); }
/** * Creates a mock object that implements the given interface, order checking * is enabled by default. * * @param name * the name of the mock object. * @param toMock * the class of the interface that the mock object should * implement. * @param <T> * the interface that the mock object should implement. * @param <R> * the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the * caller, we return a different type * @return the mock object. * @throws IllegalArgumentException * if the name is not a valid Java identifier. * * @since ${project.version} */ public <T, R> R strictMock(String name, Class<T> toMock) { return createStrictControl().createMock(name, toMock); }
/** * We are required to override a deprecated method because it's the only way the perform * the mock injection before the {@code @Before} of our class being called. Using a statement * wouldn't work. * * @param method test method class * @param target test class instance * @param statement current statement * @return a statement to return to the caller */ @Override protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) { EasyMockSupport.injectMocks(target); return super.withBefores(method, target, statement); } }
/** * Creates a mock object that implements the given interface, order checking * is disabled by default. * * @param <T> * the interface that the mock object should implement. * @param <R> * the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the * caller, we return a different type * @param toMock * the class of the interface that the mock object should * implement. * @return the mock object. * * @since ${project.version} */ public <T, R> R mock(Class<T> toMock) { return createControl().createMock(toMock); }
public <R> R createNiceMock(String name) { IMocksControl control = (support == null ? EasyMock.createNiceControl() : support .createNiceControl()); return createMock(name, control); }
public <R> R createStrictMock(String name) { IMocksControl control = (support == null ? EasyMock.createStrictControl() : support .createStrictControl()); return createMock(name, control); }
@Before public void setup() { req = new MockedHttpServletRequest(); value = UUID.randomUUID(); res = mockSupport.createMock(HttpServletResponse.class); }
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { EasyMockSupport.injectMocks(method.getTestMethod().getInstance()); }
/** * Creates a mock object of the requested type that implements the given interface or extends * the given class * * @param type * the type of the mock to be created. * @param toMock * the class of the interface that the mock object should * implement. * @param <T> * the interface that the mock object should implement. * @param <R> * the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the * caller, we return a different type * @return the mock object. * @throws IllegalArgumentException * if the name is not a valid Java identifier. * * @since ${project.version} */ public <T, R> R mock(MockType type, Class<T> toMock) { return createControl(type).createMock(toMock); }
/** * Creates a mock object that implements the given interface, order checking * is disabled by default, and the mock object will return <code>0</code>, * <code>null</code> or <code>false</code> for unexpected invocations. * * @param <T> * the interface that the mock object should implement. * @param toMock * the class of the interface that the mock object should * implement. * @return the mock object. */ public <T> T createNiceMock(Class<T> toMock) { return createNiceControl().createMock(toMock); }
/** * Creates a mock object that implements the given interface, order checking * is enabled by default. * * @param <T> * the interface that the mock object should implement. * @param toMock * the class of the interface that the mock object should * implement. * @return the mock object. */ public <T> T createStrictMock(Class<T> toMock) { return createStrictControl().createMock(toMock); }
public T produce(CreationalContext<T> ctx) { T o = injectionTarget.produce(ctx); EasyMockSupport.injectMocks(o); return o; }
/** * Creates a mock object that implements the given interface, order checking * is disabled by default. * * @param name * the name of the mock object. * @param toMock * the class of the interface that the mock object should * implement. * * @param <T> * the interface that the mock object should implement. * @param <R> * the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the * caller, we return a different type * @return the mock object. * @throws IllegalArgumentException * if the name is not a valid Java identifier. * * @since ${project.version} */ public <T, R> R mock(String name, Class<T> toMock) { return createControl().createMock(name, toMock); }
/** * Creates a mock object that implements the given interface, order checking * is disabled by default, and the mock object will return <code>0</code>, * <code>null</code> or <code>false</code> for unexpected invocations. * * @param name * the name of the mock object. * @param toMock * the class of the interface that the mock object should * implement. * * @param <T> * the interface that the mock object should implement. * @return the mock object. * @throws IllegalArgumentException * if the name is not a valid Java identifier. */ public <T> T createNiceMock(String name, Class<T> toMock) { return createNiceControl().createMock(name, toMock); }