Fix JsonObjectTests interaction with Instant

This commit is contained in:
dotasek 2023-02-02 13:52:01 -05:00
parent ea41a8b6a6
commit 7b3e206b1c
1 changed files with 9 additions and 4 deletions

View File

@ -13,7 +13,7 @@ import org.junit.jupiter.api.Test;
class JsonObjectTests {
@Test
void test1() throws ParseException {
void asInstantReturnsNonNull() throws ParseException {
JsonObject json = new JsonObject();
json.set("date", "2022-10-12");
System.out.println(json.asString("date"));
@ -21,7 +21,7 @@ class JsonObjectTests {
}
@Test
void test2() throws ParseException {
void jsonInstantEqualsJavaInstant() throws ParseException {
Instant instant = Instant.now();
JsonObject json = new JsonObject();
json.set("date", instant);
@ -30,13 +30,18 @@ class JsonObjectTests {
}
@Test
void test3() {
void differentInstantsArentEqual() throws InterruptedException {
Instant instant = Instant.now();
DateTimeFormatter df = DateTimeFormatter.ofPattern("MMM-yyyy").withLocale(Locale.getDefault()).withZone(ZoneId.systemDefault());
System.out.println(df.format(instant));
df = DateTimeFormatter.ofPattern("yyyy-MM-dd").withLocale(Locale.getDefault()).withZone(ZoneId.systemDefault());
System.out.println(df.format(instant));
Assertions.assertNotEquals(instant, Instant.now());
// We need to sleep here, as some machines are fast enough for differentInstant to have the same values to the
// nanosecond even after processing the above lines.
Thread.sleep(1);
Instant differentInstant = Instant.now();
Assertions.assertNotEquals(instant, differentInstant);
}
}