### Question:
InstantArgument implements Argument { @Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { if (instant != null) { if (calendar.isPresent()) { final Calendar calendarClone = (Calendar) calendar.get().clone(); statement.setTimestamp(position, Timestamp.from(instant), calendarClone); } else { statement.setTimestamp(position, Timestamp.from(instant)); } } else { statement.setNull(position, Types.TIMESTAMP); } } protected  InstantArgument(final Instant instant, final Optional<Calendar> calendar); @Override void apply(int position, PreparedStatement statement, StatementContext ctx);  }### Answer:
@Test public void apply() throws Exception { ZonedDateTime zonedDateTime = ZonedDateTime.parse("2012-12-21T00:00:00.000Z"); ZonedDateTime expected = zonedDateTime.withZoneSameInstant(ZoneId.systemDefault()); new InstantArgument(zonedDateTime.toInstant(), Optional.empty()).apply(1, statement, context); Mockito.verify(statement).setTimestamp(1, Timestamp.from(expected.toInstant())); }
@Test public void apply_ValueIsNull() throws Exception { new InstantArgument(null, Optional.empty()).apply(1, statement, context); Mockito.verify(statement).setNull(1, Types.TIMESTAMP); }
@Test public void applyCalendar() throws Exception { final ZoneId systemDefault = ZoneId.systemDefault(); final ZonedDateTime zonedDateTime = ZonedDateTime.parse("2012-12-21T00:00:00.000Z"); final ZonedDateTime expected = zonedDateTime.withZoneSameInstant(systemDefault); final Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone(systemDefault)); new InstantArgument(zonedDateTime.toInstant(), Optional.of(calendar)).apply(1, statement, context); Mockito.verify(statement).setTimestamp(1, Timestamp.from(expected.toInstant()), calendar); }