OracleDateNormaliser implements TypeTransformer { @Override public Object transform(Object o) throws SQLException { if (o == null) return null; if (!(o instanceof oracle.sql.DATE)) { throw new UnsupportedOperationException( "OracleDateNormaliser cannot work with " + o.getClass()); } oracle.sql.DATE ts = (oracle.sql.DATE) o; return ts.timestampValue(); }  @Override Object transform(Object o);  }
@Test public void shouldReturnNullIfGivenNull() throws SQLException { assertNull(new OracleDateNormaliser().transform(null)); }
@Test public void shouldThrowCorrectExceptionIfNotGivenAnOracleDATE() throws SQLException { expectedEx.expect(UnsupportedOperationException.class); expectedEx.expectMessage("OracleDateNormaliser cannot work with class java.lang.String"); new OracleDateNormaliser().transform("Any Old Object"); }
@Test public void shouldReturnContentsOfDateIfAllOkay() throws SQLException { DATE dt = mock(DATE.class); when(dt.timestampValue()).thenReturn(new Timestamp(0l)); assertEquals(new Timestamp(0l), new OracleDateNormaliser().transform(dt)); }