DateConvertUtils { public static Timestamp convertToTimestamp(java.util.Date date) { assertArgs(date); Timestamp timestamp = new Timestamp(date.getTime()); return timestamp; } private  DateConvertUtils(); static Timestamp convertToTimestamp(java.util.Date date); static java.sql.Date convertToSqlDate(java.util.Date date); static Time convertToTime(java.util.Date date);  }
@Test public void testConvertToTimestamp01() { DateTime date = new DateTime(2012, 9, 3, 23, 7, 11, 100); Timestamp timestamp = DateConvertUtils.convertToTimestamp(date .toDate()); DateTime result = new DateTime(timestamp.getTime()); assertThat(result.getYear(), is(2012)); assertThat(result.getMonthOfYear(), is(9)); assertThat(result.getDayOfMonth(), is(3)); assertThat(result.getHourOfDay(), is(23)); assertThat(result.getMinuteOfHour(), is(7)); assertThat(result.getSecondOfMinute(), is(11)); assertThat(result.getMillisOfSecond(), is(100)); }
@Test public void testConvertToTimestamp02() { Exception ex = assertThrows(IllegalArgumentException.class, () -> DateConvertUtils.convertToTimestamp(null)); assertThat(ex.getMessage(), is("date must not be null")); }