1 package org.junit.runners.model;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.List;
6
7 import org.junit.internal.Throwables;
8
9
10
11
12
13
14 public class MultipleFailureException extends Exception {
15 private static final long serialVersionUID = 1L;
16
17
18
19
20
21
22 private final List<Throwable> fErrors;
23
24 public MultipleFailureException(List<Throwable> errors) {
25 this.fErrors = new ArrayList<Throwable>(errors);
26 }
27
28 public List<Throwable> getFailures() {
29 return Collections.unmodifiableList(fErrors);
30 }
31
32 @Override
33 public String getMessage() {
34 StringBuilder sb = new StringBuilder(
35 String.format("There were %d errors:", fErrors.size()));
36 for (Throwable e : fErrors) {
37 sb.append(String.format("\n %s(%s)", e.getClass().getName(), e.getMessage()));
38 }
39 return sb.toString();
40 }
41
42
43
44
45
46
47
48
49
50
51 @SuppressWarnings("deprecation")
52 public static void assertEmpty(List<Throwable> errors) throws Exception {
53 if (errors.isEmpty()) {
54 return;
55 }
56 if (errors.size() == 1) {
57 throw Throwables.rethrowAsException(errors.get(0));
58 }
59
60
61
62
63
64
65
66
67 throw new org.junit.internal.runners.model.MultipleFailureException(errors);
68 }
69 }