Skip to content

Commit

Permalink
add tests of datetime deserialization for attributes & custom fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jenschude committed Aug 11, 2023
1 parent 7f1a164 commit 6bc9ed4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public void attributes() throws IOException {
dateTime -> assertThat(dateTime).isEqualTo("2020-01-01T13:15:00.123Z"));
assertThat(attributes.get("datetime-simple")).isInstanceOfSatisfying(ZonedDateTime.class,
dateTime -> assertThat(dateTime).isEqualTo("2020-01-01T13:15:00Z"));
assertThat(attributes.get("datetime-text")).isInstanceOfSatisfying(String.class,
dateTime -> assertThat(dateTime).isEqualTo("2018-09-24T00:00:00-0400"));
assertThat(attributes.get("datetime-offset")).isInstanceOfSatisfying(ZonedDateTime.class,
dateTime -> assertThat(dateTime).isEqualTo("2018-09-24T00:00:00-04:00"));
assertThat(attributes.get("datetime-no-offset")).isInstanceOfSatisfying(String.class,
dateTime -> assertThat(dateTime).isEqualTo("2018-09-24T00:00:00"));
assertThat(attributes.get("boolean")).isInstanceOfSatisfying(Boolean.class,
aBoolean -> assertThat(aBoolean).isTrue());
assertThat(attributes.get("integer")).isInstanceOfSatisfying(Long.class,
Expand Down Expand Up @@ -190,6 +196,12 @@ public void attributesAsDateFalse() throws IOException {
localTime -> assertThat(localTime).isEqualTo("13:15:00"));
assertThat(attributes.get("datetime-simple").getValue()).isInstanceOfSatisfying(String.class,
dateTime -> assertThat(dateTime).isEqualTo("2020-01-01T13:15:00Z"));
assertThat(attributes.get("datetime-text").getValue()).isInstanceOfSatisfying(String.class,
dateTime -> assertThat(dateTime).isEqualTo("2018-09-24T00:00:00-0400"));
assertThat(attributes.get("datetime-offset").getValue()).isInstanceOfSatisfying(String.class,
dateTime -> assertThat(dateTime).isEqualTo("2018-09-24T00:00:00-04:00"));
assertThat(attributes.get("datetime-no-offset").getValue()).isInstanceOfSatisfying(String.class,
dateTime -> assertThat(dateTime).isEqualTo("2018-09-24T00:00:00"));
assertThat(attributes.get("date").withAttribute(AttributeAccessor::asDate))
.isInstanceOfSatisfying(LocalDate.class, localDate -> assertThat(localDate).isEqualTo("2020-01-01"));
assertThat(attributes.get("time").withAttribute(AttributeAccessor::asTime))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public void fields() throws IOException {
localTime -> assertThat(localTime).isEqualTo("13:15:00"));
assertThat(fields.get("datetime-simple")).isInstanceOfSatisfying(ZonedDateTime.class,
dateTime -> assertThat(dateTime).isEqualTo("2020-01-01T13:15:00Z"));
assertThat(fields.get("datetime-offset")).isInstanceOfSatisfying(ZonedDateTime.class,
dateTime -> assertThat(dateTime).isEqualTo("2020-01-01T13:15:00-04:00"));
assertThat(fields.get("datetime-no-offset")).isInstanceOfSatisfying(String.class,
dateTime -> assertThat(dateTime).isEqualTo("2020-01-01T13:15:00"));
assertThat(fields.get("datetime-text")).isInstanceOfSatisfying(String.class,
dateTime -> assertThat(dateTime).isEqualTo("2020-01-01T13:15:00-0400"));
assertThat(fields.get("boolean")).isInstanceOfSatisfying(Boolean.class,
aBoolean -> assertThat(aBoolean).isTrue());
assertThat(fields.get("integer")).isInstanceOfSatisfying(Long.class,
Expand Down Expand Up @@ -114,6 +120,12 @@ public void fieldsAsDateFalse() throws IOException {
localTime -> assertThat(localTime).isEqualTo("13:15:00"));
assertThat(fields.get("datetime-simple")).isInstanceOfSatisfying(String.class,
dateTime -> assertThat(dateTime).isEqualTo("2020-01-01T13:15:00Z"));
assertThat(fields.get("datetime-offset")).isInstanceOfSatisfying(String.class,
dateTime -> assertThat(dateTime).isEqualTo("2020-01-01T13:15:00-04:00"));
assertThat(fields.get("datetime-no-offset")).isInstanceOfSatisfying(String.class,
dateTime -> assertThat(dateTime).isEqualTo("2020-01-01T13:15:00"));
assertThat(fields.get("datetime-text")).isInstanceOfSatisfying(String.class,
dateTime -> assertThat(dateTime).isEqualTo("2020-01-01T13:15:00-0400"));

assertThat(fields.get("boolean")).isInstanceOfSatisfying(Boolean.class,
aBoolean -> assertThat(aBoolean).isTrue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,18 @@
"name": "datetime-simple",
"value": "2020-01-01T13:15:00Z"
},
{
"name": "datetime-text",
"value": "2018-09-24T00:00:00-0400"
},
{
"name": "datetime-offset",
"value": "2018-09-24T00:00:00-04:00"
},
{
"name": "datetime-no-offset",
"value": "2018-09-24T00:00:00"
},
{
"name": "datetime-text",
"value": "2018-09-24T00:00:00-0400"
},
{
"name": "boolean",
"value": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
"time-simple": "13:15:00",
"datetime": "2020-01-01T13:15:00.123Z",
"datetime-simple": "2020-01-01T13:15:00Z",
"datetime-offset": "2020-01-01T13:15:00-04:00",
"datetime-no-offset": "2020-01-01T13:15:00",
"datetime-text": "2020-01-01T13:15:00-0400",
"boolean": true,
"set-text": [
"foo"
Expand Down

0 comments on commit 6bc9ed4

Please sign in to comment.