XATransactionDataSource implements AutoCloseable { @Override public void close() { if (!CONTAINER_DATASOURCE_NAMES.contains(dataSource.getClass().getSimpleName())) { xaTransactionManager.removeRecoveryResource(resourceName, xaDataSource); } else { close(dataSource); } } XATransactionDataSource(final DatabaseType databaseType, final String resourceName, final DataSource dataSource, final XATransactionManager xaTransactionManager); Connection getConnection(); @Override void close();  }
@Test public void assertCloseAtomikosDataSourceBean() { DataSource dataSource = DataSourceUtils.build(AtomikosDataSourceBean.class, DatabaseTypes.getActualDatabaseType("H2"), "ds11"); XATransactionDataSource transactionDataSource = new XATransactionDataSource(DatabaseTypes.getActualDatabaseType("H2"), "ds11", dataSource, xaTransactionManager); transactionDataSource.close(); verify(xaTransactionManager, times(0)).removeRecoveryResource(anyString(), any(XADataSource.class)); }
@Test public void assertCloseHikariDataSource() { DataSource dataSource = DataSourceUtils.build(HikariDataSource.class, DatabaseTypes.getActualDatabaseType("H2"), "ds1"); XATransactionDataSource transactionDataSource = new XATransactionDataSource(DatabaseTypes.getActualDatabaseType("H2"), "ds1", dataSource, xaTransactionManager); transactionDataSource.close(); verify(xaTransactionManager).removeRecoveryResource(anyString(), any(XADataSource.class)); }