Binders { public static Binder timestampBinder() { return TIMESTAMP_BINDER; } private  Binders(); static Binder defaultBinder(); static Binder stringBinder(); static Binder dateBinder(); static Binder timestampBinder(); static Binder timeBinder(); static Binder decimalBinder(); static Binder integerBinder();  }
@Test public void timestampBinderBindsTimestamp() throws SQLException { Timestamp ts = Timestamp.valueOf("1975-07-19 13:14:15"); Binder binder = Binders.timestampBinder(); binder.bind(stmt, 1, ts); verify(stmt).setTimestamp(1, ts); }
@Test public void timestampBinderBindsUtilDate() throws SQLException { Timestamp ts = Timestamp.valueOf("1975-07-19 13:14:15"); Binder binder = Binders.timestampBinder(); binder.bind(stmt, 1, new java.util.Date(ts.getTime())); verify(stmt).setTimestamp(1, ts); }
@Test public void timestampBinderBindsCalendar() throws SQLException { Timestamp ts = Timestamp.valueOf("1975-07-19 13:14:15"); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(ts.getTime()); Binder binder = Binders.timestampBinder(); binder.bind(stmt, 1, calendar); verify(stmt).setTimestamp(1, ts, calendar); }
@Test public void timestampBinderBindsStringWithTimestampFormat() throws SQLException { Binder binder = Binders.timestampBinder(); binder.bind(stmt, 1, "1975-07-19 13:14:15"); verify(stmt).setTimestamp(1, Timestamp.valueOf("1975-07-19 13:14:15")); }
@Test public void timestampBinderBindsStringWithDateFormat() throws SQLException { Binder binder = Binders.timestampBinder(); binder.bind(stmt, 1, "1975-07-19"); verify(stmt).setTimestamp(1, Timestamp.valueOf("1975-07-19 00:00:00")); }
@Test public void timestampBinderBindsLocalDateTime() throws SQLException { Binder binder = Binders.timestampBinder(); binder.bind(stmt, 1, LocalDateTime.parse("1975-07-19T01:02:03.000")); verify(stmt).setTimestamp(1, Timestamp.valueOf("1975-07-19 01:02:03")); }
@Test public void timestampBinderBindsLocalDate() throws SQLException { Binder binder = Binders.timestampBinder(); binder.bind(stmt, 1, LocalDate.parse("1975-07-19")); verify(stmt).setTimestamp(1, Timestamp.valueOf("1975-07-19 00:00:00")); }
@Test public void timestampBinderBindsInstant() throws SQLException { Binder binder = Binders.timestampBinder(); binder.bind(stmt, 1, LocalDateTime.parse("1975-07-19T01:02:03.000").atZone(ZoneId.systemDefault()).toInstant()); verify(stmt).setTimestamp(1, Timestamp.valueOf("1975-07-19 01:02:03")); }
@Test public void timestampBinderBindsZonedDateTime() throws SQLException { Binder binder = Binders.timestampBinder(); ZonedDateTime value = LocalDateTime.parse("1975-07-19T01:02:03.000").atZone(ZoneOffset.UTC); binder.bind(stmt, 1, value); verify(stmt).setTimestamp(eq(1), eq(Timestamp.from(value.toInstant())), calendarWithTimeZone(TimeZone.getTimeZone(ZoneOffset.UTC))); }
@Test public void timestampBinderBindsOffsetDateTime() throws SQLException { Binder binder = Binders.timestampBinder(); OffsetDateTime value = LocalDateTime.parse("1975-07-19T01:02:03.000").atOffset(ZoneOffset.UTC); binder.bind(stmt, 1, value); verify(stmt).setTimestamp(eq(1), eq(Timestamp.from(value.toInstant())), calendarWithTimeZone(TimeZone.getTimeZone(ZoneOffset.UTC))); }
@Test public void timestampBinderBindsNull() throws SQLException { Binder binder = Binders.timestampBinder(); binder.bind(stmt, 1, null); verify(stmt).setObject(1, null); }
@Test public void timestampBinderBindsObject() throws SQLException { Binder binder = Binders.timestampBinder(); binder.bind(stmt, 1, Boolean.TRUE); verify(stmt).setObject(1, Boolean.TRUE); }