diff --git a/moneta/src/test/java/tools/jackson/datatype/moneta/CurrencyUnitDeserializerTest.java b/moneta/src/test/java/tools/jackson/datatype/moneta/CurrencyUnitDeserializerTest.java index c4aaa894..061227bb 100644 --- a/moneta/src/test/java/tools/jackson/datatype/moneta/CurrencyUnitDeserializerTest.java +++ b/moneta/src/test/java/tools/jackson/datatype/moneta/CurrencyUnitDeserializerTest.java @@ -6,6 +6,7 @@ import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.exc.InvalidFormatException; +import tools.jackson.databind.exc.MismatchedInputException; import tools.jackson.databind.json.JsonMapper; import tools.jackson.databind.jsontype.BasicPolymorphicTypeValidator; @@ -29,10 +30,29 @@ public void shouldDeserialize() throws Exception { @Test public void shouldNotDeserializeInvalidCurrency() { final InvalidFormatException e = assertThrows(InvalidFormatException.class, () -> - unit.readValue("\"FOO\"", CurrencyUnit.class)); + unit.readValue(a2q("'FOO'"), CurrencyUnit.class)); + assertThat(e.getMessage()).contains("FOO"); assertThat(e.getValue()).isEqualTo("FOO"); } + @Test + public void shouldNotDeserializeFromNumber() { + assertThrows(MismatchedInputException.class, () -> + unit.readValue("12", CurrencyUnit.class)); + } + + @Test + public void shouldNotDeserializeFromObject() { + assertThrows(MismatchedInputException.class, () -> + unit.readValue(a2q("{'a':1}"), CurrencyUnit.class)); + } + + @Test + public void shouldNotDeserializeFromArray() { + assertThrows(MismatchedInputException.class, () -> + unit.readValue("[1,2]", CurrencyUnit.class)); + } + @Test public void shouldDeserializeWithTyping() throws Exception { ObjectMapper mapper = JsonMapper.builder() @@ -45,4 +65,8 @@ public void shouldDeserializeWithTyping() throws Exception { assertThat(actual).isEqualTo(expected); } + + private static String a2q(final String json) { + return json.replace("'", "\""); + } }