@@ -35,15 +35,16 @@ class SomParticipantServiceTest {
3535 @ Test
3636 @ DisplayName ("참가자 생성 - 성공" )
3737 void createParticipant_success () {
38- SomParticipantRequestDto request = new SomParticipantRequestDto ();
39- request .setParticipantName ("홍길동" );
40- request .setStudentId ("20250001" );
41- request .setDepartment ("컴퓨터공학과" );
42- request .setGrade ("3" );
43- request .setContact ("010-1234-5678" );
44- request .
setEmail (
"[email protected] " );
45- request .setGithubLink ("https://github.com/username" );
46- request .setPortfolioLink ("https://drive.google.com/file" );
38+ SomParticipantRequestDto request = SomParticipantRequestDto .builder ()
39+ .participantName ("홍길동" )
40+ .studentId ("20250001" )
41+ .department ("컴퓨터공학과" )
42+ .grade ("3" )
43+ .contact ("010-1234-5678" )
44+ 45+ .githubLink ("https://github.com/username" )
46+ .portfolioLink ("https://drive.google.com/file" )
47+ .build ();
4748
4849 when (repository .findByStudentId ("20250001" )).thenReturn (Optional .empty ());
4950 when (repository .save (any (SomParticipant .class ))).thenAnswer (invocation -> invocation .getArgument (0 ));
@@ -67,8 +68,9 @@ void createParticipant_success() {
6768 @ Test
6869 @ DisplayName ("참가자 생성 - 실패 (학생ID 중복)" )
6970 void createParticipant_fail_duplicateStudentId () {
70- SomParticipantRequestDto request = new SomParticipantRequestDto ();
71- request .setStudentId ("20250001" );
71+ SomParticipantRequestDto request = SomParticipantRequestDto .builder ()
72+ .studentId ("20250001" )
73+ .build ();
7274
7375 when (repository .findByStudentId ("20250001" )).thenReturn (Optional .of (mock (SomParticipant .class )));
7476
@@ -111,10 +113,8 @@ void getAllParticipants_success() {
111113 List <SomParticipantResponseDto > list = service .getAllParticipants ();
112114
113115 assertEquals (2 , list .size ());
114-
115116 assertEquals ("홍길동" , list .get (0 ).getParticipantName ());
116117 assertEquals ("김철수" , list .get (1 ).getParticipantName ());
117-
118118 assertEquals ("https://github.com/hong" , list .get (0 ).getGithubLink ());
119119 assertEquals ("https://notion.site" , list .get (1 ).getPortfolioLink ());
120120
@@ -156,6 +156,65 @@ void getParticipant_fail_notFound() {
156156 verify (repository , times (1 )).findById (1L );
157157 }
158158
159+ // =======================
160+ // Put Tests
161+ // =======================
162+ @ Test
163+ @ DisplayName ("참가자 수정 - 성공" )
164+ void updateParticipant_success () {
165+ SomParticipant existing = SomParticipant .builder ()
166+ .participantName ("홍길동" )
167+ .studentId ("20250001" )
168+ .department ("컴퓨터공학과" )
169+ .grade ("3" )
170+ .contact ("010-1234-5678" )
171+ 172+ .githubLink ("https://github.com/username" )
173+ .portfolioLink ("https://drive.google.com/file" )
174+ .build ();
175+
176+ SomParticipantRequestDto updateRequest = SomParticipantRequestDto .builder ()
177+ .participantName ("홍길동2" )
178+ .studentId ("20250001" )
179+ .department ("소프트웨어공학과" )
180+ .grade ("4" )
181+ .contact ("010-1111-2222" )
182+ 183+ .githubLink ("https://github.com/username2" )
184+ .portfolioLink ("https://drive.google.com/file2" )
185+ .build ();
186+
187+ when (repository .findById (1L )).thenReturn (Optional .of (existing ));
188+
189+ SomParticipantResponseDto response = service .updateParticipant (1L , updateRequest );
190+
191+ assertEquals ("홍길동2" , response .getParticipantName ());
192+ assertEquals ("20250001" , response .getStudentId ());
193+ assertEquals ("소프트웨어공학과" , response .getDepartment ());
194+ assertEquals ("4" , response .getGrade ());
195+ assertEquals ("010-1111-2222" , response .getContact ());
196+ assertEquals (
"[email protected] " ,
response .
getEmail ());
197+ assertEquals ("https://github.com/username2" , response .getGithubLink ());
198+ assertEquals ("https://drive.google.com/file2" , response .getPortfolioLink ());
199+
200+ verify (repository , times (1 )).findById (1L );
201+ }
202+
203+ @ Test
204+ @ DisplayName ("참가자 수정 - 실패 (없음)" )
205+ void updateParticipant_fail_notFound () {
206+ SomParticipantRequestDto updateRequest = SomParticipantRequestDto .builder ()
207+ .participantName ("홍길동2" )
208+ .build ();
209+
210+ when (repository .findById (1L )).thenReturn (Optional .empty ());
211+
212+ CustomException exception = assertThrows (CustomException .class , () -> service .updateParticipant (1L , updateRequest ));
213+ assertEquals (ErrorCode .NOT_FOUND_PARTICIPANT , exception .getErrorCode ());
214+
215+ verify (repository , times (1 )).findById (1L );
216+ }
217+
159218 // =======================
160219 // Delete Tests
161220 // =======================
0 commit comments