@Test public void userHasActiveAccessIntervalReturnsFalseWhenStartDateAndEndDateBeforeToday() { var startDateTime = LocalDateTime.now(clock).minus(3L, ChronoUnit.DAYS); var endDateTime = LocalDateTime.now(clock).minus(2L, ChronoUnit.DAYS); given(userMock.getLatestAccessInterval()).willReturn(Optional.of(accessIntervalMock)); given(accessIntervalMock.getStartTime()).willReturn(startDateTime); given(accessIntervalMock.getEndTime()).willReturn(endDateTime); boolean actualHasAccess = accessService.userHasActiveAccessInterval(userMock); assertThat(actualHasAccess).isFalse(); }
@Override public boolean userHasActiveAccessInterval(User user) { var latestIntervalOptional = user.getLatestAccessInterval(); if(latestIntervalOptional.isPresent()) { var latestInterval = latestIntervalOptional.get(); var startTime = latestInterval.getStartTime(); var endTime = latestInterval.getEndTime(); var now = LocalDateTime.now(clock); return (startTime.isEqual(now) || startTime.isBefore(now)) && (endTime.isEqual(now) || endTime.isAfter(now)); } return false; }
RepositoryUserAccessService implements UserAccessService { @Override public boolean userHasActiveAccessInterval(User user) { var latestIntervalOptional = user.getLatestAccessInterval(); if(latestIntervalOptional.isPresent()) { var latestInterval = latestIntervalOptional.get(); var startTime = latestInterval.getStartTime(); var endTime = latestInterval.getEndTime(); var now = LocalDateTime.now(clock); return (startTime.isEqual(now) || startTime.isBefore(now)) && (endTime.isEqual(now) || endTime.isAfter(now)); } return false; } }
RepositoryUserAccessService implements UserAccessService { @Override public boolean userHasActiveAccessInterval(User user) { var latestIntervalOptional = user.getLatestAccessInterval(); if(latestIntervalOptional.isPresent()) { var latestInterval = latestIntervalOptional.get(); var startTime = latestInterval.getStartTime(); var endTime = latestInterval.getEndTime(); var now = LocalDateTime.now(clock); return (startTime.isEqual(now) || startTime.isBefore(now)) && (endTime.isEqual(now) || endTime.isAfter(now)); } return false; } @Autowired  RepositoryUserAccessService(RepositoryUserService userService,
                                       AccessIntervalRepository intervalRepo,
                                       UserAccessEventHandler userAccessEventHandler,
                                       Clock clock); }
RepositoryUserAccessService implements UserAccessService { @Override public boolean userHasActiveAccessInterval(User user) { var latestIntervalOptional = user.getLatestAccessInterval(); if(latestIntervalOptional.isPresent()) { var latestInterval = latestIntervalOptional.get(); var startTime = latestInterval.getStartTime(); var endTime = latestInterval.getEndTime(); var now = LocalDateTime.now(clock); return (startTime.isEqual(now) || startTime.isBefore(now)) && (endTime.isEqual(now) || endTime.isAfter(now)); } return false; } @Autowired  RepositoryUserAccessService(RepositoryUserService userService,
                                       AccessIntervalRepository intervalRepo,
                                       UserAccessEventHandler userAccessEventHandler,
                                       Clock clock); @Override User giveUserAccessUntil(User user, LocalDateTime until); @Override User removeAccessFromUser(User user); @Override boolean userHasActiveAccessInterval(User user); }
RepositoryUserAccessService implements UserAccessService { @Override public boolean userHasActiveAccessInterval(User user) { var latestIntervalOptional = user.getLatestAccessInterval(); if(latestIntervalOptional.isPresent()) { var latestInterval = latestIntervalOptional.get(); var startTime = latestInterval.getStartTime(); var endTime = latestInterval.getEndTime(); var now = LocalDateTime.now(clock); return (startTime.isEqual(now) || startTime.isBefore(now)) && (endTime.isEqual(now) || endTime.isAfter(now)); } return false; } @Autowired  RepositoryUserAccessService(RepositoryUserService userService,
                                       AccessIntervalRepository intervalRepo,
                                       UserAccessEventHandler userAccessEventHandler,
                                       Clock clock); @Override User giveUserAccessUntil(User user, LocalDateTime until); @Override User removeAccessFromUser(User user); @Override boolean userHasActiveAccessInterval(User user);  }