DateConverter implements Converter<Date, Long> { @NonNull @Override public Date toConverted(@Nullable Long supported) { if (supported == null) { return new Date(); } return new Date(supported); }  @NonNull @Override Date toConverted(@Nullable Long supported); @NonNull @Override Long toSupported(@Nullable Date converted);  }
@Test public void toConvertedShouldReturnSpecifiedTimestamp() throws Exception { final Calendar calendar = Calendar.getInstance(); calendar.set(2016, Calendar.NOVEMBER, 28, 20, 0, 0); final long timestamp = calendar.getTimeInMillis(); final Date actual = underTest.toConverted(timestamp); assertThat(actual) .isWithinYear(2016) .isWithinMonth(11) .isWithinDayOfMonth(28) .isWithinHourOfDay(20) .isWithinMinute(0) .isWithinSecond(0); }
@Test public void toConvertedShouldReturnCurrentDateWhenArgumentIsNull() throws Exception { final Date actual = underTest.toConverted(null); assertThat(actual) .isBeforeOrEqualsTo(new Date()); }
@Test public void toConvertedShouldReturnCurrentDateWhenTimestampIsNegative() throws Exception { final Date actual = underTest.toConverted(Long.MIN_VALUE); assertThat(actual) .isNotNull(); }
@Test public void toConvertedShouldReturnParsedDateWhenTimestampIsMaxValue() throws Exception { final Date actual = underTest.toConverted(Long.MAX_VALUE); assertThat(actual) .isNotNull(); }