001 package org.junit.runner;
002
003 import static java.util.Collections.emptyList;
004 import static java.util.Collections.singletonList;
005
006 import java.util.List;
007
008 import org.junit.FixMethodOrder;
009 import org.junit.runners.model.TestClass;
010 import org.junit.validator.AnnotationValidator;
011
012 /**
013 * Validates that there are no errors in the use of the {@code OrderWith}
014 * annotation. If there is, a {@code Throwable} object will be added to the list
015 * of errors.
016 *
017 * @since 4.13
018 */
019 public final class OrderWithValidator extends AnnotationValidator {
020
021 /**
022 * Adds to {@code errors} a throwable for each problem detected. Looks for
023 * {@code FixMethodOrder} annotations.
024 *
025 * @param testClass that is being validated
026 * @return A list of exceptions detected
027 *
028 * @since 4.13
029 */
030 @Override
031 public List<Exception> validateAnnotatedClass(TestClass testClass) {
032 if (testClass.getAnnotation(FixMethodOrder.class) != null) {
033 return singletonList(
034 new Exception("@FixMethodOrder cannot be combined with @OrderWith"));
035 }
036 return emptyList();
037 }
038 }