Merge pull request #1101 from hapifhir/do-20230202-fix-jsonobject-instant-test

Fix JsonObjectTests interaction with Instant
This commit is contained in:
Grahame Grieve 2023-02-15 08:31:58 +11:00 committed by GitHub
commit d1690a9416
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);
}
}