01: package org.bouncycastle.util.test;
02:
03: public class SimpleTestResult implements TestResult {
04: private static final String SEPARATOR = System
05: .getProperty("line.separator");
06:
07: private boolean success;
08: private String message;
09: private Throwable exception;
10:
11: public SimpleTestResult(boolean success, String message) {
12: this .success = success;
13: this .message = message;
14: }
15:
16: public SimpleTestResult(boolean success, String message,
17: Throwable exception) {
18: this .success = success;
19: this .message = message;
20: this .exception = exception;
21: }
22:
23: public static TestResult successful(Test test, String message) {
24: return new SimpleTestResult(true, test.getName() + ": "
25: + message);
26: }
27:
28: public static TestResult failed(Test test, String message) {
29: return new SimpleTestResult(false, test.getName() + ": "
30: + message);
31: }
32:
33: public static TestResult failed(Test test, String message,
34: Throwable t) {
35: return new SimpleTestResult(false, test.getName() + ": "
36: + message, t);
37: }
38:
39: public static TestResult failed(Test test, String message,
40: Object expected, Object found) {
41: return failed(test, message + SEPARATOR + "Expected: "
42: + expected + SEPARATOR + "Found : " + found);
43: }
44:
45: public static String failedMessage(String algorithm,
46: String testName, String expected, String actual) {
47: StringBuffer sb = new StringBuffer(algorithm);
48: sb.append(" failing ").append(testName);
49: sb.append(SEPARATOR).append(" expected: ").append(expected);
50: sb.append(SEPARATOR).append(" got : ").append(actual);
51:
52: return sb.toString();
53: }
54:
55: public boolean isSuccessful() {
56: return success;
57: }
58:
59: public String toString() {
60: return message;
61: }
62:
63: public Throwable getException() {
64: return exception;
65: }
66: }
|