Package org.easymock

Examples of org.easymock.ConstructorArgs


    private ConstructorArgs args;

    @Before
    public void setUp() throws Exception {
        foo = ToMock.class.getMethod("foo");
        args = new ConstructorArgs(ToMock.class.getConstructor());
    }
View Full Code Here


    }

    @Test(expected = RuntimeException.class)
    public void testPartialMock_ConstructorNotFound() throws Exception {
        final Constructor<?> cstr = ArrayList.class.getConstructor(Integer.TYPE);
        final ConstructorArgs constructorArgs = new ConstructorArgs(cstr, 2.0);
        try {
            createMockBuilder(ArrayList.class).withConstructor(Integer.TYPE).withArgs(2.0).createMock();
        } catch (final RuntimeException e) {
            assertEquals("Failed to find constructor for param types", e.getMessage());
            throw e;
View Full Code Here

    }

    @Test(expected = IllegalArgumentException.class)
    public void testPartialMock_InvalidParams() throws Exception {
        final Constructor<?> cstr = ArrayList.class.getConstructor(Integer.TYPE);
        final ConstructorArgs constructorArgs = new ConstructorArgs(cstr, "test");
        createMockBuilder(ArrayList.class).withConstructor(Integer.TYPE).withArgs("test");
    }
View Full Code Here

    }

    @Test(expected = RuntimeException.class)
    public void testPartialMock_ExceptionInConstructor() throws Exception {
        final Constructor<?> cstr = ArrayList.class.getConstructor(Integer.TYPE);
        final ConstructorArgs constructorArgs = new ConstructorArgs(cstr, -5);
        try {
            createMockBuilder(ArrayList.class).withConstructor(-5).createMock();
        } catch (final RuntimeException e) {
            assertEquals("Failed to instantiate mock calling constructor: Exception in constructor", e
                    .getMessage());
View Full Code Here

    @SuppressWarnings("deprecation")
    @Test
    public void testMocksControl_PartialMock_ConstructorCalled() throws Exception {
        final IMocksControl ctrl = createControl();

        final ConstructorArgs args = new ConstructorArgs(A.class.getConstructor(Integer.TYPE), 6);

        final A a = ctrl.createMock(A.class, args, A.class.getMethod("bar", new Class[0]), A.class.getMethod(
                "toString", new Class[0]));

        assertEquals("Constructor called so should be initialized", 6, a.i);
View Full Code Here

    @SuppressWarnings("deprecation")
    @Test
    public void testMocksControl_NamedPartialMock_ConstructorCalled() throws Exception {
        final IMocksControl ctrl = createControl();

        final ConstructorArgs args = new ConstructorArgs(A.class.getConstructor(Integer.TYPE), 6);

        final A a = ctrl.createMock("myMock", A.class, args, A.class.getMethod("bar", new Class[0]), A.class
                .getMethod("toString", new Class[0]));

        assertEquals("Constructor called so should be initialized", 6, a.i);
View Full Code Here

    }

    @SuppressWarnings("deprecation")
    @Test
    public void testInterfaceForbidden_PartialMock() throws Exception {
        final ConstructorArgs args = new ConstructorArgs(ArrayList.class.getConstructor(Integer.TYPE), 6);
        final Method[] methods = new Method[] { List.class.getMethod("size", new Class[0]) };

        final IMocksControl ctrl = createControl();

        try {
View Full Code Here

        builder.withConstructor(int.class).withConstructor(int.class);
    }

    @Test
    public void testWithConstructorConstructorArgs() throws NoSuchMethodException {
        final ConstructorArgs args = new ConstructorArgs(ArrayList.class.getConstructor(int.class), Integer
                .valueOf(-3));
        builder.withConstructor(args);
        try {
            builder.createMock();
            fail("instantiation should fail because of negative");
View Full Code Here

     *            certain constructor.
     * @return the mock object.
     */
    public static <T> T createMock(Class<T> type, Object... constructorArguments) {
        Constructor<?> constructor = WhiteboxImpl.findUniqueConstructorOrThrowException(type, constructorArguments);
        ConstructorArgs constructorArgs = new ConstructorArgs(constructor, constructorArguments);
        return doMock(type, false, new DefaultMockStrategy(), constructorArgs, (Method[]) null);
    }
View Full Code Here

     *            certain constructor.
     * @return the mock object.
     */
    public static <T> T createStrictMock(Class<T> type, Object... constructorArguments) {
        Constructor<?> constructor = WhiteboxImpl.findUniqueConstructorOrThrowException(type, constructorArguments);
        ConstructorArgs constructorArgs = new ConstructorArgs(constructor, constructorArguments);
        return doMock(type, false, new StrictMockStrategy(), constructorArgs, (Method[]) null);
    }
View Full Code Here

TOP

Related Classes of org.easymock.ConstructorArgs

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.