Package org.jmock.core

Examples of org.jmock.core.CoreMock


     *
     * We only use CGLIB if we have to.
     */
    private static DynamicMock dynamicMockFor(Class type, String name) {
        if (type.isInterface()) {
            return new CoreMock(type, name);
        }
        else {
            return new CGLIBCoreMock(type, name);
        }
    }
View Full Code Here


    public Mock( Class mockedType ) {
        this(mockedType, CoreMock.mockNameFromClass(mockedType));
    }

    public Mock( Class mockedType, String name ) {
        this(new CoreMock(mockedType, name));
    }
View Full Code Here

        if (resultValuesByType.containsKey(returnType)) {
            return resultValuesByType.get(returnType);
        } else if (returnType.isArray()) {
            return Array.newInstance(returnType.getComponentType(), 0);
        } else if (returnType.isInterface()) {
            CoreMock nullMock = new CoreMock(returnType, "null" + Formatting.classShortName(returnType));
            nullMock.setDefaultStub(this);
            return nullMock.proxy();
        } else {
            throw new AssertionFailedError(createErrorMessage(invocation));
        }
    }
View Full Code Here

    public static Object newDummy( Class interfaceClass ) {
        return newDummy(interfaceClass, "dummy" + Formatting.classShortName(interfaceClass));
    }

    public static Object newDummy( final Class interfaceClass, final String name ) {
        CoreMock mock = new CoreMock(interfaceClass, name);
        InvocationMocker mocker = new InvocationMocker();

        mocker.addMatcher(new StatelessInvocationMatcher()
        {
            public boolean matches( Invocation invocation ) {
                return invocation.invokedMethod.getDeclaringClass() == interfaceClass;
            }

            public StringBuffer describeTo( StringBuffer buf ) {
                return buf.append("any invokedMethod declared in " + interfaceClass);
            }
        });
        mocker.setStub(new CustomStub("dummy invokedMethod")
        {
            public Object invoke( Invocation invocation ) throws Throwable {
                throw new NotImplementedException(invocation.invokedMethod.getName() + " called on " + name);
            }
        });

        mock.addInvokable(mocker);

        return mock.proxy();
    }
View Full Code Here

    public static Object newDummy( Class interfaceClass ) {
        return newDummy(interfaceClass, "dummy" + Formatting.classShortName(interfaceClass));
    }

    public static Object newDummy( final Class interfaceClass, final String name ) {
        CoreMock mock = new CoreMock(interfaceClass, name);
        InvocationMocker mocker = new InvocationMocker();

        mocker.addMatcher(new StatelessInvocationMatcher()
        {
            public boolean matches( Invocation invocation ) {
                return invocation.invokedMethod.getDeclaringClass() == interfaceClass;
            }

            public StringBuffer describeTo( StringBuffer buf ) {
                return buf.append("any invokedMethod declared in " + interfaceClass);
            }
        });
        mocker.setStub(new CustomStub("dummy invokedMethod")
        {
            public Object invoke( Invocation invocation ) throws Throwable {
                throw new NotImplementedException(invocation.invokedMethod.getName() + " called on " + name);
            }
        });

        mock.addInvokable(mocker);

        return mock.proxy();
    }
View Full Code Here

        registerToVerify(newMock);
        return newMock;
    }
   
    protected DynamicMock newCoreMock( Class mockedType, String roleName ) {
        return new CoreMock(mockedType, roleName);
    }
View Full Code Here

TOP

Related Classes of org.jmock.core.CoreMock

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.