1 package junitparams.converters; 2 3 import java.lang.annotation.Annotation; 4 5 public class ParamAnnotation { 6 matches(Annotation annotation)7 public static boolean matches(Annotation annotation) { 8 return getParam(annotation) != null; 9 } 10 convert(Annotation annotation, Object param)11 public static Object convert(Annotation annotation, Object param) throws ConversionFailedException { 12 return converter(annotation).convert(param); 13 } 14 getParam(Annotation annotation)15 private static Param getParam(Annotation annotation) { 16 if (annotation.annotationType().isAssignableFrom(Param.class)) { 17 return (Param) annotation; 18 } 19 return annotation.annotationType().getAnnotation(Param.class); 20 } 21 converter(Annotation annotation)22 private static Converter converter(Annotation annotation) { 23 Converter converter = null; 24 try { 25 converter = getParam(annotation).converter().newInstance(); 26 } catch (Exception e) { 27 throw new RuntimeException("Your Converter class must have a public no-arg constructor!", e); 28 } 29 converter.initialize(annotation); 30 return converter; 31 } 32 } 33