### Question:
UserApiService { public void preCreateUser(String userId, String passWd, String confirmPassWd) { UserEntity dbInfo = userRepository.findByUserId(userId); if (dbInfo != null) { throw new AlreadyUsernameException("이미 등록된 유저 입니다."); } if (StringUtils.equals(passWd, confirmPassWd) == false) { throw new IllegalArgumentException("비밀번호가 일치하지 않습니다."); } }  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 = AlreadyUsernameException.class) public void 유저생성_이미_존재하는_유저() { GIVEN: { UserEntity mockDbInfo = UserEntity.builder().userId(mockUserId).passWd("test").build(); given(userRepository.findByUserId(mockUserId)).willReturn(mockDbInfo); } WHEN: { userApiService.preCreateUser(mockUserId, mockPassWd, mockPassWd); } }
@Test(expected = IllegalArgumentException.class) public void 유저생성_패스워드잘못됨() { String confirmPassWd = mockPassWd + "1"; GIVEN: { given(userRepository.findByUserId(mockUserId)).willReturn(null); } WHEN: { userApiService.preCreateUser(mockUserId, mockPassWd, confirmPassWd); } }