CleanupServiceImpl implements CleanupService<TimeBasedCleanupPolicy> { public long cleanup(TimeBasedCleanupPolicy cleanupPolicy) { long affectedRows = 0; for (Cleanable cleanable : cleanables) { LOGGER.info("Running the purge process for DAO: [{}] with cleanup policy: [{}]", cleanable, cleanupPolicy); affectedRows += cleanable.cleanup(cleanupPolicy); } return affectedRows; } @Inject protected  CleanupServiceImpl(Set<Cleanable> cleanables); long cleanup(TimeBasedCleanupPolicy cleanupPolicy);  }
@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); long rows = 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); }