Wondering if anyone could help or has done something similar. I am trying to mock returning an Oracle CLOB from a custom ClobFactory. I am using the following code to create the CLOB
CLOB clob = CLOB.createTemporary(connection, false, CLOB.DURATION_SESSION);
try (final Writer clobWriter = clob.setCharacterStream(1)) {
clobWriter.write(profile);
} catch (IOException e) {
throw new SQLException(e);
}
return clob;
And my test I have set up the following mocks
@Mock OracleDataSource dataSource;
@Mock CreateProfileParameters parameters;
@Mock ClobDBAccess clobDbAccess;
@Mock OracleConnection connection;
@Mock ClobFactory clobFactory;
@Mock CLOB clob;
@Mock Writer clobWriter;
....
when(dataSource.getConnection()).thenReturn(connection);
when(CLOB.getDBAccess(connection)).thenReturn(clobDbAccess);
when(clobDbAccess.createTemporaryClob(connection, false, CLOB.DURATION_SESSION, (short) 0)).thenReturn(clob);
when(CLOB.createTemporary(connection, false, CLOB.DURATION_SESSION)).thenReturn(clob);
when(ClobFactory.getClob(connection, dataString)).thenReturn(clob);
But I keep getting a NullPointerException each time the test is run, pointing to the second line -
Stacktrace was: java.lang.NullPointerException
at oracle.sql.CLOB.getDBAccess(CLOB.java:1525) ...
Has anyone tried something like this before? Or am I missing out another object that I should be mocking?