Package org.easymock

Examples of org.easymock.ConstructorArgs


        Enhancer.registerCallbacks(mockClass, new Callback[] { interceptor });

        if (ClassExtensionHelper.getCurrentConstructorArgs() != null) {
            // Really instantiate the class
            final ConstructorArgs args = ClassExtensionHelper.getCurrentConstructorArgs();
            Constructor cstr;
            try {
                // Get the constructor with the same params
                cstr = mockClass.getDeclaredConstructor(args.getConstructor().getParameterTypes());
            } catch (final NoSuchMethodException e) {
                // Shouldn't happen, constructor is checked when ConstructorArgs is instantiated
                // ///CLOVER:OFF
                throw new RuntimeException("Fail to find constructor for param types", e);
                // ///CLOVER:ON
            }
            T mock;
            try {
                cstr.setAccessible(true); // So we can call a protected
                // constructor
                mock = (T) cstr.newInstance(args.getInitArgs());
            } catch (final InstantiationException e) {
                // ///CLOVER:OFF
                throw new RuntimeException("Failed to instantiate mock calling constructor", e);
                // ///CLOVER:ON
            } catch (final IllegalAccessException e) {
View Full Code Here


        }
    }

    @Test
    public void testConstructorArgs() {
        final ConstructorArgs args = new ConstructorArgs(A.class.getConstructors()[0], "a", 4);
        checkArgs(args);
    }
View Full Code Here

        assertEquals(A.class.getConstructors()[0], args.getConstructor());
    }

    @Test(expected = IllegalArgumentException.class)
    public void testConstructorArgs_WrongArgument() {
        new ConstructorArgs(A.class.getConstructors()[0], "a", "b");
    }
View Full Code Here

        new ConstructorArgs(A.class.getConstructors()[0], "a", "b");
    }

    @Test(expected = IllegalArgumentException.class)
    public void testConstructorArgs_NullPrimitive() {
        new ConstructorArgs(A.class.getConstructors()[0], "a", null);
    }
View Full Code Here

        new ConstructorArgs(A.class.getConstructors()[0], "a", null);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testConstructorArgs_PrimitiveForObject() {
        new ConstructorArgs(A.class.getConstructors()[0], 1, 2);
    }
View Full Code Here

        new ConstructorArgs(A.class.getConstructors()[0], 1, 2);
    }

    @Test
    public void testConstructorArgs_NullObject() {
        new ConstructorArgs(A.class.getConstructors()[0], null, 2);
    }
View Full Code Here

        new ConstructorArgs(A.class.getConstructors()[0], null, 2);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testConstructorArgs_WrongPrimitive() {
        new ConstructorArgs(A.class.getConstructors()[0], "a", 2.0f);
    }
View Full Code Here

        new ConstructorArgs(A.class.getConstructors()[0], "a", 2.0f);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testConstructorArgs_WrongNumberOfArgs() {
        new ConstructorArgs(A.class.getConstructors()[0], "a");
    }
View Full Code Here

        new ConstructorArgs(A.class.getConstructors()[0], "a");
    }

    @Test(expected = IllegalArgumentException.class)
    public void testConstructorArgs_TypeExistsButPrivate() {
        new ConstructorArgs(A.class.getConstructors()[0], "a", new A(null, 1));
    }
View Full Code Here

        new ConstructorArgs(A.class.getConstructors()[0], "a", new A(null, 1));
    }

    @Test(expected = IllegalArgumentException.class)
    public void testConstructorArgs_TypeExistsButNotStatic() {
        new ConstructorArgs(A.class.getConstructors()[0], "a", new ConstructorArgsTest());
    }
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.