/** * Creates a control, order checking is enabled by default. * * @return the control. */ public static IMocksControl createStrictControl() { return createControl(MockType.STRICT); }
/** * Creates a control, order checking is disabled by default. * * @return the control. */ public static IMocksControl createControl() { return createControl(MockType.DEFAULT); }
/** * Creates a control, order checking is disabled by default, and the mock * objects created by this control will return {@code 0}, * {@code null} or {@code false} for unexpected invocations. * * @return the control. */ public static IMocksControl createNiceControl() { return createControl(MockType.NICE); }
/** * Creates a control of the given type. * * @param type the mock type. * @return the control. * @since 3.2 */ public IMocksControl createControl(MockType type) { IMocksControl ctrl = EasyMock.createControl(type); controls.add(ctrl); return ctrl; }
/** * Creates a mock object that implements the given interface, order checking * is disabled by default. * * @param toMock * the class or interface that should be mocked. * @param <T> * the interface that the mock object should implement. It is expected to be of * class {@code toMock}. * @return the mock object. * * @since 3.4 */ public static <T> T mock(Class<?> toMock) { return createControl().mock(toMock); }
/** * 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 or interface that should be mocked. * @param <T> * the interface that the mock object should implement. It is expected to be of * class {@code toMock}. * @return the mock object * * @since 3.4 */ public static <T> T mock(MockType type, Class<?> toMock) { return createControl(type).mock(toMock); }
/** * 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 or interface that should be mocked. * @param <T> * the interface that the mock object should implement. It is expected to be of * class {@code toMock}. * @return the mock object. * @throws IllegalArgumentException * if the name is not a valid Java identifier. * * @since 3.4 */ public static <T> T mock(String name, Class<?> toMock) { return createControl().mock(name, toMock); }
/** * Creates a mock object, of the requested type and name, that implements the given interface * or extends the given class * * @param name * the name of the mock object. * @param type * the type of the mock to be created. * @param toMock * the class or interface that should be mocked. * @param <T> * the interface that the mock object should implement. It is expected to be of * class {@code toMock}. * @return the mock object. * * @since 3.4 */ public static <T> T mock(String name, MockType type, Class<?> toMock) { return createControl(type).mock(name, toMock); }
public <R> R createMock(String name, MockType type) { IMocksControl control = (support == null ? EasyMock.createControl(type) : support .createControl(type)); return createMock(name, control); }
public <R> R createMock(MockType type) { IMocksControl control = (support == null ? EasyMock.createControl(type) : support .createControl(type)); return createMock(null, control); }
public <R> R createMock(String name) { IMocksControl control = (support == null ? EasyMock.createControl() : support.createControl()); return createMock(name, control); }
@Test public void testPropertySetting() throws Exception { IMocksControl control = createControl(); TypeEncounter<SomeInjectableBean> encounter = control.createMock(TypeEncounter.class); Provider<Injector> injectorProvider = control.createMock(Provider.class); Injector injector = control.createMock(Injector.class); expect(encounter.getProvider(Injector.class)).andReturn(injectorProvider); expect(injectorProvider.get()).andReturn(injector).anyTimes(); Capture<MembersInjector<SomeInjectableBean>> capture = new Capture<MembersInjector<SomeInjectableBean>>(); encounter.register(and(anyObject(MembersInjector.class), capture(capture))); SecurityManager securityManager = control.createMock(SecurityManager.class); String property = "myPropertyValue"; expect(injector.getInstance(Key.get(SecurityManager.class))).andReturn(securityManager); expect(injector.getInstance(Key.get(String.class, Names.named("shiro.myProperty")))).andReturn(property); expect(injector.getInstance(Key.get(String.class, Names.named("shiro.unavailableProperty")))) .andThrow(new ConfigurationException(Collections.singleton(new Message("Not Available!")))); expect((Map)injector.getInstance(BeanTypeListener.MAP_KEY)).andReturn(Collections.EMPTY_MAP).anyTimes(); control.replay(); BeanTypeListener underTest = new BeanTypeListener(); underTest.hear(TypeLiteral.get(SomeInjectableBean.class), encounter); SomeInjectableBean bean = new SomeInjectableBean(); capture.getValue().injectMembers(bean); assertSame(securityManager, bean.securityManager); assertSame(property, bean.myProperty); assertNull(bean.unavailableProperty); control.verify(); }
@Override public final void setUp() { inits = 0; doFilters = 0; destroys = 0; control = EasyMock.createControl(); GuiceFilter.reset(); }
public void testSimple() throws Exception { IMocksControl testControl = createControl(); TestFilterChain testFilterChain = new TestFilterChain(); HttpServletRequest req = testControl.createMock(HttpServletRequest.class); HttpServletResponse res = testControl.createMock(HttpServletResponse.class); expect(req.getMethod()).andReturn("GET").anyTimes(); expect(req.getRequestURI()).andReturn("/bar/foo").anyTimes(); expect(req.getServletPath()).andReturn("/bar/foo").anyTimes(); expect(req.getContextPath()).andReturn("").anyTimes(); testControl.replay(); guiceFilter.doFilter(req, res, testFilterChain); assertFalse(testFilterChain.isTriggered()); assertFalse(fooServlet.isTriggered()); assertTrue(barServlet.isTriggered()); testControl.verify(); }
@Override protected IMocksControl initialValue() { return EasyMock.createControl(); } }
assertNotSame(fooServlet, barServlet); globalControl = createControl(); servletContext = globalControl.createMock(ServletContext.class); filterConfig = globalControl.createMock(FilterConfig.class);
private void runTest( final String requestURI, final String servletPath, final String contextPath, final boolean filterResult, final boolean fooResult, final boolean barResult) throws Exception { IMocksControl testControl = createControl(); barServlet.clear(); fooServlet.clear(); TestFilterChain testFilterChain = new TestFilterChain(); HttpServletRequest req = testControl.createMock(HttpServletRequest.class); HttpServletResponse res = testControl.createMock(HttpServletResponse.class); expect(req.getMethod()).andReturn("GET").anyTimes(); expect(req.getRequestURI()).andReturn(requestURI).anyTimes(); expect(req.getServletPath()).andReturn(servletPath).anyTimes(); expect(req.getContextPath()).andReturn(contextPath).anyTimes(); testControl.replay(); guiceFilter.doFilter(req, res, testFilterChain); assertEquals(filterResult, testFilterChain.isTriggered()); assertEquals(fooResult, fooServlet.isTriggered()); assertEquals(barResult, barServlet.isTriggered()); testControl.verify(); }
/** * Creates a control, order checking is disabled by default. * * @return the control. */ public IMocksControl createControl() { IMocksControl ctrl = EasyMock.createControl(); controls.add(ctrl); return ctrl; }
@Test public void removeNonMandatoryProperty() throws CommitFailedException { EffectiveType effective = createControl().createMock(EffectiveType.class); expect(effective.isMandatoryProperty("mandatory")).andReturn(false); replay(effective); TypeEditor editor = new TypeEditor(effective); editor.propertyDeleted(PropertyStates.createProperty("mandatory", "")); }
@Before public void setUp() { control = EasyMock.createControl(); jsUri = control.createMock(JsUri.class); request = control.createMock(JsRequest.class); response = new JsResponseBuilder(); processor = new AddOnloadFunctionProcessor(); EasyMock.expect(request.getJsUri()).andReturn(jsUri); }