aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/zwobble/mammoth/internal/styles/parsing/DocumentMatcherParser.java4
-rw-r--r--src/main/java/org/zwobble/mammoth/internal/styles/parsing/ParseException.java7
-rw-r--r--src/main/java/org/zwobble/mammoth/internal/styles/parsing/TokenIterator.java6
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/MammothTests.java12
4 files changed, 24 insertions, 5 deletions
diff --git a/src/main/java/org/zwobble/mammoth/internal/styles/parsing/DocumentMatcherParser.java b/src/main/java/org/zwobble/mammoth/internal/styles/parsing/DocumentMatcherParser.java
index 0998f8b..368bc81 100644
--- a/src/main/java/org/zwobble/mammoth/internal/styles/parsing/DocumentMatcherParser.java
+++ b/src/main/java/org/zwobble/mammoth/internal/styles/parsing/DocumentMatcherParser.java
@@ -29,7 +29,7 @@ public class DocumentMatcherParser {
case "strike":
return StyleMapBuilder::strikethrough;
default:
- throw new IllegalArgumentException("Unrecognised document element: " + identifier);
+ throw new ParseException("Unrecognised document element: " + identifier);
}
}
@@ -88,7 +88,7 @@ public class DocumentMatcherParser {
} else if (listType.equals("unordered-list")) {
return false;
} else {
- throw new IllegalArgumentException("Unrecognised list type: " + listType);
+ throw new ParseException("Unrecognised list type: " + listType);
}
}
}
diff --git a/src/main/java/org/zwobble/mammoth/internal/styles/parsing/ParseException.java b/src/main/java/org/zwobble/mammoth/internal/styles/parsing/ParseException.java
new file mode 100644
index 0000000..718bb30
--- /dev/null
+++ b/src/main/java/org/zwobble/mammoth/internal/styles/parsing/ParseException.java
@@ -0,0 +1,7 @@
+package org.zwobble.mammoth.internal.styles.parsing;
+
+public class ParseException extends RuntimeException {
+ public ParseException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/org/zwobble/mammoth/internal/styles/parsing/TokenIterator.java b/src/main/java/org/zwobble/mammoth/internal/styles/parsing/TokenIterator.java
index df22b5d..f006007 100644
--- a/src/main/java/org/zwobble/mammoth/internal/styles/parsing/TokenIterator.java
+++ b/src/main/java/org/zwobble/mammoth/internal/styles/parsing/TokenIterator.java
@@ -46,12 +46,12 @@ public class TokenIterator {
}
String actualValue = tokens.get(index).getValue();
if (!actualValue.equals(tokenValue)) {
- throw new IllegalArgumentException("expected " + tokenType + " token with value " + tokenValue + " but value was " + actualValue);
+ throw new ParseException("expected " + tokenType + " token with value " + tokenValue + " but value was " + actualValue);
}
index += 1;
}
- private IllegalArgumentException unexpectedTokenType(TokenType expected, TokenType actual) {
- return new IllegalArgumentException("expected token of type " + expected + " but was of type " + actual);
+ private ParseException unexpectedTokenType(TokenType expected, TokenType actual) {
+ return new ParseException("expected token of type " + expected + " but was of type " + actual);
}
}
diff --git a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java
index b2661b0..4f4c9fd 100644
--- a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java
@@ -3,6 +3,7 @@ package org.zwobble.mammoth.tests;
import org.junit.Test;
import org.zwobble.mammoth.DocumentConverter;
import org.zwobble.mammoth.Result;
+import org.zwobble.mammoth.internal.styles.parsing.ParseException;
import java.io.File;
import java.io.IOException;
@@ -15,6 +16,7 @@ import static org.junit.Assert.assertThat;
import static org.zwobble.mammoth.internal.util.Lists.list;
import static org.zwobble.mammoth.tests.ResultMatchers.isResult;
import static org.zwobble.mammoth.tests.ResultMatchers.isSuccess;
+import static org.zwobble.mammoth.tests.util.MammothAsserts.assertThrows;
public class MammothTests {
@Test
@@ -190,6 +192,16 @@ public class MammothTests {
}
@Test
+ public void errorIsRaisedIfStyleMapCannotBeParsed() throws IOException {
+ RuntimeException exception = assertThrows(
+ ParseException.class,
+ () -> new DocumentConverter().addStyleMap("p =>\np[style-name=] =>"));
+ assertThat(
+ exception.getMessage(),
+ equalTo("expected token of type STRING but was of type CLOSE_SQUARE_BRACKET"));
+ }
+
+ @Test
public void canDisableDefaultStyleMap() throws IOException {
assertThat(
convertToHtml("simple-list.docx", mammoth -> mammoth.disableDefaultStyleMap()),