001package org.junit.runner;
002
003import static java.util.Collections.emptyList;
004import static java.util.Collections.singletonList;
005
006import java.util.List;
007
008import org.junit.FixMethodOrder;
009import org.junit.runners.model.TestClass;
010import 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 */
019public 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}