Skip to content

Commit

Permalink
Code improvements and test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
pchitolina-fauna committed Jan 25, 2024
1 parent eef6eae commit dd66cc2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 7 additions & 3 deletions faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,18 @@ 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:
case MOD_TAG:
case OBJECT_TAG:
case REF_TAG:
case SET_TAG:
case TIME_TAG:
throw new SerializationException(
"Token not implemented: " + jsonParser.currentToken());
default:
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit dd66cc2

Please sign in to comment.