Package org.jmock

Examples of org.jmock.Mock


    protected void setUp()
        throws Exception
    {
        super.setUp();

        listener = new Mock(IFeedListener.class);

        feed = new DummyNetworkFeed();
        feed.addListener((IFeedListener)listener.proxy());
    }
View Full Code Here


    protected void setUp()
        throws Exception
    {
        super.setUp();

        listener = new Mock(IFeedListener.class);

        feed = new DirectFeed();
        feed.addListener((IFeedListener)listener.proxy());

        synchronized (TestDirectFeedEvents.class)
View Full Code Here

            assertFalse(touchables[i] instanceof DecoratedTouchable);
        }
    }
   
    public void testCollectionChildIdVisitedBreadthFirst() {
        Mock             mockVisior = mock(PicoVisitor.class);
        PicoVisitor     visitor = (PicoVisitor) mockVisior.proxy();

        Mock       mockC1 = mock(Constraint.class, "constraint 1");
        Constraint c1     = (Constraint) mockC1.proxy();

        Constraint c = new CollectionConstraint(c1);
       
        mockVisior.expects(once()).method("visitParameter")
            .with(same(c)).id("v");
        mockC1.expects(once()).method("accept")
            .with(same(visitor)).after(mockVisior, "v");
       
        c.accept(visitor);
    }
View Full Code Here

    public void testVisitingOfImmutableContainerWorks() {
        DefaultPicoContainer pico = new DefaultPicoContainer();
        Object foo = new Object();
        ComponentAdapter componentAdapter = pico.registerComponentInstance(foo);

        Mock fooVisitor = new Mock(PicoVisitor.class);
        fooVisitor.expects(once()).method("visitContainer").with(eq(pico));
        fooVisitor.expects(once()).method("visitComponentAdapter").with(eq(componentAdapter));

        ImmutablePicoContainer ipc = new ImmutablePicoContainer(pico);

        ipc.accept((PicoVisitor) fooVisitor.proxy());


    }
View Full Code Here

    }
   
    public void shouldVerifyMocks() throws Exception {
        // given...
      JMockSugar s = new JMockSugar() {};
        Mock mock1 = new Mock(Verifiable.class);
        Mock mock2 = new Mock(Verifiable.class);
        UsingJMock instance =
            new BehaviourClassWithMockMocks((Verifiable)mock1.proxy(), (Verifiable) mock2.proxy());
       
        // expect...
        mock1.expects(s.once()).method("verify").withNoArguments();
        mock2.expects(s.once()).method("verify").withNoArguments();
       
        // when...
        instance.verifyMocks();
       
        // verify...
        mock1.verify();
        mock2.verify();
    }
View Full Code Here

        void doStuff();
    }
   
    public static class BehaviourClassUsingJMock extends UsingJMock {
        public void shouldDoSomething() {
            new Mock(Interface.class);
            new Mock(Interface.class);
        }
View Full Code Here

        public Mock anInterface;
        public Mock anAbstractClass;
        public Mock aConcreteClass;
       
        public void shouldDoSomething() {
            anInterface = new Mock(AnInterface.class);
            anAbstractClass = new Mock(AnAbstractClass.class);
            aConcreteClass = new Mock(AConcreteClass.class);
        }
View Full Code Here

            assertTrue(e.getMessage().indexOf(String.class.getName()) >= 0);
        }
    }

    public void testThrownRuntimeExceptionIsUnwrapped() {
        Mock mockPico = mock(PicoContainer.class);
        PicoVisitor visitor = new VerifyingVisitor();
        Error exception = new Error("junit");
        mockPico.expects(once()).method("accept").with(same(visitor)).will(
                throwException(new PicoIntrospectionException("message", exception)));
        try {
            visitor.traverse(mockPico.proxy());
            fail("PicoIntrospectionException expected");
        } catch (RuntimeException e) {
            assertEquals("message", e.getMessage());
            assertSame(exception, ((PicoIntrospectionException)e).getCause());
        }
View Full Code Here

            assertSame(exception, ((PicoIntrospectionException)e).getCause());
        }
    }

    public void testThrownErrorIsUnwrapped() {
        Mock mockPico = mock(PicoContainer.class);
        PicoVisitor visitor = new VerifyingVisitor();
        Error error = new InternalError("junit");
        mockPico.expects(once()).method("accept").with(same(visitor)).id("1");
        mockPico.expects(once()).method("accept").with(same(visitor)).after("1").will(throwException(error));
        visitor.traverse(mockPico.proxy());
        try {
            visitor.traverse(mockPico.proxy());
            fail("UndeclaredThrowableException expected");
        } catch(InternalError e) {
            assertEquals("junit", e.getMessage());
        }
    }
View Full Code Here

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

        Mock monitor = mock(ComponentMonitor.class);
        Constructor emptyHashMapCtor = HashMap.class.getConstructor(new Class[0]);
        monitor.expects(once()).method("instantiating").with(eq(emptyHashMapCtor));
        Constraint startIsAfterBegin = new Constraint() {
            public boolean eval(Object o) {
                Long startTime = (Long) o;
                return beforeTime <= startTime.longValue();
            }

            public StringBuffer describeTo(StringBuffer stringBuffer) {
                return stringBuffer.append("The startTime wasn't after the begin of the test");
            }
        };
        Constraint durationIsGreaterThanOrEqualToZero = new Constraint() {
            public boolean eval(Object o) {
                Long duration = (Long) o;
                return 0 <= duration.longValue();
            }

            public StringBuffer describeTo(StringBuffer stringBuffer) {
                return stringBuffer.append("The endTime wasn't after the startTime");
            }
        };

        monitor.expects(once()).method("instantiated").with(eq(emptyHashMapCtor), startIsAfterBegin, durationIsGreaterThanOrEqualToZero);
        ConstructorInjectionComponentAdapter cica = new ConstructorInjectionComponentAdapter(Map.class, HashMap.class,
                new Parameter[0], false, (ComponentMonitor) monitor.proxy());
        cica.getComponentInstance(null);
    }
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.