Skip to content

Commit

Permalink
test: 회원가입 중복으로 인한 실패 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
9898s committed Nov 8, 2023
1 parent a70084d commit f82999c
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.snsIntegrationFeedService.user.service;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import java.util.Optional;
Expand All @@ -13,6 +14,8 @@

import com.snsIntegrationFeedService.certificateCode.entity.CertificateCode;
import com.snsIntegrationFeedService.certificateCode.repository.CertificateCodeRepository;
import com.snsIntegrationFeedService.common.error.CustomErrorCode;
import com.snsIntegrationFeedService.common.exception.CustomException;
import com.snsIntegrationFeedService.user.dto.SignupRequestDto;
import com.snsIntegrationFeedService.user.entity.User;
import com.snsIntegrationFeedService.user.repository.UserRepository;
Expand Down Expand Up @@ -57,4 +60,31 @@ class UserServiceTest {
verify(userRepository).save(any(User.class));
verify(certificateCodeRepository).save(any(CertificateCode.class));
}

@Test
void 회원_실패_중복_test() throws Exception {
// given
SignupRequestDto signupRequestDto = SignupRequestDto.builder()
.account("test")
.email("test@test.com")
.password("test123")
.build();

User user = User.builder()
.account("test")
.email("test@test.com")
.password("test123")
.build();

// stub 1
when(userRepository.findByAccount(any())).thenReturn(Optional.of(user));

// when
CustomException exception = assertThrows(CustomException.class, () -> {
userService.signup(signupRequestDto);
});

// then
assertEquals(CustomErrorCode.USER_ALREADY_EXIST, exception.getErrorCode());
}
}

0 comments on commit f82999c

Please sign in to comment.