### Question:
SimpleUserDetailsService implements UserDetailsService { @Override public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException { UserEntity dbUserInfo = userRepository.findByUserId(userId); if (dbUserInfo == null) { throw new UsernameNotFoundException("NOT Found User"); } List<UserAuthEntity> authList = userAuthRepository.findByUserId(userId); if (authList.isEmpty()) { throw new UsernameNotFoundException("계정 내 권한이 없습니다."); } return new User(dbUserInfo.getUserId(), dbUserInfo.getPassWd(), SecUtils.mapToGrantedAuthorities(authList.stream().map(userAuthEntity -> userAuthEntity.getAuthorityCd()).collect(Collectors.toList()))); }  @Override UserDetails loadUserByUsername(String userId);  }### Answer:
@Test(expected = UsernameNotFoundException.class) public void 유저정보조회관련_계정정보없음() { final String mockUserId = "akageun"; given(userRepository.findByUserId(mockUserId)).willReturn(null); simpleUserDetailsService.loadUserByUsername(mockUserId); }
@Test(expected = UsernameNotFoundException.class) public void 유저정보조회관련_권한없음() { final String mockUserId = "akageun"; UserEntity mockDbInfo = UserEntity.builder() .userId(mockUserId) .passWd("test") .build(); given(userRepository.findByUserId(mockUserId)).willReturn(mockDbInfo); given(userAuthRepository.findByUserId(mockUserId)).willReturn(Collections.emptyList()); simpleUserDetailsService.loadUserByUsername(mockUserId); }
@Test public void 유저정보조회관련_성공() { final String mockUserId = "akageun"; UserEntity mockDbInfo = UserEntity.builder() .userId(mockUserId) .passWd("test") .build(); List<UserAuthEntity> mockAuthList = Arrays.asList(UserAuthEntity.builder().authorityCd(AuthorityCd.USER.roleCd()).build()); given(userRepository.findByUserId(mockUserId)).willReturn(mockDbInfo); given(userAuthRepository.findByUserId(mockUserId)).willReturn(mockAuthList); UserDetails userDetails = simpleUserDetailsService.loadUserByUsername(mockUserId); assertNotNull(userDetails); assertEquals(mockDbInfo.getUserId(), userDetails.getUsername()); assertFalse(userDetails.getAuthorities().isEmpty()); }