@Test public void shouldGetDate() { final Date date = new Date(); final Map<String, ?> map = singletonMap("key", date); assertThat(jsonMapFrom(map).getDate("key"), is(date)); }
@Test public void shouldGetDateFromProperStringFormat() { // 2012-04-23T18:25:43.511Z ISO 8601 final Map<String, ?> map = singletonMap("key", "2012-04-23T18:25:43.511Z"); assertThat(jsonMapFrom(map).getDate("key"), is(Date.from(LocalDateTime.of(2012, 4, 23, 18, 25, 43, 511000000).toInstant(UTC)))); }
@Test public void shouldThrowExceptionWhenGettingDateFromWrongStringFormat() { final Map<String, ?> map = singletonMap("key", "Tue Jul 13 00:00:00"); assertThrows(DateTimeParseException.class, () -> { jsonMapFrom(map).getDate("key"); }); }