PGEnumUserType implements EnhancedUserType, ParameterizedType { @Override public Object nullSafeGet(final ResultSet rs, final String[] names, final SessionImplementor session, final Object owner) throws HibernateException, SQLException { Object object = rs.getObject(names[0]); if (rs.wasNull()) { return null; } if (object instanceof PGobject) { PGobject pg = (PGobject) object; return Enum.valueOf(enumClass, pg.getValue()); } return null; }  @Override void setParameterValues(final Properties parameters); @Override Object assemble(final Serializable cached, final Object owner); @Override Object deepCopy(final Object value); @Override Serializable disassemble(final Object value); @Override boolean equals(final Object x, final Object y); @Override int hashCode(final Object x); @Override boolean isMutable(); @Override void nullSafeSet(final PreparedStatement st, final Object value,
			final int index, final SessionImplementor session); @Override Object replace(final Object original, final Object target, final Object owner); @Override Class returnedClass(); @Override int[] sqlTypes(); @Override Object fromXMLString(final String xmlValue); @Override String objectToSQLString(final Object value); @Override String toXMLString(final Object value); @Override Object nullSafeGet(final ResultSet rs, final String[] names,
			final SessionImplementor session, final Object owner);  }
@Test public void testNullSafeGet() throws Exception { String[] names = { "status" }; PGobject value = new PGobject(); value.setValue("ACTIVE"); when(rs.wasNull()).thenReturn(false); when(rs.getObject(anyString())).thenReturn(value ); Object actual = unit.nullSafeGet(rs, names, session, owner); assertEquals(RowStatus.ACTIVE, actual); }
@Test public void testNullSafeGetWhenobjectIsNotPGobject() throws Exception { String[] names = { "status" }; Object value = new Object(); when(rs.wasNull()).thenReturn(false); when(rs.getObject(anyString())).thenReturn(value ); Object actual = unit.nullSafeGet(rs, names, session, owner); assertEquals(null, actual); }
@Test public void testNullSafeGetWhenRsWasNull() throws Exception { String[] names = { "status" }; PGobject value = new PGobject(); value.setValue("ACTIVE"); when(rs.wasNull()).thenReturn(true); when(rs.getObject(anyString())).thenReturn(value ); Object actual = unit.nullSafeGet(rs, names, session, owner); assertEquals(null, actual); }