### Question:
CleanupStrategyProvider implements StrategyProvider<CleanupStrategyExecutor<IDatabaseConnection, IDataSet>> { @Override public CleanupStrategyExecutor<IDatabaseConnection, IDataSet> usedRowsOnlyStrategy() { return (final IDatabaseConnection connection, final List<IDataSet> initialDataSets, final String... tablesToExclude) -> { if (initialDataSets.isEmpty()) { return; } try { final IDataSet dataSet = excludeTables(mergeDataSets(initialDataSets), tablesToExclude); DatabaseOperation.DELETE.execute(connection, dataSet); } catch (final SQLException | DatabaseUnitException e) { throw new DbFeatureException(UNABLE_TO_CLEAN_DATABASE, e); } }; }  @Override CleanupStrategyExecutor<IDatabaseConnection, IDataSet> strictStrategy(); @Override CleanupStrategyExecutor<IDatabaseConnection, IDataSet> usedTablesOnlyStrategy(); @Override CleanupStrategyExecutor<IDatabaseConnection, IDataSet> usedRowsOnlyStrategy();  }### Answer:
@Test public void testUsedRowsOnlyCleanupWithInitialDataSets() throws Exception { final CleanupStrategyProvider provider = new CleanupStrategyProvider(); final CleanupStrategyExecutor<IDatabaseConnection, IDataSet> strategyExecutor = provider.usedRowsOnlyStrategy(); assertThat(strategyExecutor, notNullValue()); strategyExecutor.execute(connection, Arrays.asList(initialDataSet)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_1"), equalTo(1)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_2"), equalTo(0)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_3"), equalTo(1)); }
@Test public void testUsedRowsOnlyCleanupWithInitialDataSetsExcludingOneTable() throws Exception { final CleanupStrategyProvider provider = new CleanupStrategyProvider(); final CleanupStrategyExecutor<IDatabaseConnection, IDataSet> strategyExecutor = provider.usedRowsOnlyStrategy(); assertThat(strategyExecutor, notNullValue()); strategyExecutor.execute(connection, Arrays.asList(initialDataSet), "XML_TABLE_2"); assertThat(getRecordCountFromTable(connection, "XML_TABLE_1"), equalTo(1)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_2"), equalTo(1)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_3"), equalTo(1)); }
@Test public void testUsedRowsOnlyCleanupWithoutInitialDataSets() throws Exception { final CleanupStrategyProvider provider = new CleanupStrategyProvider(); final CleanupStrategyExecutor<IDatabaseConnection, IDataSet> strategyExecutor = provider.usedRowsOnlyStrategy(); assertThat(strategyExecutor, notNullValue()); strategyExecutor.execute(connection, Collections.emptyList()); assertThat(getRecordCountFromTable(connection, "XML_TABLE_1"), equalTo(4)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_2"), equalTo(1)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_3"), equalTo(1)); }
@Test public void testUsedRowsOnlyCleanupWithoutInitialDataSetsExcludingOneTable() throws Exception { final CleanupStrategyProvider provider = new CleanupStrategyProvider(); final CleanupStrategyExecutor<IDatabaseConnection, IDataSet> strategyExecutor = provider.usedRowsOnlyStrategy(); assertThat(strategyExecutor, notNullValue()); strategyExecutor.execute(connection, Collections.emptyList(), "XML_TABLE_2"); assertThat(getRecordCountFromTable(connection, "XML_TABLE_1"), equalTo(4)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_2"), equalTo(1)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_3"), equalTo(1)); }
@Test(expected = DbFeatureException.class) public void testUsedRowsOnlyCleanupOnClosedConnection() throws Exception { final CleanupStrategyProvider provider = new CleanupStrategyProvider(); final CleanupStrategyExecutor<IDatabaseConnection, IDataSet> strategyExecutor = provider.usedRowsOnlyStrategy(); assertThat(strategyExecutor, notNullValue()); connection.close(); strategyExecutor.execute(connection, Arrays.asList(initialDataSet)); }