|
20 | 20 | import org.junit.platform.commons.JUnitException;
|
21 | 21 | import org.junit.platform.commons.util.Preconditions;
|
22 | 22 | import org.junit.platform.engine.DiscoveryIssue;
|
| 23 | +import org.junit.platform.engine.support.descriptor.ClassSource; |
| 24 | +import org.junit.platform.engine.support.descriptor.MethodSource; |
23 | 25 |
|
24 | 26 | class DiscoveryIssueException extends JUnitException {
|
25 | 27 |
|
@@ -47,15 +49,31 @@ public String getMessage() {
|
47 | 49 | StringBuilder message = new StringBuilder(super.getMessage());
|
48 | 50 | if (issues != null) { // after deserialization
|
49 | 51 | message.append(":");
|
50 |
| - for (DiscoveryIssue issue : issues) { |
51 |
| - message.append("\n- [").append(issue.severity()).append("] ").append(issue.message()); |
52 |
| - issue.source().ifPresent(s -> message.append(" at ").append(s).append("]")); |
53 |
| - issue.cause().ifPresent(t -> message.append("\n Caused by: ").append(getStackTrace(t))); |
| 52 | + for (int i = 0; i < issues.size(); i++) { |
| 53 | + DiscoveryIssue issue = issues.get(i); |
| 54 | + message.append("\n\n(").append(i + 1).append(") [").append(issue.severity()).append("] ").append( |
| 55 | + issue.message()); |
| 56 | + issue.source().ifPresent(source -> { |
| 57 | + message.append("\n Source: ").append(source); |
| 58 | + if (source instanceof MethodSource) { |
| 59 | + MethodSource methodSource = (MethodSource) source; |
| 60 | + appendIdeCompatibleLink(message, methodSource.getClassName(), methodSource.getMethodName()); |
| 61 | + } |
| 62 | + else if (source instanceof ClassSource) { |
| 63 | + ClassSource classSource = (ClassSource) source; |
| 64 | + appendIdeCompatibleLink(message, classSource.getClassName(), "<no-method>"); |
| 65 | + } |
| 66 | + }); |
| 67 | + issue.cause().ifPresent(t -> message.append("\n Cause: ").append(getStackTrace(t))); |
54 | 68 | }
|
55 | 69 | }
|
56 | 70 | return message.toString();
|
57 | 71 | }
|
58 | 72 |
|
| 73 | + private static void appendIdeCompatibleLink(StringBuilder message, String className, String methodName) { |
| 74 | + message.append("\n at ").append(className).append(".").append(methodName).append("(SourceFile:0)"); |
| 75 | + } |
| 76 | + |
59 | 77 | private static String getStackTrace(Throwable cause) {
|
60 | 78 | StringWriter stringWriter = new StringWriter();
|
61 | 79 | try (PrintWriter writer = new PrintWriter(stringWriter, true)) {
|
|
0 commit comments