From 0518e1624cae35738e71c98ef6150105524871f3 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 2 Mar 2016 18:35:52 +0000 Subject: Throw more informative exception when relationship is missing --- .../org/zwobble/mammoth/tests/util/MammothAsserts.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/test/java/org/zwobble/mammoth/tests/util/MammothAsserts.java (limited to 'src/test/java/org/zwobble/mammoth/tests/util/MammothAsserts.java') diff --git a/src/test/java/org/zwobble/mammoth/tests/util/MammothAsserts.java b/src/test/java/org/zwobble/mammoth/tests/util/MammothAsserts.java new file mode 100644 index 0000000..2439ee2 --- /dev/null +++ b/src/test/java/org/zwobble/mammoth/tests/util/MammothAsserts.java @@ -0,0 +1,15 @@ +package org.zwobble.mammoth.tests.util; + +import org.zwobble.mammoth.internal.util.Casts; + +public class MammothAsserts { + public static T assertThrows(Class exceptionType, Action action) throws T { + try { + action.run(); + throw new AssertionError("Expected exception"); + } catch (RuntimeException exception) { + return Casts.tryCast(exceptionType, exception) + .orElseThrow(() -> exception); + } + } +} -- cgit v1.2.3