### Question:
SqlDateConverter implements TypeConverter<Date> { public Date convert(Timestamp t) { return new java.sql.Date(t.getTime()); } SqlDateConverter(); Date convert(Timestamp t); Date convert(java.util.Date d); Date convert(String v);  }### Answer:
@Test public void Stringからのconvertテスト() throws Exception { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyy/MM/dd HH:mm:ss.SSS"); String ymdhmss = "2011/11/11 13:45:56.789"; assertEquals(sdf.parse(ymdhmss), new SqlDateConverter().convert(ymdhmss)); sdf.applyPattern("yyyy/MM/dd"); String ymdhms = "2011/11/11 13:45:56"; assertEquals(sdf.parse(ymdhms), new SqlDateConverter().convert(ymdhms)); String ymdhm = "2011/11/11 13:45"; assertEquals(sdf.parse(ymdhm), new SqlDateConverter().convert(ymdhm)); String ymdh = "2011/11/11 13"; assertEquals(sdf.parse(ymdh), new SqlDateConverter().convert(ymdh)); String ymd = "2011/11/11"; assertEquals(sdf.parse(ymd), new SqlDateConverter().convert(ymd)); sdf.applyPattern("yyyy-MM-dd HH:mm:ss.SSS"); String hymdhmss = "2011-11-11 13:45:56.789"; assertEquals(sdf.parse(hymdhmss), new SqlDateConverter().convert(hymdhmss)); sdf.applyPattern("yyyy-MM-dd"); String hymdhms = "2011-11-11 13:45:56"; assertEquals(sdf.parse(hymdhms), new SqlDateConverter().convert(hymdhms)); String hymdhm = "2011-11-11 13:45"; assertEquals(sdf.parse(hymdhm), new SqlDateConverter().convert(hymdhm)); String hymdh = "2011-11-11 13"; assertEquals(sdf.parse(hymdh), new SqlDateConverter().convert(hymdh)); String hymd = "2011-11-11"; assertEquals(sdf.parse(hymd), new SqlDateConverter().convert(hymd)); }
@Test public void Stringからconvertテスト2() { String d = ""; Date expected = null; Date actual = new SqlDateConverter().convert(d); assertEquals(expected, actual); }
@Test public void Timestampからconvertテスト() throws Exception { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyy/MM/dd HH:mm:ss.SSS"); String ymdhmss = "2011/11/11 13:45:56.789"; Date d = sdf.parse(ymdhmss); Timestamp ts = new Timestamp(d.getTime()); assertEquals(sdf.parse(ymdhmss), new SqlDateConverter().convert(ts)); }
@Test public void Dateからconvertテスト() throws Exception { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyy/MM/dd HH:mm:ss.SSS"); String ymdhmss = "2011/11/11 13:45:56.789"; Date d = sdf.parse(ymdhmss); assertEquals(sdf.parse(ymdhmss), new SqlDateConverter().convert(d)); }