1 package org.junit.validator; 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.runners.model.TestClass; 9 10 /** 11 * Validates that a {@link TestClass} is public. 12 * 13 * @since 4.12 14 */ 15 public class PublicClassValidator implements TestClassValidator { 16 private static final List<Exception> NO_VALIDATION_ERRORS = emptyList(); 17 18 /** 19 * Validate that the specified {@link TestClass} is public. 20 * 21 * @param testClass the {@link TestClass} that is validated. 22 * @return an empty list if the class is public or a list with a single 23 * exception otherwise. 24 */ validateTestClass(TestClass testClass)25 public List<Exception> validateTestClass(TestClass testClass) { 26 if (testClass.isPublic()) { 27 return NO_VALIDATION_ERRORS; 28 } else { 29 return singletonList(new Exception("The class " 30 + testClass.getName() + " is not public.")); 31 } 32 } 33 } 34