KeyRotationJob implements FullstopJob { @EveryDayAtTenPM public void run() { log.info("Running {}", getClass().getSimpleName()); allAccountIds.get().forEach(accountId -> { try { log.debug("Checking account {} for expired IAM access keys", accountId); iamDataSource.getUsers(accountId).stream() .map(u -> iamDataSource.getAccessKeys(accountId, u.getUserName())) .flatMap(Collection::stream) .filter(isActiveAndOlderThanDays(properties.getAccessKeysExpireAfterDays())) .forEach(accessKey -> violationWriter.writeViolation(accountId, accessKey)); } catch (Exception e) { jobExceptionHandler.onException(e, ImmutableMap.of( "job", this.getClass().getSimpleName(), "aws_account_id", accountId)); } }); log.info("Finished {}", getClass().getSimpleName()); } @Autowired  KeyRotationJob(final IdentityManagementDataSource iamDataSource,
                          final KeyRotationViolationWriter violationWriter,
                          final JobsProperties properties,
                          final AccountIdSupplier allAccountIds,
                          final JobExceptionHandler jobExceptionHandler); @PostConstruct void init(); @EveryDayAtTenPM void run();  }
@Test public void testSimple() { new KeyRotationJob(mockIAMDataSource, mockViolationWriter, new JobsProperties(), mockAccountIdSupplier, mock(JobExceptionHandler.class)).run(); verify(mockIAMDataSource, times(2)).getUsers(anyString()); verify(mockIAMDataSource, times(3)).getAccessKeys(anyString(), anyString()); verify(mockAccountIdSupplier).get(); verify(mockViolationWriter).writeViolation(eq("account01"), any()); }