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