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

org.mockito.configuration.MockitoConfiguration Maven / Gradle / Ivy

There is a newer version: 0.63
Show newest version
package org.mockito.configuration;

import com.googlecode.gwt.test.Mock;
import org.mockito.ReturnValues;
import org.mockito.exceptions.Reporter;
import org.mockito.stubbing.Answer;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

/**
 * Custom Mockito configuration which relies on a custom AnnotationEngine to be able to mock GWT
 * overlay types and to support {@link Mock} annotation as well as Mockito's ones.
 *
 * @author Gael Lazzari
 * @see GwtInjectingAnnotationEngine
 */
@SuppressWarnings("deprecation")
public class MockitoConfiguration implements IMockitoConfiguration {

    @SuppressWarnings({"unchecked", "rawtypes"})
    static void assertNoAnnotations(Class annotation, Field field,
                                    Class... undesiredAnnotations) {

        for (Class undesiredAnnotation : undesiredAnnotations) {
            if (field.isAnnotationPresent(undesiredAnnotation)) {
                new Reporter().unsupportedCombinationOfAnnotations(undesiredAnnotation.getSimpleName(),
                        annotation.getSimpleName());
            }
        }
    }

    private final IMockitoConfiguration delegate = new DefaultMockitoConfiguration();

    public boolean cleansStackTrace() {
        return delegate.cleansStackTrace();
    }

    public boolean enableClassCache() {
        return delegate.enableClassCache();
    }

    public AnnotationEngine getAnnotationEngine() {
        return AnnotationEngineHolder.getAnnotationEngine();
    }

    public Answer getDefaultAnswer() {
        return delegate.getDefaultAnswer();
    }

    public ReturnValues getReturnValues() {
        return delegate.getReturnValues();
    }

}