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

junitparams.internal.annotation.FrameworkMethodAnnotations Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package junitparams.internal.annotation;

import java.lang.annotation.Annotation;

import org.junit.runners.model.FrameworkMethod;

import junitparams.Parameters;
import junitparams.custom.CustomParameters;

public class FrameworkMethodAnnotations {

    private final FrameworkMethod frameworkMethod;

    public FrameworkMethodAnnotations(FrameworkMethod frameworkMethod) {
        this.frameworkMethod = frameworkMethod;
    }

    public boolean isParametrised() {
        return hasAnnotation(Parameters.class)
                || hasCustomParameters();
    }

    public Annotation[] allAnnotations() {
        return frameworkMethod.getAnnotations();
    }

    public  T getAnnotation(Class annotationType) {
        return frameworkMethod.getAnnotation(annotationType);
    }

    public boolean hasAnnotation(Class annotation) {
        return getAnnotation(annotation) != null;
    }

    public boolean hasCustomParameters() {
        return getCustomParameters() != null;
    }

    public CustomParametersDescriptor getCustomParameters() {
        CustomParameters customParameters = frameworkMethod.getAnnotation(CustomParameters.class);
        if (customParameters != null) {
            return new CustomParametersDescriptor(customParameters);
        }

        for (Annotation annotation : frameworkMethod.getAnnotations()) {
            customParameters = annotation.annotationType().getAnnotation(CustomParameters.class);
            if (customParameters != null) {
                return new CustomParametersDescriptor(customParameters, annotation);
            }
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy