X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Fgeneral%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Ftest%2FAssertionUtils.java;h=0a3e41719a8121ec52f844d63ebb7c33385b30e9;hb=e4c24db4532ff3473bb40dda0af6c200a317ac50;hp=8d179db7ad1d488a9d53361c414b3adea6d1e5f8;hpb=dc05aae40ab88d4224d37f53c35d516107a3b031;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 8d179db7..0a3e4171 100644 --- a/support/general/src/test/java/org/wamblee/test/AssertionUtils.java +++ b/support/general/src/test/java/org/wamblee/test/AssertionUtils.java @@ -16,6 +16,7 @@ package org.wamblee.test; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Set; @@ -35,7 +36,7 @@ public final class AssertionUtils { private AssertionUtils() { // Empty } - + /** * Asserts that two object arrays are equal. * @@ -117,4 +118,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); + } + } + } }