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 81 82 83 84
|
package org.bouncycastle.util.test;
import java.io.PrintStream;
import org.bouncycastle.util.Arrays;
public abstract class SimpleTest
implements Test
{
public abstract String getName();
private TestResult success()
{
return SimpleTestResult.successful(this, "Okay");
}
protected void fail(
String message)
{
throw new TestFailedException(SimpleTestResult.failed(this, message));
}
protected void fail(
String message,
Throwable throwable)
{
throw new TestFailedException(SimpleTestResult.failed(this, message, throwable));
}
protected void fail(
String message,
Object expected,
Object found)
{
throw new TestFailedException(SimpleTestResult.failed(this, message, expected, found));
}
protected boolean areEqual(
byte[] a,
byte[] b)
{
return Arrays.areEqual(a, b);
}
public TestResult perform()
{
try
{
performTest();
return success();
}
catch (TestFailedException e)
{
return e.getResult();
}
catch (Exception e)
{
return SimpleTestResult.failed(this, "Exception: " + e, e);
}
}
protected static void runTest(
Test test)
{
runTest(test, System.out);
}
protected static void runTest(
Test test,
PrintStream out)
{
TestResult result = test.perform();
out.println(result.toString());
if (result.getException() != null)
{
result.getException().printStackTrace(out);
}
}
public abstract void performTest()
throws Exception;
}
|