### Question:
PurgeService { public void runAutoPurge() { int daysBeforePurge = settings.getProperty(PurgeSettings.DAYS_BEFORE_REMOVE_PLAYER); if (!settings.getProperty(PurgeSettings.USE_AUTO_PURGE)) { return; } else if (daysBeforePurge <= 0) { ConsoleLogger.warning("Did not run auto purge: configured days before purging must be positive"); return; } ConsoleLogger.info("Automatically purging the database..."); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -daysBeforePurge); long until = calendar.getTimeInMillis(); runPurge(null, until); } PurgeService(); void runAutoPurge(); void runPurge(CommandSender sender, long until); void purgePlayers(CommandSender sender, Set<String> names, OfflinePlayer[] players);  }### Answer:
@Test public void shouldNotRunAutoPurge() { given(settings.getProperty(PurgeSettings.USE_AUTO_PURGE)).willReturn(false); given(settings.getProperty(PurgeSettings.DAYS_BEFORE_REMOVE_PLAYER)).willReturn(60); purgeService.runAutoPurge(); verifyZeroInteractions(bukkitService, dataSource); }
@Test public void shouldNotRunAutoPurgeForInvalidInterval() { given(settings.getProperty(PurgeSettings.USE_AUTO_PURGE)).willReturn(true); given(settings.getProperty(PurgeSettings.DAYS_BEFORE_REMOVE_PLAYER)).willReturn(0); purgeService.runAutoPurge(); verifyZeroInteractions(bukkitService, dataSource); }
@Test public void shouldRunAutoPurge() { given(settings.getProperty(PurgeSettings.USE_AUTO_PURGE)).willReturn(true); given(settings.getProperty(PurgeSettings.DAYS_BEFORE_REMOVE_PLAYER)).willReturn(60); Set<String> playerNames = newHashSet("alpha", "bravo", "charlie", "delta"); given(dataSource.getRecordsToPurge(anyLong())).willReturn(playerNames); purgeService.runAutoPurge(); ArgumentCaptor<Long> captor = ArgumentCaptor.forClass(Long.class); verify(dataSource).getRecordsToPurge(captor.capture()); assertCorrectPurgeTimestamp(captor.getValue(), 60); assertThat(Boolean.TRUE, equalTo( ReflectionTestUtils.getFieldValue(PurgeService.class, purgeService, "isPurging"))); verifyScheduledPurgeTask(null, playerNames); }