diff options
author | Roberto Tyley <roberto.tyley@gmail.com> | 2014-07-15 01:38:01 +0400 |
---|---|---|
committer | Roberto Tyley <roberto.tyley@gmail.com> | 2014-07-26 11:23:17 +0400 |
commit | 7cb752aaf746dc0b473afeb9e892b7fbc12666c5 (patch) | |
tree | cc4f91ddc18332b5adbe82e3fcb040d976c90105 /core/src/main/j2me/org/spongycastle/util/test/SimpleTest.java | |
parent | 551830f8ea5177042af2c7dd1fc90888bc67387d (diff) |
Execute become-spongy.sh
https://github.com/rtyley/spongycastle/blob/3040af/become-spongy.sh
Diffstat (limited to 'core/src/main/j2me/org/spongycastle/util/test/SimpleTest.java')
-rw-r--r-- | core/src/main/j2me/org/spongycastle/util/test/SimpleTest.java | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/core/src/main/j2me/org/spongycastle/util/test/SimpleTest.java b/core/src/main/j2me/org/spongycastle/util/test/SimpleTest.java new file mode 100644 index 00000000..a61e3bdd --- /dev/null +++ b/core/src/main/j2me/org/spongycastle/util/test/SimpleTest.java @@ -0,0 +1,84 @@ +package org.spongycastle.util.test; + +import java.io.PrintStream; + +import org.spongycastle.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(); + } + } + + public abstract void performTest() + throws Exception; +} |