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

org.mockito.internal.configuration.CaptorAnnotationProcessor Maven / Gradle / Ivy

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

import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.exceptions.base.MockitoException;
import org.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