Skip to content

Commit 3a5257d

Browse files
author
Borzoo Esmailloo
committed
Use expected exception instead of try-catch
1 parent 1be6c77 commit 3a5257d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

javasource/databaseconnectortest/test/JdbcConnectorTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ private SimpleEntry<String, IMetaPrimitive.PrimitiveType> entry(String name, IMe
7878
return new SimpleEntry<>(name, type);
7979
}
8080

81-
@Test public void testStatementCreationException() throws SQLException {
81+
@Test(expected = SQLException.class)
82+
public void testStatementCreationException() throws SQLException {
8283
Exception testException = new SQLException("Test Exception Text");
8384

8485
when(connectionManager.getConnection(anyString(), anyString(), anyString())).thenReturn(connection);
@@ -87,10 +88,11 @@ private SimpleEntry<String, IMetaPrimitive.PrimitiveType> entry(String name, IMe
8788
try {
8889
jdbcConnector.executeQuery(jdbcUrl, userName, password, mockIMetaObject(), sqlQuery, context);
8990
fail("An exception should occur!");
90-
} catch(SQLException sqlException) {}
91-
92-
verify(connection).close();
93-
verify(preparedStatement, never()).close();
91+
}
92+
finally {
93+
verify(connection).close();
94+
verify(preparedStatement, never()).close();
95+
}
9496
}
9597

9698
@Test public void testObjectInstantiatorException() throws SQLException {

0 commit comments

Comments
 (0)