### Question:
TimestampConverter implements TypeConverter<Timestamp> { public Timestamp convert(java.sql.Date d) { return new Timestamp(d.getTime()); } TimestampConverter(); Timestamp convert(java.sql.Date d); Timestamp convert(java.util.Date d); Timestamp 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 TimestampConverter().convert(ymdhmss)); sdf.applyPattern("yyyy/MM/dd"); String ymdhms = "2011/11/11 13:45:56"; assertEquals(sdf.parse(ymdhms), new TimestampConverter().convert(ymdhms)); String ymdhm = "2011/11/11 13:45"; assertEquals(sdf.parse(ymdhm), new TimestampConverter().convert(ymdhm)); String ymdh = "2011/11/11 13"; assertEquals(sdf.parse(ymdh), new TimestampConverter().convert(ymdh)); String ymd = "2011/11/11"; assertEquals(sdf.parse(ymd), new TimestampConverter().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 TimestampConverter().convert(hymdhmss)); sdf.applyPattern("yyyy-MM-dd"); String hymdhms = "2011-11-11 13:45:56"; assertEquals(sdf.parse(hymdhms), new TimestampConverter().convert(hymdhms)); String hymdhm = "2011-11-11 13:45"; assertEquals(sdf.parse(hymdhm), new TimestampConverter().convert(hymdhm)); String hymdh = "2011-11-11 13"; assertEquals(sdf.parse(hymdh), new TimestampConverter().convert(hymdh)); String hymd = "2011-11-11"; assertEquals(sdf.parse(hymd), new TimestampConverter().convert(hymd)); }
@Test public void Stringからconvertテスト2() { String d = ""; Date expected = null; Date actual = new TimestampConverter().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); java.sql.Date sd = new java.sql.Date(d.getTime()); assertEquals(sdf.parse(ymdhmss), new TimestampConverter().convert(sd)); }
@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 TimestampConverter().convert(d)); }