LegacyTimestampFormatter implements TimestampFormatter { @Override public String format(final Timestamp timestamp) { return format(timestamp.toDate()); } LegacyTimestampFormatter(final String pattern, final Locale locale); @Override boolean isValid(final String timestamp); @Override String format(final Timestamp timestamp);  }
@Test public void minutePrecision() { LegacyTimestampFormatter formatter = new LegacyTimestampFormatter("yyyy-MM-dd HH:mm", Locale.US); assertThat(formatter.format(TimestampFactory.create(2016, 2, 1, 12, 30, 55, 0))).isEqualTo("2016-02-01 12:30"); assertThat(formatter.format(TimestampFactory.create(2016, 2, 1, 12, 30, 55, 999_000_000))).isEqualTo("2016-02-01 12:30"); assertThat(formatter.format(TimestampFactory.create(2016, 2, 1, 12, 30, 56, 0))).isEqualTo("2016-02-01 12:30"); }
@Test public void secondPrecision() { LegacyTimestampFormatter formatter = new LegacyTimestampFormatter("yyyy-MM-dd HH:mm:ss", Locale.US); assertThat(formatter.format(TimestampFactory.create(2016, 2, 1, 12, 30, 55, 0))).isEqualTo("2016-02-01 12:30:55"); assertThat(formatter.format(TimestampFactory.create(2016, 2, 1, 12, 30, 55, 999_000_000))).isEqualTo("2016-02-01 12:30:55"); assertThat(formatter.format(TimestampFactory.create(2016, 2, 1, 12, 30, 56, 0))).isEqualTo("2016-02-01 12:30:56"); }
@Test public void millisecondPrecision() { LegacyTimestampFormatter formatter = new LegacyTimestampFormatter("HH:mm:ss.SSS", Locale.US); assertThat(formatter.format(TimestampFactory.create(2016, 2, 1, 12, 30, 55, 0))).isEqualTo("12:30:55.000"); assertThat(formatter.format(TimestampFactory.create(2016, 2, 1, 12, 30, 55, 999_000_000))).isEqualTo("12:30:55.999"); assertThat(formatter.format(TimestampFactory.create(2016, 2, 1, 12, 30, 56, 0))).isEqualTo("12:30:56.000"); }