-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathValidationTextJUnitResultFormatter.java
More file actions
61 lines (48 loc) · 1.68 KB
/
ValidationTextJUnitResultFormatter.java
File metadata and controls
61 lines (48 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package net.sf.webcat.plugins.javatddplugin;
import junit.framework.Test;
import junit.framework.AssertionFailedError;
public class ValidationTextJUnitResultFormatter
extends BasicJUnitResultFormatter {
private static class FormattedThrowable extends Throwable {
private static final long serialVersionUID = 1L;
private final Throwable original;
private final String message;
public FormattedThrowable(String message, Throwable original) {
super(message, original);
this.message = message;
this.original = original;
this.setStackTrace(original.getStackTrace());
}
@Override
public String toString() {
return original.getClass().getName() + ": " + message;
}
}
@Override
public void addError(Test test, Throwable error) {
String msg = formatMessage(error);
Throwable newError = new FormattedThrowable(msg, error);
super.addError(test, newError);
}
@Override
public void addFailure(Test test, AssertionFailedError error) {
String msg = formatMessage(error);
Throwable newFailure = new FormattedThrowable(msg, error);
super.addFailure(test, newFailure);
}
private String formatMessage(Throwable error) {
String customMsg = ValidationMessageFormatter.formatMessage(error);
if (customMsg != null) {
return customMsg;
}
if (error != null) {
if (error.getMessage() != null) {
return error.getMessage();
}
else {
return error.toString();
}
}
return "";
}
}