1 package org.junit.runner; 2 3 import static java.util.Collections.emptyList; 4 import static java.util.Collections.singletonList; 5 6 import java.util.List; 7 8 import org.junit.FixMethodOrder; 9 import org.junit.runners.model.TestClass; 10 import org.junit.validator.AnnotationValidator; 11 12 /** 13 * Validates that there are no errors in the use of the {@code OrderWith} 14 * annotation. If there is, a {@code Throwable} object will be added to the list 15 * of errors. 16 * 17 * @since 4.13 18 */ 19 public final class OrderWithValidator extends AnnotationValidator { 20 21 /** 22 * Adds to {@code errors} a throwable for each problem detected. Looks for 23 * {@code FixMethodOrder} annotations. 24 * 25 * @param testClass that is being validated 26 * @return A list of exceptions detected 27 * 28 * @since 4.13 29 */ 30 @Override validateAnnotatedClass(TestClass testClass)31 public List<Exception> validateAnnotatedClass(TestClass testClass) { 32 if (testClass.getAnnotation(FixMethodOrder.class) != null) { 33 return singletonList( 34 new Exception("@FixMethodOrder cannot be combined with @OrderWith")); 35 } 36 return emptyList(); 37 } 38 } 39