001package org.junit.runners.model;
002
003import java.util.List;
004
005/**
006 * Thrown by {@link org.junit.runner.Runner}s in case the class under test is not valid.
007 * <p>
008 * Its message conveniently lists all of the validation errors.
009 *
010 * @since 4.13
011 */
012public class InvalidTestClassError extends InitializationError {
013    private static final long serialVersionUID = 1L;
014
015    private final String message;
016
017    public InvalidTestClassError(Class<?> offendingTestClass, List<Throwable> validationErrors) {
018        super(validationErrors);
019        this.message = createMessage(offendingTestClass, validationErrors);
020    }
021
022    private static String createMessage(Class<?> testClass, List<Throwable> validationErrors) {
023        StringBuilder sb = new StringBuilder();
024        sb.append(String.format("Invalid test class '%s':", testClass.getName()));
025        int i = 1;
026        for (Throwable error : validationErrors) {
027            sb.append("\n  " + (i++) + ". " + error.getMessage());
028        }
029        return sb.toString();
030    }
031
032    /**
033     * @return a message with a list of all of the validation errors
034     */
035    @Override
036    public String getMessage() {
037        return message;
038    }
039}