diff --git a/libraries/plugin-tests/src/main/java/de/oliver/plugintests/Expectable.java b/libraries/plugin-tests/src/main/java/de/oliver/plugintests/Expectable.java index 56d1a7ee..352ce9e3 100644 --- a/libraries/plugin-tests/src/main/java/de/oliver/plugintests/Expectable.java +++ b/libraries/plugin-tests/src/main/java/de/oliver/plugintests/Expectable.java @@ -240,4 +240,16 @@ public class Expectable { throw new AssertionError("toHaveLength can only be used on Strings"); } + + public E toThrow(Class expected) { + try { + ((Runnable) t).run(); + } catch (Throwable e) { + if (expected.isInstance(e)) { + return (E) e; + } + throw new AssertionError("Expected " + expected.getSimpleName() + " but got " + e.getClass().getSimpleName()); + } + throw new AssertionError("Expected " + expected.getSimpleName() + " but got nothing"); + } }