### Question:
HousekeepingRunner implements ApplicationRunner { @Override public void run(ApplicationArguments args) { Instant deletionCutoff = new Instant().minus(housekeeping.getExpiredPathDuration()); LOG.info("Housekeeping at instant {} has started", deletionCutoff); CompletionCode completionCode = CompletionCode.SUCCESS; try { housekeepingService.cleanUp(deletionCutoff); LOG.info("Housekeeping at instant {} has finished", deletionCutoff); } catch (Exception e) { completionCode = CompletionCode.FAILURE; LOG.error("Housekeeping at instant {} has failed", deletionCutoff, e); throw e; } finally { Map<String, Long> metricsMap = ImmutableMap .<String, Long>builder() .put("housekeeping", completionCode.getCode()) .build(); metricSender.send(metricsMap); } } @Autowired  HousekeepingRunner(Housekeeping housekeeping, HousekeepingService housekeepingService, MetricSender metricSender); @Override void run(ApplicationArguments args);  }### Answer:
@Test public void typical() throws Exception { ArgumentCaptor<Instant> instantCaptor = ArgumentCaptor.forClass(Instant.class); runner.run(null); verify(cleanUpPathService).cleanUp(instantCaptor.capture()); Instant twoDaysAgo = new Instant().minus(TWO_DAYS_DURATION.getMillis()); assertThat(instantCaptor.getValue().getMillis(), is(lessThanOrEqualTo(twoDaysAgo.getMillis()))); }
@Test(expected = IllegalStateException.class) public void rethrowException() throws Exception { doThrow(new IllegalStateException()).when(cleanUpPathService).cleanUp(any(Instant.class)); runner.run(null); }