JDBCSSHRecordStore implements SSHRecordStore { @Override public SSHRecordStoreConnection getConnection() { try { JDBCSSHRecordStoreConnection jdbcConn = new JDBCSSHRecordStoreConnection(src.getConnection()); jdbcConn.setOperationTimeout(opTimeout); return jdbcConn; } catch (SQLException ex) { LOGGER.error("getConnection: {}", ex.getMessage()); throw new ResourceException(ResourceException.SERVICE_UNAVAILABLE, ex.getMessage()); } } JDBCSSHRecordStore(PoolableDataSource src); @Override SSHRecordStoreConnection getConnection(); @Override void setOperationTimeout(int opTimeout); @Override void clearConnections(); @Override void log(final Principal principal, final String ip, final String service,
                    final String instanceId); @Override boolean enableNotifications(NotificationManager notificationManager, RolesProvider rolesProvider, final String serverName);  }
@Test public void testGetConnection() throws SQLException { PoolableDataSource mockDataSrc = Mockito.mock(PoolableDataSource.class); Connection mockConn = Mockito.mock(Connection.class); Mockito.doReturn(mockConn).when(mockDataSrc).getConnection(); JDBCSSHRecordStore store = new JDBCSSHRecordStore(mockDataSrc); assertNotNull(store.getConnection()); store.clearConnections(); }
@Test public void testGetConnectionException() throws SQLException { PoolableDataSource mockDataSrc = Mockito.mock(PoolableDataSource.class); Mockito.doThrow(new SQLException()).when(mockDataSrc).getConnection(); try { JDBCSSHRecordStore store = new JDBCSSHRecordStore(mockDataSrc); store.getConnection(); fail(); } catch (RuntimeException ex) { assertTrue(true); } }