Write testcase for improved exception handling.
parent
8f155ec318
commit
a2ba0fb2b1
|
|
@ -13,6 +13,12 @@ public abstract class MockConnection implements Connection {
|
||||||
|
|
||||||
ResultSet mockResultSet;
|
ResultSet mockResultSet;
|
||||||
|
|
||||||
|
public final void mockExceptionOnExecute(String exceptionMessage) throws SQLException {
|
||||||
|
PreparedStatement mockPreparedStatement = Mockito.mock(PreparedStatement.class);
|
||||||
|
Mockito.when(mockPreparedStatement.execute()).thenThrow(new SQLException(exceptionMessage));
|
||||||
|
Mockito.when(this.prepareStatement(Mockito.anyString())).thenReturn(mockPreparedStatement);
|
||||||
|
}
|
||||||
|
|
||||||
public final void mockType(String sqlTypesName) throws SQLException {
|
public final void mockType(String sqlTypesName) throws SQLException {
|
||||||
PreparedStatement mockPreparedStatement = Mockito.mock(PreparedStatement.class);
|
PreparedStatement mockPreparedStatement = Mockito.mock(PreparedStatement.class);
|
||||||
Mockito.when(mockPreparedStatement.execute()).thenReturn(true);
|
Mockito.when(mockPreparedStatement.execute()).thenReturn(true);
|
||||||
|
|
|
||||||
|
|
@ -46,3 +46,13 @@ class MockTest(unittest.TestCase):
|
||||||
extra_type_mappings.get(jsql_type_name,
|
extra_type_mappings.get(jsql_type_name,
|
||||||
'getObject'))
|
'getObject'))
|
||||||
verify_get(1)
|
verify_get(1)
|
||||||
|
|
||||||
|
def test_exception_on_execute(self):
|
||||||
|
dummy_msg = "expected"
|
||||||
|
self.conn.jconn.mockExceptionOnExecute(dummy_msg)
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
try:
|
||||||
|
cursor.execute("dummy stmt")
|
||||||
|
fail("expected exception")
|
||||||
|
except jaydebeapi.Error, e:
|
||||||
|
self.assertEquals(str(e), 'expected')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue