Skip to content

Commit

Permalink
Additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsloan committed Sep 13, 2024
1 parent c236b4b commit 3b86cc9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public Instant format(String value, ZoneId zoneId) {
return localDateTime.atZone(zoneId).toInstant();
} catch (DateTimeParseException dtpe) {
// ignore exception and use fallback
System.err.println("ERROR: " + dtpe.getMessage());
}
}
throw new DateTimeParseException("Cannot parse date with any formats", value, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,41 @@ void testGetDisplayPatterns() {
String result = formatter.getDisplayPatterns();
assertEquals(expected, result);
}

@Test
void testFormatWithEmptyListOfDateStrings() {
MultiDateTimeFormatter formatter = new MultiDateTimeFormatter(
List.of(),
List.of(),
false
);

assertThrows(DateTimeParseException.class, () -> formatter.format("2021-10-01T11:30:00", ZoneId.of("UTC")));
}

@Test
void testFormatWithMultiplePatternsTargetingFirst() {
MultiDateTimeFormatter formatter = MultiDateTimeFormatter.createDateTimeFormatter(
List.of("yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd HH:mm:ss"),
"TestConfig",
ZoneId.of("UTC")
);

Instant expected = Instant.parse("2021-10-01T11:30:00Z");
Instant result = formatter.format("2021-10-01T11:30:00", ZoneId.of("UTC"));
assertEquals(expected, result);
}

@Test
void testFormatWithMultiplePatternsTargetingSecond() {
MultiDateTimeFormatter formatter = MultiDateTimeFormatter.createDateTimeFormatter(
List.of("yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd HH:mm:ss"),
"TestConfig",
ZoneId.of("UTC")
);

Instant expected = Instant.parse("2021-10-01T11:30:00Z");
Instant result = formatter.format("2021-10-01 11:30:00", ZoneId.of("UTC"));
assertEquals(expected, result);
}
}

0 comments on commit 3b86cc9

Please sign in to comment.