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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
package org.bouncycastle.util.test;
public class SimpleTestResult implements TestResult
{
private static final String SEPARATOR = System.getProperty("line.separator");
private boolean success;
private String message;
private Throwable exception;
public SimpleTestResult(boolean success, String message)
{
this.success = success;
this.message = message;
}
public SimpleTestResult(boolean success, String message, Throwable exception)
{
this.success = success;
this.message = message;
this.exception = exception;
}
public static TestResult successful(
Test test,
String message)
{
return new SimpleTestResult(true, test.getName() + ": " + message);
}
public static TestResult failed(
Test test,
String message)
{
return new SimpleTestResult(false, test.getName() + ": " + message);
}
public static TestResult failed(
Test test,
String message,
Throwable t)
{
return new SimpleTestResult(false, test.getName() + ": " + message, t);
}
public static TestResult failed(
Test test,
String message,
Object expected,
Object found)
{
return failed(test, message + SEPARATOR + "Expected: " + expected + SEPARATOR + "Found : " + found);
}
public static String failedMessage(String algorithm, String testName, String expected,
String actual)
{
StringBuffer sb = new StringBuffer(algorithm);
sb.append(" failing ").append(testName);
sb.append(SEPARATOR).append(" expected: ").append(expected);
sb.append(SEPARATOR).append(" got : ").append(actual);
return sb.toString();
}
public boolean isSuccessful()
{
return success;
}
public String toString()
{
return message;
}
public Throwable getException()
{
return exception;
}
}
|