Skip to content

Commit cef8f3d

Browse files
committed
test: 변경된 저장 로직에 따라 테스트 케이스 구현
1 parent a6f1e91 commit cef8f3d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/test/java/dmu/dasom/api/domain/applicant/ApplicantServiceTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.springframework.data.domain.PageRequest;
2020

2121
import java.util.Collections;
22+
import java.util.Optional;
2223

2324
import static org.junit.jupiter.api.Assertions.*;
2425
import static org.mockito.Mockito.*;
@@ -37,6 +38,8 @@ class ApplicantServiceTest {
3738
void apply_success() {
3839
// given
3940
ApplicantCreateRequestDto request = mock(ApplicantCreateRequestDto.class);
41+
when(request.getStudentNo()).thenReturn("20210000");
42+
when(applicantRepository.findByStudentNo("20210000")).thenReturn(Optional.empty());
4043

4144
// when
4245
applicantService.apply(request);
@@ -48,6 +51,38 @@ void apply_success() {
4851
@Test
4952
@DisplayName("지원자 저장 - 실패")
5053
void apply_fail() {
54+
// given
55+
ApplicantCreateRequestDto request = mock(ApplicantCreateRequestDto.class);
56+
when(request.getStudentNo()).thenReturn("20210000");
57+
when(applicantRepository.findByStudentNo("20210000")).thenReturn(Optional.of(mock(Applicant.class)));
58+
when(request.getIsOverwriteConfirmed()).thenReturn(false);
59+
60+
// when
61+
CustomException exception = assertThrows(CustomException.class, () -> {
62+
applicantService.apply(request);
63+
});
64+
65+
// then
66+
verify(applicantRepository).findByStudentNo("20210000");
67+
assertEquals(ErrorCode.DUPLICATED_STUDENT_NO, exception.getErrorCode());
68+
}
69+
70+
@Test
71+
@DisplayName("지원자 저장 - 덮어쓰기")
72+
void apply_overwrite() {
73+
// given
74+
ApplicantCreateRequestDto request = mock(ApplicantCreateRequestDto.class);
75+
when(request.getStudentNo()).thenReturn("20210000");
76+
Applicant applicant = mock(Applicant.class);
77+
when(applicantRepository.findByStudentNo("20210000")).thenReturn(Optional.of(applicant));
78+
when(request.getIsOverwriteConfirmed()).thenReturn(true);
79+
80+
// when
81+
applicantService.apply(request);
82+
83+
// then
84+
verify(applicantRepository).findByStudentNo("20210000");
85+
verify(applicant).overwrite(request);
5186
}
5287

5388
@Test

0 commit comments

Comments
 (0)