Package org.jmock

Examples of org.jmock.Mock.expects()


        Object bar = Dispatching.object(new Class[]{Bar.class, BarSimilar.class}, new Object[]{
                barMock.proxy(), barSimilarMock.proxy()}, getFactory());

        barMock.expects(once()).method("doSomething").with(eq("some thing"));
        barSimilarMock.expects(once()).method("doSomething").with(eq(1));

        ((Bar)bar).doSomething("some thing");
        ((BarSimilar)bar).doSomething(1);
    }
View Full Code Here


        assertEquals(0, pool.size());
    }

    public void testReturnedElementIsResetted() throws Exception {
        final Mock mockResetter = mock(Resetter.class);
        mockResetter.expects(once()).method("reset").will(returnValue(true));

        final Pool pool = new Pool(Identifiable.class, (Resetter)mockResetter.proxy(), getFactory());
        pool.add(createIdentifiables(1));
        Object borrowed = pool.get();
        ((Poolable)borrowed).returnInstanceToPool();
View Full Code Here

        Mock fooBarMock = mock(FooBar.class);

        Object foobar = Dispatching.object(
                new Class[]{Foo.class, Bar.class}, new Object[]{fooBarMock.proxy()}, getFactory());

        fooBarMock.expects(once()).method("doSomething").with(eq("some thing"));
        fooBarMock.expects(once()).method("getSomething").withNoArguments().will(returnValue("some thing"));

        assertEquals("some thing", ((Foo)foobar).getSomething());
        ((Bar)foobar).doSomething("some thing");
    }
View Full Code Here

        Object foobar = Dispatching.object(
                new Class[]{Foo.class, Bar.class}, new Object[]{fooBarMock.proxy()}, getFactory());

        fooBarMock.expects(once()).method("doSomething").with(eq("some thing"));
        fooBarMock.expects(once()).method("getSomething").withNoArguments().will(returnValue("some thing"));

        assertEquals("some thing", ((Foo)foobar).getSomething());
        ((Bar)foobar).doSomething("some thing");
    }
View Full Code Here

        ((Poolable)borrowed).returnInstanceToPool();
    }

    public void testGarbageCollectedElementIsResetted() throws Exception {
        final Mock mockResetter = mock(Resetter.class);
        mockResetter.expects(once()).method("reset").will(returnValue(true));

        final Pool pool = new Pool(Identifiable.class, (Resetter)mockResetter.proxy(), getFactory());
        pool.add(createIdentifiables(1));
        Object borrowed = pool.get();
        assertNotNull(borrowed);
View Full Code Here

        Object dummyInstance = new Object();
        Inspector inspector = getTestableInspector(dummyInstance);
        Class[] paramTypes = {Object.class, MetaProperty.class};
        Object[] params = {null, null};
        Mock mock = mock(PropertyValue.class, paramTypes, params);
        mock.expects(once()).method("getType");
        mock.expects(once()).method("getName");
        mock.expects(once()).method("getValue").will(throwException(new RuntimeException()));
        PropertyValue propertyValue = (PropertyValue) mock.proxy();
        String[] result = inspector.fieldInfo(propertyValue);
        assertEquals(Inspector.NOT_APPLICABLE, result[Inspector.MEMBER_VALUE_IDX]);
View Full Code Here

        Inspector inspector = getTestableInspector(dummyInstance);
        Class[] paramTypes = {Object.class, MetaProperty.class};
        Object[] params = {null, null};
        Mock mock = mock(PropertyValue.class, paramTypes, params);
        mock.expects(once()).method("getType");
        mock.expects(once()).method("getName");
        mock.expects(once()).method("getValue").will(throwException(new RuntimeException()));
        PropertyValue propertyValue = (PropertyValue) mock.proxy();
        String[] result = inspector.fieldInfo(propertyValue);
        assertEquals(Inspector.NOT_APPLICABLE, result[Inspector.MEMBER_VALUE_IDX]);
    }
View Full Code Here

        Class[] paramTypes = {Object.class, MetaProperty.class};
        Object[] params = {null, null};
        Mock mock = mock(PropertyValue.class, paramTypes, params);
        mock.expects(once()).method("getType");
        mock.expects(once()).method("getName");
        mock.expects(once()).method("getValue").will(throwException(new RuntimeException()));
        PropertyValue propertyValue = (PropertyValue) mock.proxy();
        String[] result = inspector.fieldInfo(propertyValue);
        assertEquals(Inspector.NOT_APPLICABLE, result[Inspector.MEMBER_VALUE_IDX]);
    }
View Full Code Here

        Interceptor interceptor = interceptorFactory.create(null);
        assertNotNull(interceptor);

        // verify that the dynaop interceptor delegates to the MethodInterceptor
        // in the container:
        methodInterceptorMock.expects(once()).method("invoke");
        interceptor.intercept(null);
    }

    public void testInterceptorNotFoundInContainer() {
        MutablePicoContainer container = new DefaultPicoContainer();
View Full Code Here

                "    component(A)\n" +
                "}");

        A a = new A();
        Mock cafMock = mock(ComponentAdapterFactory.class);
        cafMock.expects(once()).method("createComponentAdapter").with(same(A.class), same(A.class), eq(null)).will(returnValue(new InstanceComponentAdapter(A.class, a)));
        ComponentAdapterFactory componentAdapterFactory = (ComponentAdapterFactory) cafMock.proxy();
        PicoContainer pico = buildContainer(script, null, componentAdapterFactory);
        assertSame(a, pico.getComponentInstanceOfType(A.class));
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.