• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.junit.validator;
2 
3 import org.junit.runners.model.FrameworkField;
4 import org.junit.runners.model.FrameworkMethod;
5 import org.junit.runners.model.TestClass;
6 
7 import static java.util.Collections.emptyList;
8 
9 import java.util.List;
10 
11 /**
12  * Validates annotations on classes and methods. To be validated,
13  * an annotation should be annotated with {@link ValidateWith}
14  *
15  * Instances of this class are shared by multiple test runners, so they should
16  * be immutable and thread-safe.
17  *
18  * @since 4.12
19  */
20 public abstract class AnnotationValidator {
21 
22     private static final List<Exception> NO_VALIDATION_ERRORS = emptyList();
23 
24     /**
25      * Validates annotation on the given class.
26      *
27      * @param testClass that is being validated
28      * @return A list of exceptions. Default behavior is to return an empty list.
29      *
30      * @since 4.12
31      */
validateAnnotatedClass(TestClass testClass)32     public List<Exception> validateAnnotatedClass(TestClass testClass) {
33         return NO_VALIDATION_ERRORS;
34     }
35 
36     /**
37      * Validates annotation on the given field.
38      *
39      * @param field that is being validated
40      * @return A list of exceptions. Default behavior is to return an empty list.
41      *
42      * @since 4.12
43      */
validateAnnotatedField(FrameworkField field)44     public List<Exception> validateAnnotatedField(FrameworkField field) {
45         return NO_VALIDATION_ERRORS;
46 
47     }
48 
49     /**
50      * Validates annotation on the given method.
51      *
52      * @param method that is being validated
53      * @return A list of exceptions. Default behavior is to return an empty list.
54      *
55      * @since 4.12
56      */
validateAnnotatedMethod(FrameworkMethod method)57     public List<Exception> validateAnnotatedMethod(FrameworkMethod method) {
58         return NO_VALIDATION_ERRORS;
59     }
60 }
61