ApplicationsAndBookmarkCleaner extends FixedHourScheduledJob { void removeOldBookmarksAndApplications() { var latestAccessIntervals = accessIntervalRepo.findAllLatestIntervals(); for (AccessInterval interval : latestAccessIntervals) { if (interval.getEndTime().plusDays(28L).isBefore(LocalDateTime.now(clock))) { bookmarkService.removeAllBookmarksOfUser(interval.getUser()); userService.removeAllApplicationsOfUser(interval.getUser()); log.debug("deleted bookmarks and applications of user " + interval.getUser().getId()); } } } @Autowired  ApplicationsAndBookmarkCleaner(UserService userService,
                                          BookmarkService bookmarkService,
                                          AccessIntervalRepository accessIntervalRepo,
                                          Clock clock); @Override void execute(LocalDateTime lastExecuteTime); @Override void execute(); @Override String getJobIdentifier();  }
@Test public void removeOldBookmarksAndApplications() { var firstIntervalEndTime = LocalDateTime.now(clock).minus(29L, ChronoUnit.DAYS); var secondIntervalEndTime = LocalDateTime.now(clock).plus(2L, ChronoUnit.DAYS); given(airMock.findAllLatestIntervals()).willReturn(List.of(accessIntervalMock, accessIntervalMock)); given(accessIntervalMock.getEndTime()).willReturn(firstIntervalEndTime, secondIntervalEndTime); given(accessIntervalMock.getUser()).willReturn(userMock); cleaner.removeOldBookmarksAndApplications(); verify(bookmarkServiceMock).removeAllBookmarksOfUser(userMock); verify(userServiceMock).removeAllApplicationsOfUser(userMock); }