CalendarTimestampType implements UserType { @Override public Object nullSafeGet(final ResultSet rs, final String[] names, final SharedSessionContractImplementor session, final Object owner) throws HibernateException, SQLException { String timeInMillisStr = rs.getString(names[0]); if (timeInMillisStr == null) { return null; } Long timeInMillis = Long.valueOf(timeInMillisStr); Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); calendar.setTimeInMillis(timeInMillis); return calendar; }  @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 nullSafeGet() throws Exception { CalendarTimestampType type = new CalendarTimestampType(); String[] names = new String[]{"test"}; ResultSet rs = Mockito.mock(ResultSet.class); Calendar one = Calendar.getInstance(); Mockito.doReturn(String.valueOf(one.getTimeInMillis())) .when(rs).getString(names[0]); Calendar result = (Calendar) type.nullSafeGet(rs, names, null, null); assertEquals(one, result); }
@Test public void nullSafeGetNull() throws Exception { CalendarTimestampType type = new CalendarTimestampType(); String[] names = new String[]{"test"}; ResultSet rs = Mockito.mock(ResultSet.class); Mockito.doReturn(null).when(rs).getString(names[0]); Calendar result = (Calendar) type.nullSafeGet(rs, names, null, null); assertNull(result); }