AbstractDataSourceChecker implements DataSourceChecker { @Override public final void checkConnection(final Collection<? extends DataSource> dataSources) { try { for (DataSource each : dataSources) { each.getConnection().close(); } } catch (final SQLException ex) { throw new PrepareFailedException("Data sources can't connected!", ex); } }  @Override final void checkConnection(final Collection<? extends DataSource> dataSources);  }
@Test public void assertCheckConnection() throws SQLException { when(dataSource.getConnection()).thenReturn(connection); dataSourceChecker.checkConnection(dataSources); verify(dataSource).getConnection(); }
@Test(expected = PrepareFailedException.class) public void assertCheckConnectionFailed() throws SQLException { when(dataSource.getConnection()).thenThrow(new SQLException("error")); dataSourceChecker.checkConnection(dataSources); }