All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kubek2k.springockito.annotations.DesiredMockitoBeansFinder Maven / Gradle / Ivy

There is a newer version: 1.0.9
Show newest version
package org.kubek2k.springockito.annotations;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

class DesiredMockitoBeansFinder {
    public Map> findMockedBeans(Class clazz) {
        return findAnnotatedFieldsTypes(clazz.getDeclaredFields(), ReplaceWithMock.class);
    }

    public Set findSpiedBeans(Class clazz) {
        return findAnnotatedFieldsTypes(clazz.getDeclaredFields(), WrapWithSpy.class).keySet();
    }

    private Map> findAnnotatedFieldsTypes(Field[] fieldsToScan, Class annotationClass) {
        Map> mockedBeans = new HashMap>();
        for (Field field : fieldsToScan) {
            if (field.getAnnotation(annotationClass) != null) {
                mockedBeans.put(field.getName(), field.getType());
            }
        }
        return mockedBeans;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy