NitfAttributeConverters { @Nullable public static Date nitfDate(@Nullable DateTime nitfDateTime) { if (nitfDateTime == null || nitfDateTime.getZonedDateTime() == null) { return null; } ZonedDateTime zonedDateTime = nitfDateTime.getZonedDateTime(); Instant instant = zonedDateTime.toInstant(); return Date.from(instant); } NitfAttributeConverters(CountryCodeConverter converter); @Nullable static Date nitfDate(@Nullable DateTime nitfDateTime); @Nullable static String fipsToStandardCountryCode(@Nullable String fipsCode);  }
@Test public void testConvertNitfDate() { DateTime dateTime = NitfTestCommons.createNitfDateTime(1997, 12, 17, 10, 26, 30); Date convertedDate = NitfAttributeConverters.nitfDate(dateTime); assertThat(dateTime.getZonedDateTime().toInstant(), is(convertedDate.toInstant())); }
@Test public void testConvertNitfDateWithNull() { Date convertedDate = NitfAttributeConverters.nitfDate(null); assertThat(convertedDate, is(nullValue())); }
@Test public void testConvertNitfDateWithNullZonedTime() { DateTime mockDateTime = mock(DateTime.class); doReturn(null).when(mockDateTime).getZonedDateTime(); Date convertedDate = NitfAttributeConverters.nitfDate(mockDateTime); assertThat(convertedDate, is(nullValue())); }