Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
Change exception class
  • Loading branch information
pchitolina-fauna committed Jan 29, 2024
1 parent 7218734 commit 7917a25
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
10 changes: 5 additions & 5 deletions faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public String getValueAsString() {
try {
return jsonParser.getValueAsString();
} catch (IOException e) {
throw new RuntimeException("Error getting the current token as String", e);
throw new SerializationException("Error getting the current token as String", e);
}
}

Expand All @@ -197,15 +197,15 @@ public Integer getValueAsInt() {
try {
return Integer.parseInt(taggedTokenValue);
} catch (NumberFormatException e) {
throw new RuntimeException("Error getting the current token as Integer", e);
throw new SerializationException("Error getting the current token as Integer", e);
}
}

public Boolean getValueAsBoolean() {
try {
return jsonParser.getValueAsBoolean();
} catch (IOException e) {
throw new RuntimeException("Error getting the current token as Boolean", e);
throw new SerializationException("Error getting the current token as Boolean", e);
}
}

Expand All @@ -214,7 +214,7 @@ public LocalDate getValueAsLocalDate() {
try {
return LocalDate.parse(taggedTokenValue);
} catch (NumberFormatException e) {
throw new RuntimeException("Error getting the current token as LocalDate", e);
throw new SerializationException("Error getting the current token as LocalDate", e);
}
}

Expand All @@ -223,7 +223,7 @@ public Instant getValueAsTime() {
try {
return Instant.parse(taggedTokenValue);
} catch (NumberFormatException e) {
throw new RuntimeException("Error getting the current token as LocalDateTime", e);
throw new SerializationException("Error getting the current token as LocalDateTime", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ public void testeGetValueAsTime() throws IOException {
assertThrows(RuntimeException.class, invalidReader::getValueAsLocalDate);
}

@Test
public void testeGetValueAsTimeNonUTC() throws IOException {
String s = "{\"@time\":\"2023-12-03T05:52:10.000001-09:00\"}";
InputStream inputStream = new ByteArrayInputStream(s.getBytes());
FaunaParser reader = new FaunaParser(inputStream);

Instant instant = Instant.parse("2023-12-03T05:52:10.000001-09:00");

List<Map.Entry<FaunaTokenType, Object>> expectedTokens = List.of(
Map.entry(FaunaTokenType.TIME, instant)
);

assertReader(reader, expectedTokens);

}

private static void assertReader(FaunaParser reader,
List<Map.Entry<FaunaTokenType, Object>> tokens) throws IOException {
for (Map.Entry<FaunaTokenType, Object> entry : tokens) {
Expand Down

0 comments on commit 7917a25

Please sign in to comment.