Home | History | Annotate | Download | only in annotation
      1 package junitparams.internal.annotation;
      2 
      3 import java.lang.annotation.Annotation;
      4 
      5 import org.junit.runners.model.FrameworkMethod;
      6 
      7 import junitparams.Parameters;
      8 import junitparams.custom.CustomParameters;
      9 
     10 public class FrameworkMethodAnnotations {
     11 
     12     private final FrameworkMethod frameworkMethod;
     13 
     14     public FrameworkMethodAnnotations(FrameworkMethod frameworkMethod) {
     15         this.frameworkMethod = frameworkMethod;
     16     }
     17 
     18     public boolean isParametrised() {
     19         return hasAnnotation(Parameters.class)
     20                 || hasCustomParameters();
     21     }
     22 
     23     public Annotation[] allAnnotations() {
     24         return frameworkMethod.getAnnotations();
     25     }
     26 
     27     public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
     28         return frameworkMethod.getAnnotation(annotationType);
     29     }
     30 
     31     public boolean hasAnnotation(Class<? extends Annotation> annotation) {
     32         return getAnnotation(annotation) != null;
     33     }
     34 
     35     public boolean hasCustomParameters() {
     36         return getCustomParameters() != null;
     37     }
     38 
     39     public CustomParametersDescriptor getCustomParameters() {
     40         CustomParameters customParameters = frameworkMethod.getAnnotation(CustomParameters.class);
     41         if (customParameters != null) {
     42             return new CustomParametersDescriptor(customParameters);
     43         }
     44 
     45         for (Annotation annotation : frameworkMethod.getAnnotations()) {
     46             customParameters = annotation.annotationType().getAnnotation(CustomParameters.class);
     47             if (customParameters != null) {
     48                 return new CustomParametersDescriptor(customParameters, annotation);
     49             }
     50         }
     51         return null;
     52     }
     53 }
     54