1717import dmu .dasom .api .domain .recruit .enums .ResultCheckType ;
1818import dmu .dasom .api .domain .recruit .repository .RecruitRepository ;
1919import dmu .dasom .api .domain .recruit .service .RecruitServiceImpl ;
20+ import dmu .dasom .api .global .generation .service .GenerationService ;
2021import org .junit .jupiter .api .DisplayName ;
2122import org .junit .jupiter .api .Test ;
2223import org .junit .jupiter .api .extension .ExtendWith ;
3334
3435import static org .junit .jupiter .api .Assertions .*;
3536import static org .mockito .Mockito .*;
36- import static org .mockito .Mockito .mock ;
3737
3838@ ExtendWith (MockitoExtension .class )
3939class RecruitServiceTest {
@@ -47,6 +47,9 @@ class RecruitServiceTest {
4747 @ Mock
4848 private InterviewServiceImpl interviewService ;
4949
50+ @ Mock
51+ private GenerationService generationService ;
52+
5053 @ InjectMocks
5154 private RecruitServiceImpl recruitService ;
5255
@@ -56,32 +59,42 @@ void getRecruitSchedule() {
5659 // given
5760 Recruit recruit1 = mock (Recruit .class );
5861 Recruit recruit2 = mock (Recruit .class );
59- when (recruitRepository .findAll ()).thenReturn (List .of (recruit1 , recruit2 ));
62+ Recruit recruit3 = mock (Recruit .class );
63+ when (recruitRepository .findAll ()).thenReturn (List .of (recruit1 , recruit2 , recruit3 ));
64+ when (recruit1 .getKey ()).thenReturn (ConfigKey .RECRUITMENT_PERIOD_START );
65+ when (recruit2 .getKey ()).thenReturn (ConfigKey .RECRUITMENT_PERIOD_END );
66+ when (recruit3 .getKey ()).thenReturn (ConfigKey .GENERATION );
67+ when (generationService .getCurrentGeneration ()).thenReturn ("34기" );
6068
6169 // when
6270 List <RecruitConfigResponseDto > schedule = recruitService .getRecruitSchedule ();
6371
6472 // then
6573 assertNotNull (schedule );
66- assertEquals (2 , schedule .size ());
74+ assertEquals (3 , schedule .size ());
6775 verify (recruitRepository , times (1 )).findAll ();
76+ verify (generationService , times (1 )).getCurrentGeneration ();
6877 }
6978
7079 @ Test
7180 @ DisplayName ("모집 일정 수정 - 성공" )
7281 void modifyRecruitSchedule_success () {
7382 // given
7483 Recruit recruit = mock (Recruit .class );
84+ Recruit generationRecruit = mock (Recruit .class );
7585 RecruitScheduleModifyRequestDto request = mock (RecruitScheduleModifyRequestDto .class );
7686 when (request .getKey ()).thenReturn (ConfigKey .RECRUITMENT_PERIOD_START );
7787 when (request .getValue ()).thenReturn ("2025-01-02T12:00:00" );
7888 when (recruitRepository .findByKey (ConfigKey .RECRUITMENT_PERIOD_START )).thenReturn (Optional .of (recruit ));
89+ when (recruitRepository .findByKey (ConfigKey .GENERATION )).thenReturn (Optional .of (generationRecruit ));
90+ when (generationService .getCurrentGeneration ()).thenReturn ("34기" );
7991
8092 // when
8193 recruitService .modifyRecruitSchedule (request );
8294
8395 // then
8496 verify (recruit , times (1 )).updateDateTime (LocalDateTime .of (2025 , 1 , 2 , 12 , 0 , 0 ));
97+ verify (generationRecruit , times (1 )).updateGeneration ("34기" );
8598 }
8699
87100 @ Test
@@ -196,4 +209,42 @@ void reserveInterviewSlot_fail_alreadyReserved() {
196209 assertEquals (ErrorCode .ALREADY_RESERVED , exception .getErrorCode ());
197210 }
198211
199- }
212+ @ Test
213+ @ DisplayName ("기수 정보 조회" )
214+ void getGenerationInfo () {
215+ // given
216+ Recruit generationRecruit = mock (Recruit .class );
217+ when (recruitRepository .findAll ()).thenReturn (List .of (generationRecruit ));
218+ when (generationRecruit .getKey ()).thenReturn (ConfigKey .GENERATION );
219+ when (generationService .getCurrentGeneration ()).thenReturn ("34기" );
220+
221+ // when
222+ List <RecruitConfigResponseDto > schedule = recruitService .getRecruitSchedule ();
223+ boolean generationFound = schedule .stream ()
224+ .anyMatch (dto -> dto .getKey () == ConfigKey .GENERATION );
225+
226+ // then
227+ assertTrue (generationFound );
228+ verify (generationService , times (1 )).getCurrentGeneration ();
229+ }
230+
231+ @ Test
232+ @ DisplayName ("기수 정보 수정" )
233+ void modifyGenerationInfo () {
234+ // given
235+ Recruit generationRecruit = mock (Recruit .class );
236+ RecruitScheduleModifyRequestDto request = mock (RecruitScheduleModifyRequestDto .class );
237+ when (request .getKey ()).thenReturn (ConfigKey .RECRUITMENT_PERIOD_START );
238+ when (request .getValue ()).thenReturn ("2025-01-02T12:00:00" );
239+ when (recruitRepository .findByKey (ConfigKey .RECRUITMENT_PERIOD_START )).thenReturn (Optional .of (mock (Recruit .class )));
240+ when (recruitRepository .findByKey (ConfigKey .GENERATION )).thenReturn (Optional .of (generationRecruit ));
241+ when (generationService .getCurrentGeneration ()).thenReturn ("34기" );
242+
243+ // when
244+ recruitService .modifyRecruitSchedule (request );
245+
246+ // then
247+ verify (generationRecruit , times (1 )).updateGeneration ("34기" );
248+ }
249+
250+ }
0 commit comments