test_class.declarator: userService
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private RepositoryUserService userService;
test_class.type: RepositoryUserService
test_class.var_name: userService
test_class.declarator: intervalRepo
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private AccessIntervalRepository intervalRepo;
test_class.type: AccessIntervalRepository
test_class.var_name: intervalRepo
test_class.declarator: userAccessEventHandlerMock
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private UserAccessEventHandler userAccessEventHandlerMock;
test_class.type: UserAccessEventHandler
test_class.var_name: userAccessEventHandlerMock
test_class.declarator: userMock
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private User userMock;
test_class.type: User
test_class.var_name: userMock
test_class.declarator: accessIntervalMock
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private AccessInterval accessIntervalMock;
test_class.type: AccessInterval
test_class.var_name: accessIntervalMock
test_class.declarator: clock
test_class.modifier: private
test_class.original_string: private Clock clock;
test_class.type: Clock
test_class.var_name: clock
test_class.declarator: accessService
test_class.modifier: private
test_class.original_string: private RepositoryUserAccessService accessService;
test_class.type: RepositoryUserAccessService
test_class.var_name: accessService
test_class.file: backend/project-board/src/test/java/de/adesso/projectboard/ad/access/RepositoryUserAccessServiceTest.java
test_class.identifier: RepositoryUserAccessServiceTest
test_case.body: @Test
      public void giveUserAccessUntilCreatesAccessWhenUserHasNoAccessInstance() {
          // given
          var expectedStartTime = LocalDateTime.now(clock);
          var expectedEndTime = LocalDateTime.now(clock).plus(10L , ChronoUnit.DAYS);
  
          given(userMock.getLatestAccessInterval()).willReturn(Optional.empty());
          given(userService.save(userMock)).willReturn(userMock);
  
          // when
          var actualUser = accessService.giveUserAccessUntil(userMock, expectedEndTime);
  
          // then
          assertThat(actualUser).isEqualTo(userMock);
  
          var accessInfoArgumentCaptor = ArgumentCaptor.forClass(AccessInterval.class);
          verify(userMock, times(2)).addAccessInterval(accessInfoArgumentCaptor.capture());
          var createdAccessInterval = accessInfoArgumentCaptor.getValue();
  
          var softly = new SoftAssertions();
          softly.assertThat(createdAccessInterval.getUser()).isEqualTo(userMock);
          softly.assertThat(createdAccessInterval.getStartTime()).isEqualTo(expectedStartTime);
          softly.assertThat(createdAccessInterval.getEndTime()).isEqualTo(expectedEndTime);
          softly.assertAll();
  
          verify(userService).save(userMock);
          verify(userAccessEventHandlerMock).onAccessCreated(userMock, createdAccessInterval);
      }
test_case.class_method_signature: RepositoryUserAccessServiceTest.giveUserAccessUntilCreatesAccessWhenUserHasNoAccessInstance()
test_case.full_signature: @Test public void giveUserAccessUntilCreatesAccessWhenUserHasNoAccessInstance()
test_case.identifier: giveUserAccessUntilCreatesAccessWhenUserHasNoAccessInstance
test_case.invocations: now plus now willReturn given getLatestAccessInterval empty willReturn given save giveUserAccessUntil isEqualTo assertThat forClass addAccessInterval verify times capture getValue isEqualTo assertThat getUser isEqualTo assertThat getStartTime isEqualTo assertThat getEndTime assertAll save verify onAccessCreated verify
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void giveUserAccessUntilCreatesAccessWhenUserHasNoAccessInstance()
focal_class.declarator: userService
focal_class.modifier: private final
focal_class.original_string: private final RepositoryUserService userService;
focal_class.type: RepositoryUserService
focal_class.var_name: userService
focal_class.declarator: intervalRepo
focal_class.modifier: private final
focal_class.original_string: private final AccessIntervalRepository intervalRepo;
focal_class.type: AccessIntervalRepository
focal_class.var_name: intervalRepo
focal_class.declarator: userAccessEventHandler
focal_class.modifier: private final
focal_class.original_string: private final UserAccessEventHandler userAccessEventHandler;
focal_class.type: UserAccessEventHandler
focal_class.var_name: userAccessEventHandler
focal_class.declarator: clock
focal_class.modifier: private final
focal_class.original_string: private final Clock clock;
focal_class.type: Clock
focal_class.var_name: clock
focal_class.file: backend/project-board/src/main/java/de/adesso/projectboard/ad/access/RepositoryUserAccessService.java
focal_class.identifier: RepositoryUserAccessService
focal_class.interfaces: implements UserAccessService
focal_class.class_method_signature: RepositoryUserAccessService.RepositoryUserAccessService(RepositoryUserService userService,
                                         AccessIntervalRepository intervalRepo,
                                         UserAccessEventHandler userAccessEventHandler,
                                         Clock clock)
focal_class.full_signature: @Autowired public  RepositoryUserAccessService(RepositoryUserService userService,
                                         AccessIntervalRepository intervalRepo,
                                         UserAccessEventHandler userAccessEventHandler,
                                         Clock clock)
focal_class.identifier: RepositoryUserAccessService
focal_class.modifiers: @Autowired public
focal_class.parameters: (RepositoryUserService userService,
                                         AccessIntervalRepository intervalRepo,
                                         UserAccessEventHandler userAccessEventHandler,
                                         Clock clock)
focal_class.signature:  RepositoryUserAccessService(RepositoryUserService userService,
                                         AccessIntervalRepository intervalRepo,
                                         UserAccessEventHandler userAccessEventHandler,
                                         Clock clock)
focal_class.class_method_signature: RepositoryUserAccessService.giveUserAccessUntil(User user, LocalDateTime until)
focal_class.full_signature: @Override public User giveUserAccessUntil(User user, LocalDateTime until)
focal_class.identifier: giveUserAccessUntil
focal_class.modifiers: @Override public
focal_class.parameters: (User user, LocalDateTime until)
focal_class.return: User
focal_class.signature: User giveUserAccessUntil(User user, LocalDateTime until)
focal_class.class_method_signature: RepositoryUserAccessService.removeAccessFromUser(User user)
focal_class.full_signature: @Override public User removeAccessFromUser(User user)
focal_class.identifier: removeAccessFromUser
focal_class.modifiers: @Override public
focal_class.parameters: (User user)
focal_class.return: User
focal_class.signature: User removeAccessFromUser(User user)
focal_class.class_method_signature: RepositoryUserAccessService.userHasActiveAccessInterval(User user)
focal_class.full_signature: @Override public boolean userHasActiveAccessInterval(User user)
focal_class.identifier: userHasActiveAccessInterval
focal_class.modifiers: @Override public
focal_class.parameters: (User user)
focal_class.return: boolean
focal_class.signature: boolean userHasActiveAccessInterval(User user)
focal_method.body: @Override
      public User giveUserAccessUntil(User user, LocalDateTime until) throws IllegalArgumentException {
          if(until.isBefore(LocalDateTime.now(clock))) {
              throw new IllegalArgumentException("End date must lie in the future!");
          }
  
          var latestIntervalOptional = user.getLatestAccessInterval();
  
          if(latestIntervalOptional.isEmpty() || !userHasActiveAccessInterval(user)) {
              var interval = new AccessInterval(user, LocalDateTime.now(clock), until);
              user.addAccessInterval(interval);
  
              userAccessEventHandler.onAccessCreated(user, interval);
  
              return userService.save(user);
          } else {
              var latestInterval = latestIntervalOptional.get();
              var oldEndTime = latestInterval.getEndTime();
              if(oldEndTime.isEqual(until)) {
                  return user;
              }
  
              latestInterval.setEndTime(until);
              intervalRepo.save(latestInterval);
  
              userAccessEventHandler.onAccessChanged(user, latestInterval, oldEndTime);
          }
  
          return user;
      }
focal_method.class_method_signature: RepositoryUserAccessService.giveUserAccessUntil(User user, LocalDateTime until)
focal_method.full_signature: @Override public User giveUserAccessUntil(User user, LocalDateTime until)
focal_method.identifier: giveUserAccessUntil
focal_method.invocations: isBefore now getLatestAccessInterval isEmpty userHasActiveAccessInterval now addAccessInterval onAccessCreated save get getEndTime isEqual setEndTime save onAccessChanged
focal_method.modifiers: @Override public
focal_method.parameters: (User user, LocalDateTime until)
focal_method.return: User
focal_method.signature: User giveUserAccessUntil(User user, LocalDateTime until)