when(mockConnection.prepareCall(anyString(), anyInt(), anyInt(), anyInt())).thenReturn(mockCallableStatement);
// Handle Connection.close()
doAnswer(new Answer() {
public Object answer(InvocationOnMock invocation) throws Throwable {
EventRecorder eventRecorder = EventRecorder.getEventRecorder(mockConnection);
eventRecorder.addEvent(new ConnectionCloseEvent(mockConnection));
return null;
}
}).doThrow(new SQLException("Connection is already closed")).when(mockConnection).close();
// Handle Connection.commit()
doAnswer(new Answer() {
public Object answer(InvocationOnMock invocation) throws Throwable {
EventRecorder eventRecorder = EventRecorder.getEventRecorder(mockConnection);
eventRecorder.addEvent(new LocalCommitEvent(mockConnection, new Exception()));
return null;
}
}).doThrow(new SQLException("Transaction already commited")).when(mockConnection).commit();
// Handle Connection.rollback()
doAnswer(new Answer() {
public Object answer(InvocationOnMock invocation) throws Throwable {
EventRecorder eventRecorder = EventRecorder.getEventRecorder(mockConnection);
eventRecorder.addEvent(new LocalRollbackEvent(mockConnection, new Exception()));
return null;
}
}).doThrow(new SQLException("Transaction already rolledback")).when(mockConnection).rollback();
return mockConnection;