From dd66cc2279c921b6d92d4c7b8e55b10353a1fc44 Mon Sep 17 00:00:00 2001 From: Pablo Chitolina Date: Thu, 25 Jan 2024 15:00:31 -0300 Subject: [PATCH] Code improvements and test coverage --- .../java/com/fauna/serialization/FaunaParser.java | 10 +++++++--- .../com/fauna/serialization/FaunaParserTest.java | 12 ++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java b/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java index a2b56548..966769b4 100644 --- a/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java +++ b/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java @@ -124,6 +124,11 @@ private void handleStartObject() throws IOException { handleTaggedString(FaunaTokenType.INT); break; case DATE_TAG: + handleTaggedString(FaunaTokenType.DATE); + break; + case TIME_TAG: + handleTaggedString(FaunaTokenType.TIME); + break; case DOC_TAG: case DOUBLE_TAG: case LONG_TAG: @@ -131,7 +136,6 @@ private void handleStartObject() throws IOException { case OBJECT_TAG: case REF_TAG: case SET_TAG: - case TIME_TAG: throw new SerializationException( "Token not implemented: " + jsonParser.currentToken()); default: @@ -210,7 +214,7 @@ public LocalDate getValueAsLocalDate() { try { return LocalDate.parse(taggedTokenValue); } catch (NumberFormatException e) { - throw new RuntimeException("Error parsing the current token as LocalDate", e); + throw new RuntimeException("Error getting the current token as LocalDate", e); } } @@ -219,7 +223,7 @@ public Instant getValueAsTime() { try { return Instant.parse(taggedTokenValue); } catch (NumberFormatException e) { - throw new RuntimeException("Error reading current token as LocalDateTime", e); + throw new RuntimeException("Error getting the current token as LocalDateTime", e); } } } \ No newline at end of file diff --git a/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java b/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java index f0abfde7..363d511c 100644 --- a/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java +++ b/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java @@ -96,6 +96,12 @@ public void testeGetValueAsLocalDate() throws IOException { ); assertReader(reader, expectedTokens); + + String invalidJson = "{\"@date\": \"abc\"}"; + InputStream invalidInputStream = new ByteArrayInputStream(invalidJson.getBytes()); + FaunaParser invalidReader = new FaunaParser(invalidInputStream); + + assertThrows(RuntimeException.class, invalidReader::getValueAsLocalDate); } @Test @@ -111,6 +117,12 @@ public void testeGetValueAsTime() throws IOException { ); assertReader(reader, expectedTokens); + + String invalidJson = "{\"@time\": \"abc\"}"; + InputStream invalidInputStream = new ByteArrayInputStream(invalidJson.getBytes()); + FaunaParser invalidReader = new FaunaParser(invalidInputStream); + + assertThrows(RuntimeException.class, invalidReader::getValueAsLocalDate); } private static void assertReader(FaunaParser reader,