Package org.jmock

Examples of org.jmock.Mock


public class PublisherTest extends TestCase {

    public void testOneSubscriberReceivesAMessage() {
        // setup
        Mock mockSubscriber = new Mock(Subscriber.class);
        Publisher publisher = new Publisher();
        publisher.add((Subscriber) mockSubscriber.proxy());

        Message message = new Message();

        // expectations
        mockSubscriber.expect("receive", message);
       
        // execute
        publisher.publish(message);
       
        // verify
        mockSubscriber.verify();
    }
View Full Code Here


    public void setUp() {
        actions = createActions();
    }

    public void testHasDefaultNameBasedOnMockedType() {
        Mock mock = new Mock(MockTestActions.class);
        assertEquals("Should have same name", "mockMockTestActions", mock.toString());
    }
View Full Code Here

        Mock mock = new Mock(MockTestActions.class);
        assertEquals("Should have same name", "mockMockTestActions", mock.toString());
    }

    public void testCanBeExplicitlyNamed() {
        Mock otherMock = new Mock(MockTestActions.class, "otherMock");
        assertEquals("Should have same name", "otherMock", otherMock.toString());
    }
View Full Code Here

        AssertMo.assertIncludes("Should contain method name", "methodName", result);
        AssertMo.assertIncludes("Should contain args as an array", "[<1>, <2>]", result);
    }

    public void testMethodToStringWithProxyArg() throws Exception {
        Mock mockDummyInterface = new Mock(DummyInterface.class, "DummyMock");

        Invocation invocation =
                new Invocation("methodName", new Class[]{String.class, DummyInterface.class}, void.class,
                        new Object[]{"arg1", mockDummyInterface.proxy()});
        String result = invocation.toString();

        AssertMo.assertIncludes("Should contain method name", "methodName", result);
        AssertMo.assertIncludes("Should contain firstArg", "arg1", result);
        AssertMo.assertIncludes("Should contain second Arg", "DummyMock", result);
View Full Code Here

        mockMarket.verify();
    }

    public void xtestExample() {
        Mock mockMarket = new Mock(Market.class);
        Agent agent = new Agent((Market) mockMarket.proxy());
// 
//  
//      mockMarket.method("buyStock", "MSFT", new Integer(10)).void();
//
//    mockMarket.method("buyStock", "MSFT", new Integer(10)).returns(true)
View Full Code Here

                " =  = NestedConstraint", new IsEqual(new IsEqual("NestedConstraint")).toString());
    }

    public void testIsEqualToStringOnProxyArgument() {
        // Required for error message reporting
        Mock mockDummyInterface = new Mock(DummyInterface.class, "MockName");
        Constraint p = new IsEqual(mockDummyInterface.proxy());

        AssertMo.assertIncludes("Should get resolved toString() with no expectation error", "MockName", p.toString());
    }
View Full Code Here

    @Override
    public void setUp() throws Exception
    {
        super.setUp();

        Mock mockXWiki = mock(XWiki.class, new Class[] {}, new Object[] {});

        mockXWiki.stubs().method("getCacheFactory").will(returnValue(cacheFactory));
        mockXWiki.stubs().method("getXWikiPreference").will(returnValue(null));
        mockXWiki.stubs().method("getXWikiPreferenceAsInt").will(throwException(new NumberFormatException("null")));
        mockXWiki.stubs().method("Param").will(new CustomStub("Implements XWiki.Param")
        {
            public Object invoke(Invocation invocation) throws Throwable
            {
                return properties.getProperty((String) invocation.parameterValues.get(0));
            }
        });
        mockXWiki.stubs().method("ParamAsLong").will(new CustomStub("Implements XWiki.ParamAsLong")
        {
            public Object invoke(Invocation invocation) throws Throwable
            {
                return Long.parseLong(properties.getProperty((String) invocation.parameterValues.get(0)));
            }
        });

        getContext().setWiki((XWiki) mockXWiki.proxy());

        this.properties.setProperty("xwiki.authentication.ldap", "1");
        this.properties.setProperty("xwiki.authentication.ldap.server", LDAPTestSetup.LDAP_SERVER);
        this.properties.setProperty("xwiki.authentication.ldap.port", "" + LDAPTestSetup.getLDAPPort());
        this.properties.setProperty("xwiki.authentication.ldap.base_DN", LDAPTestSetup.LDAP_BASEDN);
View Full Code Here

        this.mockGroupService = mock(XWikiGroupService.class, new Class[] {}, new Object[] {});
        this.mockGroupService.stubs().method("getAllGroupsNamesForMember").will(returnValue(Collections.EMPTY_LIST));
        this.mockGroupService.stubs().method("getAllMatchedGroups").will(returnValue(Collections.EMPTY_LIST));

        Mock mockXWiki = mock(XWiki.class, new Class[] {}, new Object[] {});

        mockXWiki.stubs().method("getStore").will(returnValue(mockStore.proxy()));
        mockXWiki.stubs().method("getGroupService").will(returnValue(mockGroupService.proxy()));
        mockXWiki.stubs().method("getCacheFactory").will(returnValue(this.cacheFactory));
        mockXWiki.stubs().method("getXWikiPreference").will(returnValue(null));
        mockXWiki.stubs().method("getXWikiPreferenceAsInt").will(throwException(new NumberFormatException("null")));
        mockXWiki.stubs().method("isVirtualMode").will(returnValue(this.isVirtualMode));
        mockXWiki.stubs().method("getDefaultDocumentSyntax").will(returnValue(Syntax.XWIKI_1_0.toIdString()));
        mockXWiki.stubs().method("Param").will(new CustomStub("Implements XWiki.Param")
        {
            public Object invoke(Invocation invocation) throws Throwable
            {
                return properties.getProperty((String) invocation.parameterValues.get(0));
            }
        });
        mockXWiki.stubs().method("ParamAsLong").will(new CustomStub("Implements XWiki.ParamAsLong")
        {
            public Object invoke(Invocation invocation) throws Throwable
            {
                return Long.parseLong(properties.getProperty((String) invocation.parameterValues.get(0)));
            }
        });
        mockXWiki.stubs().method("getDocument").will(new CustomStub("Implements XWiki.getDocument")
        {
            public Object invoke(Invocation invocation) throws Throwable
            {
                Object document = invocation.parameterValues.get(0);
               
                if (document instanceof String) {
                    return getDocument((String) document);
                } else {
                    return getDocument((DocumentReference) document);
                }
            }
        });
        mockXWiki.stubs().method("saveDocument").will(new CustomStub("Implements XWiki.saveDocument")
        {
            public Object invoke(Invocation invocation) throws Throwable
            {
                saveDocument((XWikiDocument) invocation.parameterValues.get(0));

                return null;
            }
        });
        mockXWiki.stubs().method("exists").will(new CustomStub("Implements XWiki.exists")
        {
            public Object invoke(Invocation invocation) throws Throwable
            {
                return documentExists((String) invocation.parameterValues.get(0));
            }
        });
        mockXWiki.stubs().method("getXClass").will(new CustomStub("Implements XWiki.getClass")
        {
            public Object invoke(Invocation invocation) throws Throwable
            {
                return getDocument(localEntityReferenceSerializer.serialize((EntityReference) invocation.parameterValues.get(0))).getXClass();
            }
        });
        mockXWiki.stubs().method("search").will(returnValue(Collections.EMPTY_LIST));

        this.userClass.setName(USER_XCLASS);
        this.userClass.addTextField("first_name", "First Name", 30);
        this.userClass.addTextField("last_name", "Last Name", 30);
        this.userClass.addTextField("email", "e-Mail", 30);
        this.userClass.addPasswordField("password", "Password", 10);
        this.userClass.addTextField("customproperty", "Custom property", 10);

        mockXWiki.stubs().method("getUserClass").will(returnValue(this.userClass));

        this.groupClass.setName(GROUP_XCLASS);
        this.groupClass.addTextField("member", "Member", 30);

        mockXWiki.stubs().method("getGroupClass").will(returnValue(this.groupClass));

        mockXWiki.stubs().method("createUser").will(new CustomStub("Implements XWiki.createUser")
        {
            public Object invoke(Invocation invocation) throws Throwable
            {
                XWikiDocument document = new XWikiDocument();
                document.setFullName("XWiki." + invocation.parameterValues.get(0));

                BaseObject newobject = new BaseObject();
                newobject.setClassName(userClass.getName());

                userClass.fromMap((Map) invocation.parameterValues.get(1), newobject);

                document.addObject(userClass.getName(), newobject);

                saveDocument(document);

                return 1;
            }
        });

        getContext().setWiki((XWiki) mockXWiki.proxy());

        this.properties.setProperty("xwiki.authentication.ldap", "1");
        this.properties.setProperty("xwiki.authentication.ldap.server", LDAPTestSetup.LDAP_SERVER);
        this.properties.setProperty("xwiki.authentication.ldap.port", "" + LDAPTestSetup.getLDAPPort());
        this.properties.setProperty("xwiki.authentication.ldap.base_DN", LDAPTestSetup.LDAP_BASEDN);
View Full Code Here

    protected void setUp()
        throws Exception
    {
        action = new CreateProjectsFromMetadataAction();
        action.enableLogging( new ConsoleLogger( Logger.LEVEL_DEBUG, "" ) );
        Mock projectBuilderManagerMock = mock( ContinuumProjectBuilderManager.class );
        Mock mavenSettingsBuilderMock = mock( MavenSettingsBuilder.class );
        action.setProjectBuilderManager( (ContinuumProjectBuilderManager) projectBuilderManagerMock.proxy() );
        action.setMavenSettingsBuilder( (MavenSettingsBuilder) mavenSettingsBuilderMock.proxy() );
        action.setUrlValidator( new ContinuumUrlValidator() );
        Mock projectBuilder = mock( ContinuumProjectBuilder.class );

        projectBuilderManagerMock.expects( once() ).method( "getProjectBuilder" ).will(
            returnValue( projectBuilder.proxy() ) );
        projectBuilder.expects( once() ).method( "buildProjectsFromMetadata" ).will(
            returnValue( new ContinuumProjectBuildingResult() ) );

        projectBuilder.expects( once() ).method( "getDefaultBuildDefinitionTemplate" ).will(
            returnValue( getDefaultBuildDefinitionTemplate() ) );

        mavenSettingsBuilderMock.expects( once() ).method( "buildSettings" ).will( returnValue( new Settings() ) );

    }
View Full Code Here

* Test case for ClearSessionInterceptor.
*/
public class ClearSessionInterceptorTest extends StrutsInternalTestCase {

    public void testCreateSession() throws Exception {
        Mock httpServletRequestMock = new Mock(HttpServletRequest.class);

        ClearSessionInterceptor interceptor = new ClearSessionInterceptor();
        MockActionInvocation invocation = new MockActionInvocation();
        ActionContext context = new ActionContext(new HashMap());
        Map session = new HashMap();
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.