### Question:
CleanupServiceImpl implements CleanupService<TimeBasedCleanupPolicy> { public CleanupResult cleanup(TimeBasedCleanupPolicy cleanupPolicy) { long affectedRows = 0; int errorCount = 0; for (Cleanable cleanable : cleanables) { LOGGER.info("Running the purge process for DAO: [{}] with cleanup policy: [{}]", cleanable, cleanupPolicy); try { affectedRows += cleanable.cleanup(cleanupPolicy); } catch (Exception ex) { LOGGER.error("Running the purge process for DAO: [{}] failed with: {}", cleanable, ex); errorCount++; } } return new Result(affectedRows, errorCount); } @Inject protected  CleanupServiceImpl(Set<Cleanable> cleanables); CleanupResult cleanup(TimeBasedCleanupPolicy cleanupPolicy);  }### Answer:
@Test public void testShouldDaosBeCalledWithTheCleanupPolicy() throws Exception { cleanables = new HashSet<>(); cleanables.add(cleanableDao); expect(cleanableDao.cleanup(capture(timeBasedCleanupPolicyCapture))).andReturn(2L); replay(cleanableDao); cleanupServiceImpl = new CleanupServiceImpl(cleanables); cleanupServiceImpl.cleanup(cleanupPolicy); Assert.assertNotNull("The argument is null", timeBasedCleanupPolicyCapture.getValue()); Assert.assertEquals("The cluster name is wrong!", timeBasedCleanupPolicyCapture.getValue().getClusterName(), CLUSTER_NAME); Assert.assertEquals("The to date is wrong!", timeBasedCleanupPolicyCapture.getValue().getToDateInMillis(), FROM_DATE_TIMESTAMP); }
@Test public void testAffectedRowsNoError() throws Exception { cleanables = new HashSet<>(); cleanables.add(cleanableDao); expect(cleanableDao.cleanup(cleanupPolicy)).andReturn(2L); replay(cleanableDao); cleanupServiceImpl = new CleanupServiceImpl(cleanables); CleanupService.CleanupResult res = cleanupServiceImpl.cleanup(cleanupPolicy); Assert.assertEquals("The affected rows count is wrong", 2L, res.getAffectedRows()); Assert.assertEquals("The error count is wrong", 0L, res.getErrorCount()); }
@Test public void testAffectedRowsWithErrors() throws Exception { cleanables = new HashSet<>(); cleanables.add(cleanableDao); expect(cleanableDao.cleanup(cleanupPolicy)).andThrow(new RuntimeException()); replay(cleanableDao); cleanupServiceImpl = new CleanupServiceImpl(cleanables); CleanupService.CleanupResult res = cleanupServiceImpl.cleanup(cleanupPolicy); Assert.assertEquals("The affected rows count is wrong", 0L, res.getAffectedRows()); Assert.assertEquals("The error count is wrong", 1L, res.getErrorCount()); }