DateConvertUtils { public static java.sql.Date convertToSqlDate(java.util.Date date) { assertArgs(date); Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); java.sql.Date sqlDate = new java.sql.Date(cal.getTimeInMillis()); return sqlDate; } 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 testConvertToSqlDate01() { DateTime date = new DateTime(2012, 9, 3, 23, 7, 11, 100); java.sql.Date sqlDate = DateConvertUtils.convertToSqlDate(date .toDate()); DateTime result = new DateTime(sqlDate.getTime()); assertThat(result.getYear(), is(2012)); assertThat(result.getMonthOfYear(), is(9)); assertThat(result.getDayOfMonth(), is(3)); assertThat(result.getHourOfDay(), is(0)); assertThat(result.getMinuteOfHour(), is(0)); assertThat(result.getSecondOfMinute(), is(0)); assertThat(result.getMillisOfSecond(), is(0)); }
@Test public void testConvertToSqlDate02() { Exception ex = assertThrows(IllegalArgumentException.class, () -> DateConvertUtils.convertToSqlDate(null)); assertThat(ex.getMessage(), is("date must not be null")); }