### Question:
UserApiService { public UserDetails getUserDetails(String userId, String passWd) { UserDetails userInfo = simpleUserDetailsService.loadUserByUsername(userId); if (passwordEncoder.matches(passWd, userInfo.getPassword()) == false) { throw new BadCredentialsException("비밀번호가 일치하지 않습니다."); } return userInfo; }  UserDetails getUserDetails(String userId, String passWd); String generatorToken(UserDetails details); void preCreateUser(String userId, String passWd, String confirmPassWd); @Transactional void createUser(String userId, String passWd);  }### Answer:
@Test(expected = BadCredentialsException.class) public void 유저정보가져오기_서비스테스트_비밀번호실패() { GIVEN: { UserDetails userDetails = new User(mockUserId, mockPassWd, SecUtils.mapToGrantedAuthorities(Arrays.asList(AuthorityCd.USER.roleCd()))); given(simpleUserDetailsService.loadUserByUsername(mockUserId)).willReturn(userDetails); } WHEN: { userApiService.getUserDetails(mockUserId, mockPassWd); } }
@Test public void 유저정보가져오기_서비스테스트_성공() { GIVEN: { UserDetails userDetails = new User(mockUserId, passwordEncoder.encode(mockPassWd), SecUtils.mapToGrantedAuthorities(Arrays.asList(AuthorityCd.USER.roleCd()))); given(simpleUserDetailsService.loadUserByUsername(mockUserId)).willReturn(userDetails); } UserDetails details; WHEN: { details = userApiService.getUserDetails(mockUserId, mockPassWd); } THEN: { assertNotNull(details); assertEquals(mockUserId, details.getUsername()); } }