Package org.jmock

Examples of org.jmock.Mock


    }

    public void testMonitoringHappensBeforeAndOnFailOfImpossibleComponentsInstantiation() throws NoSuchMethodException {
        final long beforeTime = System.currentTimeMillis();

        Mock monitor = mock(ComponentMonitor.class);
        Constructor barfingActionListenerCtor = BarfingActionListener.class.getConstructor(new Class[0]);
        monitor.expects(once()).method("instantiating").with(eq(barfingActionListenerCtor));

        Constraint isITE = new Constraint() {
            public boolean eval(Object o) {
                Exception ex = (Exception) o;
                return ex instanceof InvocationTargetException;
            }

            public StringBuffer describeTo(StringBuffer stringBuffer) {
                return stringBuffer.append("Should have been unable to instantiate");
            }
        };

        monitor.expects(once()).method("instantiationFailed").with(eq(barfingActionListenerCtor), isITE);
        ConstructorInjectionComponentAdapter cica = new ConstructorInjectionComponentAdapter(ActionListener.class, BarfingActionListener.class,
                new Parameter[0], false, (ComponentMonitor) monitor.proxy());
        try {
            cica.getComponentInstance(null);
            fail("Should barf");
        } catch (RuntimeException e) {
            assertEquals("Barf!", e.getMessage());
View Full Code Here


        extends MockObjectTestCase {

    public void testShouldInstantiateArrayOfStrings() {
        CollectionComponentParameter ccp = new CollectionComponentParameter();

        Mock componentAdapterMock = mock(ComponentAdapter.class);
        componentAdapterMock.expects(atLeastOnce()).method("getComponentKey").will(returnValue("x"));
        Mock containerMock = mock(PicoContainer.class);
        containerMock.expects(once()).method("getComponentAdapters").withNoArguments().will(returnValue(new HashSet()));
        containerMock.expects(once()).method("getComponentAdaptersOfType").with(eq(String.class)).will(
                returnValue(Arrays.asList(new ComponentAdapter[]{
                        new InstanceComponentAdapter("y", "Hello"), new InstanceComponentAdapter("z", "World")})));
        containerMock.expects(once()).method("getComponentInstance").with(eq("z")).will(returnValue("World"));
        containerMock.expects(once()).method("getComponentInstance").with(eq("y")).will(returnValue("Hello"));
        containerMock.expects(once()).method("getParent").withNoArguments().will(returnValue(null));

        List expected = Arrays.asList(new String[]{"Hello", "World"});
        Collections.sort(expected);
        List actual = Arrays.asList((Object[]) ccp.resolveInstance(
                (PicoContainer) containerMock.proxy(), (ComponentAdapter) componentAdapterMock.proxy(), String[].class));
        Collections.sort(actual);
        assertEquals(expected, actual);
    }
View Full Code Here

    public MessageEndpointProxyTest(String name) {
        super(name);
    }
   
    protected void setUp() {
        mockEndpoint = new Mock(EndpointAndListener.class);
        stubMessage = new Mock(Message.class);
        endpointProxy = new MessageEndpointProxy((MessageEndpoint) mockEndpoint.proxy());      
    }
View Full Code Here

        stubMessage = new Mock(Message.class);
        endpointProxy = new MessageEndpointProxy((MessageEndpoint) mockEndpoint.proxy());      
    }

    public void testInvalidConstruction() {
        Mock mockEndpoint = new Mock(MessageEndpoint.class);
        try {
            MessageEndpointProxy proxy = new MessageEndpointProxy((MessageEndpoint) mockEndpoint.proxy());
            fail("An exception should have been thrown");
        } catch (IllegalArgumentException e) {
            assertTrue(true);
        }
    }
View Full Code Here

     * @throws java.lang.Exception
     */
    protected void setUp() throws Exception
    {
        super.setUp();
        entityAccessMock = new Mock(PortletEntityAccessComponent.class);
        fragMock = new Mock(Fragment.class);
        entityMock = new Mock(MutablePortletEntity.class);
        windowListMock = new Mock(CompositeWindowList.class);
        windowAccess = new PortletWindowAccessorImpl((PortletEntityAccessComponent) entityAccessMock.proxy());
    }
View Full Code Here

    protected void setUp() throws Exception {
        // Override testService in test case.
        _testService = mock(TestService.class);
        // We use one partner to simulate failing service and receive message upon process completion.
        final Mock partner = mock(MessageExchangeContext.class);
        // Some processes will complete, but not all.
        partner.expects(atMostOnce()).match(invokeOnOperation("respond")).will(new CustomStub("process completed") {
            public Object invoke(Invocation invocation) {
                ((TestService)_testService.proxy()).completed();
                return null;
            }
        });
        // There will be multiple calls to invoke.
        partner.expects(atLeastOnce()).match(invokeOnOperation("invoke")).will(new CustomStub("invoke failing service") {
            public Object invoke(Invocation invocation) {
                PartnerRoleMessageExchange mex = (PartnerRoleMessageExchange) invocation.parameterValues.get(0);
                if (((TestService)_testService.proxy()).invoke()) {
                    Message response = mex.createMessage(mex.getOperation().getOutput().getMessage().getQName());
                    response.setMessage(DOMUtils.newDocument().createElementNS(NAMESPACE, "tns:ResponseElement"));
                    mex.reply(response);
                } else {
                    mex.replyWithFailure(MessageExchange.FailureType.COMMUNICATION_ERROR, "BangGoesInvoke", null);
                }
                return null;
            }
        });
        // Faulting a process would send the fault message asynchronously.
        // (Which might be a bug, but right now we swallow it).
        partner.expects(atMostOnce()).method("onAsyncReply").will(new CustomStub("async reply") {
            public Object invoke(Invocation invocation) {
                return null;
            }
        });
       
        _server = new MockBpelServer() {
            protected MessageExchangeContext createMessageExchangeContext() {
                return (MessageExchangeContext) partner.proxy();
            }
        };
        _server.deploy(new File(new URI(this.getClass().getResource("/recovery").toString())));
        _management = new BpelManagementFacadeImpl(_server._server,_server._store);
    }
View Full Code Here

   *
   * @throws ValidatorException  when test fails
   */
  public void testNull() throws ValidatorException
  {
    Mock mock = buildMockUIComponent();
    UIComponent component = (UIComponent) mock.proxy();
    MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
    LongRangeValidator validator = new LongRangeValidator();

    doTestNull(facesContext, wrapper, validator);
  }
View Full Code Here

  /**
   * Test when context is set to null
   */
  public void testNullContext()
  {
    Mock mock = buildMockUIComponent();
    UIComponent component = (UIComponent) mock.proxy();
    MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
    LongRangeValidator validator = new LongRangeValidator();

    doTestNullContext(wrapper, validator);
  }
View Full Code Here

  public void testTooLarge()
  {
    // since the pattern has not been set it will be null
    // let us push some arbitary value
    Mock mock = mock(UIComponent.class);
    UIComponent component = (UIComponent) mock.proxy();
    MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
    setMockLabelForComponent(wrapper);

    try
    {
      LongRangeValidator validator = new LongRangeValidator();
      validator.setMaximum(100);
      validator.validate(facesContext, component, 1000);
      // test fails if it is here

      fail("Expected Null pointer exception");
    }
    catch (ValidatorException ve)
    {
      // suppress it - this is as expected
    }
    mock.verify();
  }
View Full Code Here

  public void testWrongType()
  {
    // since the pattern has not been set it will be null
    // let us push some arbitary value
    Mock mock = mock(UIComponent.class);
    UIComponent component = (UIComponent) mock.proxy();
    MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
    setMockLabelForComponent(wrapper);

    try
    {
      LongRangeValidator validator = new LongRangeValidator();
      validator.setMaximum(2);
      validator.validate(facesContext, component, "thisShouldFail");
      // test fails if it is here

      fail("Expected Null pointer exception");
    }
    catch (ValidatorException ve)
    {
      // suppress it - this is as expected
    }
    mock.verify();
  }
View Full Code Here

TOP

Related Classes of org.jmock.Mock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.