X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Fgeneral%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Ftest%2FAssertionUtils.java;h=767f679c9be45026010a959110afdf7328aaac54;hb=c210d3c212308d3c5a84f4c19e84a95175e4f172;hp=fc4040721d9aabeffac4017ad0b5f4907caa0529;hpb=2acd9d7b630b9978a504a5a415f25ea2efe18c10;p=utils diff --git a/support/general/src/test/java/org/wamblee/test/AssertionUtils.java b/support/general/src/test/java/org/wamblee/test/AssertionUtils.java index fc404072..767f679c 100644 --- a/support/general/src/test/java/org/wamblee/test/AssertionUtils.java +++ b/support/general/src/test/java/org/wamblee/test/AssertionUtils.java @@ -137,4 +137,27 @@ public final class AssertionUtils { aExpectedMap.get(key), aActual.get(key)); } } + + public static interface ErroneousCode { + void run() throws Exception; + } + + /** + * Asserts that an exception occurs. + * @param aRunnable Test cases should create a subclass of this which contains the + * code that should throw an exception. + * @param aType Type of exception that is expected. + */ + public static void assertException(ErroneousCode aObject, Class aType) { + try { + aObject.run(); + } catch (Throwable t) { + if ( aType.isInstance(t)) { + return; // ok + } + else { + throw new RuntimeException(t); + } + } + } }