2222import java .time .LocalDateTime ;
2323import java .util .List ;
2424
25- import static grep .neogulcoder .domain .study .enums .StudyMemberRole .LEADER ;
26- import static grep .neogulcoder .domain .study .enums .StudyMemberRole .MEMBER ;
25+ import static grep .neogulcoder .domain .study .enums .StudyMemberRole .*;
2726import static grep .neogulcoder .domain .studyapplication .ApplicationStatus .*;
28- import static grep .neogulcoder .domain .studyapplication .exception .code .ApplicationErrorCode .APPLICATION_NOT_APPLYING ;
27+ import static grep .neogulcoder .domain .studyapplication .exception .code .ApplicationErrorCode .* ;
2928import static org .assertj .core .api .Assertions .assertThat ;
3029import static org .assertj .core .api .Assertions .assertThatThrownBy ;
3130
@@ -96,6 +95,29 @@ void createApplication() {
9695 assertThat (application .getApplicationReason ()).isEqualTo ("자바를 더 공부하고 싶어 지원합니다." );
9796 }
9897
98+ @ DisplayName ("종료되지 않은 스터디를 10개를 진행중일 때 신청서 생성 시 예외가 발생합니다." )
99+ @ Test
100+ void createApplicationFail () {
101+ // given
102+ ApplicationCreateRequest request = ApplicationCreateRequest .builder ()
103+ .applicationReason ("자바를 더 공부하고 싶어 지원합니다." )
104+ .build ();
105+
106+ for (int i = 0 ; i < 9 ; i ++) {
107+ Study study = createStudy ("스터디" , LocalDateTime .parse ("2025-07-25T20:20:20" ), LocalDateTime .parse ("2026-07-28T20:20:20" ));
108+ studyRepository .save (study );
109+ StudyMember studyLeader = createStudyLeader (study , userId2 );
110+ studyMemberRepository .save (studyLeader );
111+ em .flush ();
112+ em .clear ();
113+ }
114+
115+ // when then
116+ assertThatThrownBy (() ->
117+ applicationService .createApplication (recruitmentPostId , request , userId2 ))
118+ .isInstanceOf (BusinessException .class ).hasMessage (APPLICATION_PARTICIPATION_LIMIT_EXCEEDED .getMessage ());
119+ }
120+
99121 @ DisplayName ("스터디장이 신청서를 승인합니다." )
100122 @ Test
101123 void approveApplication () {
@@ -113,6 +135,29 @@ void approveApplication() {
113135 assertThat (application .getStatus ()).isEqualTo (APPROVED );
114136 }
115137
138+ @ DisplayName ("참여 중인 스터디가 10개인 사용자의 신청서 승인 시 예외가 발생합니다." )
139+ @ Test
140+ void approveApplicationFail () {
141+ // given
142+ StudyApplication application = createApplication (recruitmentPostId , userId2 );
143+ applicationRepository .save (application );
144+ Long id = application .getId ();
145+
146+ for (int i = 0 ; i < 9 ; i ++) {
147+ Study study = createStudy ("스터디" , LocalDateTime .parse ("2025-07-25T20:20:20" ), LocalDateTime .parse ("2026-07-28T20:20:20" ));
148+ studyRepository .save (study );
149+ StudyMember studyLeader = createStudyLeader (study , userId2 );
150+ studyMemberRepository .save (studyLeader );
151+ em .flush ();
152+ em .clear ();
153+ }
154+
155+ // when then
156+ assertThatThrownBy (() ->
157+ applicationService .approveApplication (id , userId1 ))
158+ .isInstanceOf (BusinessException .class ).hasMessage (APPLICATION_PARTICIPANT_LIMIT_EXCEEDED .getMessage ());
159+ }
160+
116161 @ DisplayName ("스터디장이 신청서를 거절합니다." )
117162 @ Test
118163 void rejectApplication () {
0 commit comments