    001    package org.junit.validator;
    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.runners.model.TestClass;
    009
    010    /**
    011     * Validates that a {@link TestClass} is public.
    012     *
    013     * @since 4.12
    014     */
    015    public class PublicClassValidator implements TestClassValidator {
    016        private static final List<Exception> NO_VALIDATION_ERRORS = emptyList();
    017
    018        /**
    019         * Validate that the specified {@link TestClass} is public.
    020         *
    021         * @param testClass the {@link TestClass} that is validated.
    022         * @return an empty list if the class is public or a list with a single
    023         *         exception otherwise.
    024         */
    025        public List<Exception> validateTestClass(TestClass testClass) {
    026            if (testClass.isPublic()) {
    027                return NO_VALIDATION_ERRORS;
    028            } else {
    029                return singletonList(new Exception("The class "
    030                        + testClass.getName() + " is not public."));
    031            }
    032        }
    033    }