### Question:
TimestampType extends AbstractSqlType { protected Timestamp toTimestamp(String value) { String pattern = null; if (value.contains("-")) { pattern = "yyyy-MM-dd HH:mm:ss"; } else { pattern = "yyyy/MM/dd HH:mm:ss"; } Timestamp timestamp = TimestampConversionUtil.toTimestamp(value, pattern); int pos = value.indexOf('.'); if (pos > -1) { int nanos = IntegerConversionUtil.toPrimitiveInt(value .substring(pos + 1)); if (nanos > 0) { int n = (int) Math.log10(nanos); if (n < 8) { nanos *= (int) Math.pow(10, 8 - n); } } timestamp.setNanos(nanos); } return timestamp; } TimestampType();  TimestampType(String dataType); void bindValue(PreparedStatement ps, int index, String value); String getValue(ResultSet resultSet, int index);  }### Answer:
@Test public void testNanos() throws Exception { TimestampType timestampType = new TimestampType(); Timestamp timestamp = timestampType .toTimestamp("2008/01/01 12:11:10.123456"); assertEquals(123456000, timestamp.getNanos()); }
@Test public void testNanos_zero() throws Exception { TimestampType timestampType = new TimestampType(); Timestamp timestamp = timestampType .toTimestamp("2008/01/01 12:11:10.000"); assertEquals(0, timestamp.getNanos()); }
@Test public void testToTimestamp_hyphen() throws Exception { TimestampType timestampType = new TimestampType(); assertEquals(Timestamp.valueOf("2008-01-01 01:02:03"), timestampType.toTimestamp("2008-01-01 01:02:03")); assertEquals(Timestamp.valueOf("2008-01-01 01:02:03"), timestampType.toTimestamp("2008-01-01 01:02:03")); }
@Test public void testToTimestamp_slash() throws Exception { TimestampType timestampType = new TimestampType(); assertEquals(Timestamp.valueOf("2008-01-01 01:02:03"), timestampType.toTimestamp("2008/01/01 01:02:03")); assertEquals(Timestamp.valueOf("2008-01-01 01:02:03"), timestampType.toTimestamp("2008/01/01 01:02:03")); }