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

com.fitbur.mockito.internal.configuration.CaptorAnnotationProcessor Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
/*
 * Copyright (c) 2007 Mockito contributors
 * This program is made available under the terms of the MIT License.
 */
package com.fitbur.mockito.internal.configuration;

import com.fitbur.mockito.ArgumentCaptor;
import com.fitbur.mockito.Captor;
import com.fitbur.mockito.exceptions.base.MockitoException;
import com.fitbur.mockito.internal.util.reflection.GenericMaster;

import java.lang.reflect.Field;

/**
 * Instantiate {@link ArgumentCaptor} a field annotated by @Captor.
 */
public class CaptorAnnotationProcessor implements FieldAnnotationProcessor {
    public Object process(Captor annotation, Field field) {
        Class type = field.getType();
        if (!ArgumentCaptor.class.isAssignableFrom(type)) {
            throw new MockitoException("@Captor field must be of the type ArgumentCaptor.\n" + "Field: '"
               + field.getName() + "' has wrong type\n"
               + "For info how to use @Captor annotations see examples in javadoc for MockitoAnnotations class.");
        }
        Class cls = new GenericMaster().getGenericType(field);
        return ArgumentCaptor.forClass(cls);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy