org.easymock.EasyMock.createControl()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中org.easymock.EasyMock.createControl()方法的一些代码示例,展示了EasyMock.createControl()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EasyMock.createControl()方法的具体详情如下:
包路径:org.easymock.EasyMock
类名称:EasyMock
方法名:createControl

EasyMock.createControl介绍

[英]Creates a control, order checking is disabled by default.
[中]创建控件,默认情况下禁用顺序检查。

代码示例

代码示例来源:origin: org.easymock/easymock

  1. /**
  2. * Creates a control, order checking is enabled by default.
  3. *
  4. * @return the control.
  5. */
  6. public static IMocksControl createStrictControl() {
  7. return createControl(MockType.STRICT);
  8. }

代码示例来源:origin: org.easymock/easymock

  1. /**
  2. * Creates a control, order checking is disabled by default.
  3. *
  4. * @return the control.
  5. */
  6. public static IMocksControl createControl() {
  7. return createControl(MockType.DEFAULT);
  8. }

代码示例来源:origin: org.easymock/easymock

  1. /**
  2. * Creates a control, order checking is disabled by default, and the mock
  3. * objects created by this control will return {@code 0},
  4. * {@code null} or {@code false} for unexpected invocations.
  5. *
  6. * @return the control.
  7. */
  8. public static IMocksControl createNiceControl() {
  9. return createControl(MockType.NICE);
  10. }

代码示例来源:origin: org.easymock/easymock

  1. /**
  2. * Creates a control of the given type.
  3. *
  4. * @param type the mock type.
  5. * @return the control.
  6. * @since 3.2
  7. */
  8. public IMocksControl createControl(MockType type) {
  9. IMocksControl ctrl = EasyMock.createControl(type);
  10. controls.add(ctrl);
  11. return ctrl;
  12. }

代码示例来源:origin: org.easymock/easymock

  1. /**
  2. * Creates a mock object that implements the given interface, order checking
  3. * is disabled by default.
  4. *
  5. * @param toMock
  6. * the class or interface that should be mocked.
  7. * @param <T>
  8. * the interface that the mock object should implement. It is expected to be of
  9. * class {@code toMock}.
  10. * @return the mock object.
  11. *
  12. * @since 3.4
  13. */
  14. public static <T> T mock(Class<?> toMock) {
  15. return createControl().mock(toMock);
  16. }

代码示例来源:origin: org.easymock/easymock

  1. /**
  2. * Creates a mock object, of the requested type, that implements the given interface
  3. * or extends the given class
  4. *
  5. * @param type
  6. * the type of the mock to be created.
  7. * @param toMock
  8. * the class or interface that should be mocked.
  9. * @param <T>
  10. * the interface that the mock object should implement. It is expected to be of
  11. * class {@code toMock}.
  12. * @return the mock object
  13. *
  14. * @since 3.4
  15. */
  16. public static <T> T mock(MockType type, Class<?> toMock) {
  17. return createControl(type).mock(toMock);
  18. }

代码示例来源:origin: org.easymock/easymock

  1. /**
  2. * Creates a mock object that implements the given interface, order checking
  3. * is disabled by default.
  4. *
  5. * @param name
  6. * the name of the mock object.
  7. * @param toMock
  8. * the class or interface that should be mocked.
  9. * @param <T>
  10. * the interface that the mock object should implement. It is expected to be of
  11. * class {@code toMock}.
  12. * @return the mock object.
  13. * @throws IllegalArgumentException
  14. * if the name is not a valid Java identifier.
  15. *
  16. * @since 3.4
  17. */
  18. public static <T> T mock(String name, Class<?> toMock) {
  19. return createControl().mock(name, toMock);
  20. }

代码示例来源:origin: org.easymock/easymock

  1. /**
  2. * Creates a mock object, of the requested type and name, that implements the given interface
  3. * or extends the given class
  4. *
  5. * @param name
  6. * the name of the mock object.
  7. * @param type
  8. * the type of the mock to be created.
  9. * @param toMock
  10. * the class or interface that should be mocked.
  11. * @param <T>
  12. * the interface that the mock object should implement. It is expected to be of
  13. * class {@code toMock}.
  14. * @return the mock object.
  15. *
  16. * @since 3.4
  17. */
  18. public static <T> T mock(String name, MockType type, Class<?> toMock) {
  19. return createControl(type).mock(name, toMock);
  20. }

代码示例来源:origin: org.easymock/easymock

  1. public <R> R createMock(String name, MockType type) {
  2. IMocksControl control = (support == null ? EasyMock.createControl(type) : support
  3. .createControl(type));
  4. return createMock(name, control);
  5. }

代码示例来源:origin: org.easymock/easymock

  1. public <R> R createMock(MockType type) {
  2. IMocksControl control = (support == null ? EasyMock.createControl(type) : support
  3. .createControl(type));
  4. return createMock(null, control);
  5. }

代码示例来源:origin: org.easymock/easymock

  1. public <R> R createMock(String name) {
  2. IMocksControl control = (support == null ? EasyMock.createControl() : support.createControl());
  3. return createMock(name, control);
  4. }

代码示例来源:origin: apache/shiro

  1. @Test
  2. public void testPropertySetting() throws Exception {
  3. IMocksControl control = createControl();
  4. TypeEncounter<SomeInjectableBean> encounter = control.createMock(TypeEncounter.class);
  5. Provider<Injector> injectorProvider = control.createMock(Provider.class);
  6. Injector injector = control.createMock(Injector.class);
  7. expect(encounter.getProvider(Injector.class)).andReturn(injectorProvider);
  8. expect(injectorProvider.get()).andReturn(injector).anyTimes();
  9. Capture<MembersInjector<SomeInjectableBean>> capture = new Capture<MembersInjector<SomeInjectableBean>>();
  10. encounter.register(and(anyObject(MembersInjector.class), capture(capture)));
  11. SecurityManager securityManager = control.createMock(SecurityManager.class);
  12. String property = "myPropertyValue";
  13. expect(injector.getInstance(Key.get(SecurityManager.class))).andReturn(securityManager);
  14. expect(injector.getInstance(Key.get(String.class, Names.named("shiro.myProperty")))).andReturn(property);
  15. expect(injector.getInstance(Key.get(String.class, Names.named("shiro.unavailableProperty"))))
  16. .andThrow(new ConfigurationException(Collections.singleton(new Message("Not Available!"))));
  17. expect((Map)injector.getInstance(BeanTypeListener.MAP_KEY)).andReturn(Collections.EMPTY_MAP).anyTimes();
  18. control.replay();
  19. BeanTypeListener underTest = new BeanTypeListener();
  20. underTest.hear(TypeLiteral.get(SomeInjectableBean.class), encounter);
  21. SomeInjectableBean bean = new SomeInjectableBean();
  22. capture.getValue().injectMembers(bean);
  23. assertSame(securityManager, bean.securityManager);
  24. assertSame(property, bean.myProperty);
  25. assertNull(bean.unavailableProperty);
  26. control.verify();
  27. }

代码示例来源:origin: com.google.inject.extensions/guice-servlet

  1. @Override
  2. public final void setUp() {
  3. inits = 0;
  4. doFilters = 0;
  5. destroys = 0;
  6. control = EasyMock.createControl();
  7. GuiceFilter.reset();
  8. }

代码示例来源:origin: com.google.inject.extensions/guice-servlet

  1. public void testSimple() throws Exception {
  2. IMocksControl testControl = createControl();
  3. TestFilterChain testFilterChain = new TestFilterChain();
  4. HttpServletRequest req = testControl.createMock(HttpServletRequest.class);
  5. HttpServletResponse res = testControl.createMock(HttpServletResponse.class);
  6. expect(req.getMethod()).andReturn("GET").anyTimes();
  7. expect(req.getRequestURI()).andReturn("/bar/foo").anyTimes();
  8. expect(req.getServletPath()).andReturn("/bar/foo").anyTimes();
  9. expect(req.getContextPath()).andReturn("").anyTimes();
  10. testControl.replay();
  11. guiceFilter.doFilter(req, res, testFilterChain);
  12. assertFalse(testFilterChain.isTriggered());
  13. assertFalse(fooServlet.isTriggered());
  14. assertTrue(barServlet.isTriggered());
  15. testControl.verify();
  16. }

代码示例来源:origin: org.apache.tapestry/tapestry-test

  1. @Override
  2. protected IMocksControl initialValue()
  3. {
  4. return EasyMock.createControl();
  5. }
  6. }

代码示例来源:origin: com.google.inject.extensions/guice-servlet

  1. assertNotSame(fooServlet, barServlet);
  2. globalControl = createControl();
  3. servletContext = globalControl.createMock(ServletContext.class);
  4. filterConfig = globalControl.createMock(FilterConfig.class);

代码示例来源:origin: com.google.inject.extensions/guice-servlet

  1. private void runTest(
  2. final String requestURI,
  3. final String servletPath,
  4. final String contextPath,
  5. final boolean filterResult,
  6. final boolean fooResult,
  7. final boolean barResult)
  8. throws Exception {
  9. IMocksControl testControl = createControl();
  10. barServlet.clear();
  11. fooServlet.clear();
  12. TestFilterChain testFilterChain = new TestFilterChain();
  13. HttpServletRequest req = testControl.createMock(HttpServletRequest.class);
  14. HttpServletResponse res = testControl.createMock(HttpServletResponse.class);
  15. expect(req.getMethod()).andReturn("GET").anyTimes();
  16. expect(req.getRequestURI()).andReturn(requestURI).anyTimes();
  17. expect(req.getServletPath()).andReturn(servletPath).anyTimes();
  18. expect(req.getContextPath()).andReturn(contextPath).anyTimes();
  19. testControl.replay();
  20. guiceFilter.doFilter(req, res, testFilterChain);
  21. assertEquals(filterResult, testFilterChain.isTriggered());
  22. assertEquals(fooResult, fooServlet.isTriggered());
  23. assertEquals(barResult, barServlet.isTriggered());
  24. testControl.verify();
  25. }

代码示例来源:origin: org.easymock/com.springsource.org.easymock

  1. /**
  2. * Creates a control, order checking is disabled by default.
  3. *
  4. * @return the control.
  5. */
  6. public IMocksControl createControl() {
  7. IMocksControl ctrl = EasyMock.createControl();
  8. controls.add(ctrl);
  9. return ctrl;
  10. }

代码示例来源:origin: apache/jackrabbit-oak

  1. @Test
  2. public void removeNonMandatoryProperty() throws CommitFailedException {
  3. EffectiveType effective = createControl().createMock(EffectiveType.class);
  4. expect(effective.isMandatoryProperty("mandatory")).andReturn(false);
  5. replay(effective);
  6. TypeEditor editor = new TypeEditor(effective);
  7. editor.propertyDeleted(PropertyStates.createProperty("mandatory", ""));
  8. }

代码示例来源:origin: org.apache.shindig/shindig-gadgets

  1. @Before
  2. public void setUp() {
  3. control = EasyMock.createControl();
  4. jsUri = control.createMock(JsUri.class);
  5. request = control.createMock(JsRequest.class);
  6. response = new JsResponseBuilder();
  7. processor = new AddOnloadFunctionProcessor();
  8. EasyMock.expect(request.getJsUri()).andReturn(jsUri);
  9. }

相关文章