DataSourceManager implements AutoCloseable { @Override public void close() { for (DataSourceWrapper each : cachedDataSources.values()) { try { each.close(); } catch (final IOException ex) { log.error("An exception occurred while closing the data source", ex); } } cachedDataSources.clear(); sourceDataSources.clear(); } DataSourceManager(final List<SyncConfiguration> syncConfigs); DataSource getDataSource(final ScalingDataSourceConfiguration dataSourceConfig); @Override void close();  }
@Test public void assertClose() throws NoSuchFieldException, IllegalAccessException { DataSourceManager dataSourceManager = new DataSourceManager(syncConfigurations); dataSourceManager.close(); Map<?, ?> cachedDataSources = ReflectionUtil.getFieldValueFromClass(dataSourceManager, "cachedDataSources", Map.class); assertNotNull(cachedDataSources); assertThat(cachedDataSources.size(), is(0)); }