Package org.mockito.configuration

Examples of org.mockito.configuration.AnnotationEngine


    public static void initMocks(Object testClass) {
        if (testClass == null) {
            throw new MockitoException("testClass cannot be null. For info how to use @Mock annotations see examples in javadoc for MockitoAnnotations class");
        }

        AnnotationEngine annotationEngine = new GlobalConfiguration().getAnnotationEngine();
        Class<?> clazz = testClass.getClass();

        //below can be removed later, when we get read rid of deprecated stuff
        if (annotationEngine.getClass() != new DefaultMockitoConfiguration().getAnnotationEngine().getClass()) {
            //this means user has his own annotation engine and we have to respect that.
            //we will do annotation processing the old way so that we are backwards compatible
            while (clazz != Object.class) {
                scanDeprecatedWay(annotationEngine, testClass, clazz);
                clazz = clazz.getSuperclass();
            }
        }

        //anyway act 'the new' way
        annotationEngine.process(testClass.getClass(), testClass);
    }
View Full Code Here


            clazz = clazz.getSuperclass();
        }
    }

    static void scan(Object testClass, Class<?> clazz) {
        AnnotationEngine annotationEngine = new GlobalConfiguration().getAnnotationEngine();
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            if (annotationEngine.getClass() != new DefaultMockitoConfiguration().getAnnotationEngine().getClass()) {
                //this means user has his own annotation engine and we have to respect that.
                //we will do annotation processing the old way so that we are backwards compatible
                processAnnotationDeprecatedWay(annotationEngine, testClass, field);               
            }
            //act 'the new' way
            annotationEngine.process(clazz, testClass);
        }
    }
View Full Code Here

    class Dependency {}
   
    @Test
    public void shouldInjectMocksIfThereIsNoUserDefinedEngine() throws Exception {
        //given
        AnnotationEngine defaultEngine = new DefaultMockitoConfiguration().getAnnotationEngine();
        ConfigurationAccess.getConfig().overrideAnnotationEngine(defaultEngine);
        SimpleTestCase test = new SimpleTestCase();
       
        //when
        MockitoAnnotations.initMocks(test);
View Full Code Here

    }
   
    @Test
    public void shouldRespectUsersEngine() throws Exception {
        //given
        AnnotationEngine customizedEngine = new DefaultAnnotationEngine() { /**/ };
        ConfigurationAccess.getConfig().overrideAnnotationEngine(customizedEngine);
        SimpleTestCase test = new SimpleTestCase();
       
        //when
        MockitoAnnotations.initMocks(test);
View Full Code Here

    public static void initMocks(Object testClass) {
        if (testClass == null) {
            throw new MockitoException("testClass cannot be null. For info how to use @Mock annotations see examples in javadoc for MockitoAnnotations class");
        }

        AnnotationEngine annotationEngine = new GlobalConfiguration().getAnnotationEngine();
        Class<?> clazz = testClass.getClass();

        //below can be removed later, when we get read rid of deprecated stuff
        if (annotationEngine.getClass() != new DefaultMockitoConfiguration().getAnnotationEngine().getClass()) {
            //this means user has his own annotation engine and we have to respect that.
            //we will do annotation processing the old way so that we are backwards compatible
            while (clazz != Object.class) {
                scanDeprecatedWay(annotationEngine, testClass, clazz);
                clazz = clazz.getSuperclass();
            }
        }

        //anyway act 'the new' way
        annotationEngine.process(testClass.getClass(), testClass);
    }
View Full Code Here

            clazz = clazz.getSuperclass();
        }
    }

    private static void scan(Object testClass, Class<?> clazz) {
        AnnotationEngine annotationEngine = new GlobalConfiguration().getAnnotationEngine();
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            for(Annotation annotation : field.getAnnotations()) {
                Object mock = annotationEngine.createMockFor(annotation, field);
                if (mock != null) {
                    boolean wasAccessible = field.isAccessible();
                    field.setAccessible(true);
                    try {
                        field.set(testClass, mock);
View Full Code Here

            clazz = clazz.getSuperclass();
        }
    }

    private static void scan(Object testClass, Class<?> clazz) {
        AnnotationEngine annotationEngine = new GlobalConfiguration().getAnnotationEngine();
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            for(Annotation annotation : field.getAnnotations()) {
                Object mock = annotationEngine.createMockFor(annotation, field);
                if (mock != null) {
                    boolean wasAccessible = field.isAccessible();
                    field.setAccessible(true);
                    try {
                        field.set(testClass, mock);
View Full Code Here

            clazz = clazz.getSuperclass();
        }
    }

    static void scan(Object testClass, Class<?> clazz) {
        AnnotationEngine annotationEngine = new GlobalConfiguration().getAnnotationEngine();
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            //below can be removed later, when we get rid of deprecated stuff
            if (annotationEngine.getClass() != new DefaultMockitoConfiguration().getAnnotationEngine().getClass()) {
                //this means user has his own annotation engine and we have to respect that.
                //we will do annotation processing the old way so that we are backwards compatible
                processAnnotationDeprecatedWay(annotationEngine, testClass, field);               
            }
        }
        //act 'the new' way
        annotationEngine.process(clazz, testClass);
    }
View Full Code Here

TOP

Related Classes of org.mockito.configuration.AnnotationEngine

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.