aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/docx/RelationshipsTests.java19
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/util/Action.java6
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/util/MammothAsserts.java15
3 files changed, 40 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/RelationshipsTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/RelationshipsTests.java
new file mode 100644
index 0000000..f9a7672
--- /dev/null
+++ b/src/test/java/org/zwobble/mammoth/tests/docx/RelationshipsTests.java
@@ -0,0 +1,19 @@
+package org.zwobble.mammoth.tests.docx;
+
+import org.junit.Test;
+import org.zwobble.mammoth.internal.docx.Relationships;
+
+import static org.junit.Assert.assertEquals;
+import static org.zwobble.mammoth.internal.util.MammothMaps.map;
+import static org.zwobble.mammoth.tests.util.MammothAsserts.assertThrows;
+
+public class RelationshipsTests {
+ @Test
+ public void exceptionIsThrownIfRelationshipCannotBeFound() {
+ Relationships relationships = new Relationships(map());
+ RuntimeException exception = assertThrows(
+ RuntimeException.class,
+ () -> relationships.findRelationshipById("rId5"));
+ assertEquals("Could not find relationship 'rId5'", exception.getMessage());
+ }
+}
diff --git a/src/test/java/org/zwobble/mammoth/tests/util/Action.java b/src/test/java/org/zwobble/mammoth/tests/util/Action.java
new file mode 100644
index 0000000..c99a770
--- /dev/null
+++ b/src/test/java/org/zwobble/mammoth/tests/util/Action.java
@@ -0,0 +1,6 @@
+package org.zwobble.mammoth.tests.util;
+
+@FunctionalInterface
+public interface Action {
+ void run();
+}
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 extends Throwable> T assertThrows(Class<T> exceptionType, Action action) throws T {
+ try {
+ action.run();
+ throw new AssertionError("Expected exception");
+ } catch (RuntimeException exception) {
+ return Casts.tryCast(exceptionType, exception)
+ .orElseThrow(() -> exception);
+ }
+ }
+}