OracleClobNormaliser implements TypeTransformer { @Override public Object transform(Object o) throws SQLException { if (o == null) return null; if (!(o instanceof java.sql.Clob)) { throw new UnsupportedOperationException("OracleClobNormaliser cannot work with " + o.getClass()); } java.sql.Clob clob = (java.sql.Clob) o; if (clob.length() > MAX_CLOB_LENGTH) throw new UnsupportedOperationException( "Clobs larger than " + MAX_CLOB_LENGTH + " bytes are not supported by DBFIT"); return clob.getSubString(1, MAX_CLOB_LENGTH); }  @Override Object transform(Object o);  }
@Test public void shouldReturnNullIfGivenNull() throws SQLException { assertNull(new OracleClobNormaliser().transform(null)); }
@Test public void shouldThrowCorrectExceptionIfNotGivenACLOB() throws SQLException { expectedEx.expect(UnsupportedOperationException.class); expectedEx.expectMessage("OracleClobNormaliser cannot work with class java.lang.String"); new OracleClobNormaliser().transform("Any Old Object"); }
@Test public void shouldThrowCorrectExceptionIfClobIsLargerThanMaximum() throws SQLException { Clob clob = mock(Clob.class); when(clob.length()).thenReturn(10001l); expectedEx.expect(UnsupportedOperationException.class); expectedEx.expectMessage("Clobs larger than 10000 bytes are not supported by DBFIT"); new OracleClobNormaliser().transform(clob); }
@Test public void shouldReturnContentsOfClobIFAllOkay() throws SQLException { Clob clob = mock(Clob.class); when(clob.length()).thenReturn(Long.valueOf("CLOB contents".length())); when(clob.getSubString(eq(1l), eq(10000))).thenReturn("CLOB contents"); new OracleClobNormaliser().transform(clob); }