CalendarTimestampType implements UserType { @Override public void nullSafeSet(final PreparedStatement st, final Object value, final int index, final SharedSessionContractImplementor session) throws HibernateException, SQLException { if (value != null) { Calendar calendar = (Calendar) value; st.setLong(index, calendar.getTimeInMillis()); } else { st.setNull(index, Types.BIGINT); } }  @Override int[] sqlTypes(); @Override Class returnedClass(); @Override boolean equals(final Object x,
                          final Object y); @Override int hashCode(final Object x); @Override Object nullSafeGet(final ResultSet rs,
                              final String[] names,
                              final SharedSessionContractImplementor session,
                              final Object owner); @Override void nullSafeSet(final PreparedStatement st,
                            final Object value,
                            final int index,
                            final SharedSessionContractImplementor session); @Override Object deepCopy(final Object value); @Override boolean isMutable(); @Override Serializable disassemble(final Object value); @Override Object assemble(final Serializable cached,
                           final Object owner); @Override Object replace(final Object original,
                          final Object target,
                          final Object owner);  }
@Test public void nullSafeSet() throws Exception { CalendarTimestampType type = new CalendarTimestampType(); PreparedStatement st = Mockito.mock(PreparedStatement.class); Calendar one = Calendar.getInstance(); type.nullSafeSet(st, one, 0, null); Mockito.verify(st, times(1)) .setLong(0, one.getTimeInMillis()); }
@Test public void nullSafeSetNull() throws Exception { CalendarTimestampType type = new CalendarTimestampType(); PreparedStatement st = Mockito.mock(PreparedStatement.class); type.nullSafeSet(st, null, 0, null); Mockito.verify(st, times(1)).setNull(0, Types.BIGINT); }