From 573ca0c75cdd7e982e416b32d1821f32f78381df Mon Sep 17 00:00:00 2001 From: NaMinhyeok Date: Tue, 4 Feb 2025 14:52:46 +0900 Subject: [PATCH] =?UTF-8?q?[#31]=20test:=20nested=20=EC=9D=B4=EC=9A=A9=20?= =?UTF-8?q?=EB=B6=84=EA=B8=B0=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/survey/model/SurveyBundleTest.java | 109 +++++++++++------- 1 file changed, 65 insertions(+), 44 deletions(-) diff --git a/jaknaeso-core/src/test/java/org/nexters/jaknaesocore/domain/survey/model/SurveyBundleTest.java b/jaknaeso-core/src/test/java/org/nexters/jaknaesocore/domain/survey/model/SurveyBundleTest.java index 79a1ebaf..08edcd6f 100644 --- a/jaknaeso-core/src/test/java/org/nexters/jaknaesocore/domain/survey/model/SurveyBundleTest.java +++ b/jaknaeso-core/src/test/java/org/nexters/jaknaesocore/domain/survey/model/SurveyBundleTest.java @@ -5,6 +5,7 @@ import java.util.List; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.test.util.ReflectionTestUtils; @@ -50,50 +51,70 @@ void getUnSubmittedSurveyByList_AllSubmitted() { .hasMessage("모든 설문을 완료하셨습니다."); } - @Test - void 모든_설문을_제출했는지_확인한다() { - // given - SurveyBundle surveyBundle = new SurveyBundle(); - - BalanceSurvey survey1 = createBalanceSurvey("대학 동기 모임에서 나의 승진 이야기가 나왔습니다", surveyBundle, 1L); - BalanceSurvey survey2 = createBalanceSurvey("회사에서 팀 리더로 뽑혔습니다", surveyBundle, 2L); - MultipleChoiceSurvey survey3 = createMultipleChoiceSurvey("나의 행복 지수는", surveyBundle, 3L); - MultipleChoiceSurvey survey4 = createMultipleChoiceSurvey("나는 노는게 좋다.", surveyBundle, 4L); - - surveyBundle.getSurveys().addAll(List.of(survey1, survey2, survey3, survey4)); - - SurveySubmission submission1 = SurveySubmission.builder().survey(survey1).build(); - - SurveySubmission submission2 = SurveySubmission.builder().survey(survey2).build(); - - SurveySubmission submission3 = SurveySubmission.builder().survey(survey3).build(); - - SurveySubmission submission4 = SurveySubmission.builder().survey(survey4).build(); - - // when - boolean result = - surveyBundle.isAllSubmitted(List.of(submission1, submission2, submission3, submission4)); - // then - then(result).isTrue(); - } - - @Test - void 모든_설문을_제출했는지_확인한다2() { - // given - SurveyBundle surveyBundle = new SurveyBundle(); - - BalanceSurvey survey1 = createBalanceSurvey("대학 동기 모임에서 나의 승진 이야기가 나왔습니다", surveyBundle, 1L); - BalanceSurvey survey2 = createBalanceSurvey("회사에서 팀 리더로 뽑혔습니다", surveyBundle, 2L); - MultipleChoiceSurvey survey3 = createMultipleChoiceSurvey("나의 행복 지수는", surveyBundle, 3L); - MultipleChoiceSurvey survey4 = createMultipleChoiceSurvey("나는 노는게 좋다.", surveyBundle, 4L); - - surveyBundle.getSurveys().addAll(List.of(survey1, survey2, survey3, survey4)); - - SurveySubmission submission1 = SurveySubmission.builder().survey(survey1).build(); - // when - boolean result = surveyBundle.isAllSubmitted(List.of(submission1)); - // then - then(result).isFalse(); + @Nested + @DisplayName("isAllSubmitted 메서드는") + class isAllSubmitted { + + @Nested + @DisplayName("모든 설문을 제출한 경우") + class whenAllSubmitted { + + @DisplayName("true를 반환한다.") + @Test + void 모든_설문을_제출했는지_확인한다() { + // given + SurveyBundle surveyBundle = new SurveyBundle(); + + BalanceSurvey survey1 = + createBalanceSurvey("대학 동기 모임에서 나의 승진 이야기가 나왔습니다", surveyBundle, 1L); + BalanceSurvey survey2 = createBalanceSurvey("회사에서 팀 리더로 뽑혔습니다", surveyBundle, 2L); + MultipleChoiceSurvey survey3 = createMultipleChoiceSurvey("나의 행복 지수는", surveyBundle, 3L); + MultipleChoiceSurvey survey4 = createMultipleChoiceSurvey("나는 노는게 좋다.", surveyBundle, 4L); + + surveyBundle.getSurveys().addAll(List.of(survey1, survey2, survey3, survey4)); + + SurveySubmission submission1 = SurveySubmission.builder().survey(survey1).build(); + + SurveySubmission submission2 = SurveySubmission.builder().survey(survey2).build(); + + SurveySubmission submission3 = SurveySubmission.builder().survey(survey3).build(); + + SurveySubmission submission4 = SurveySubmission.builder().survey(survey4).build(); + + // when + boolean result = + surveyBundle.isAllSubmitted( + List.of(submission1, submission2, submission3, submission4)); + // then + then(result).isTrue(); + } + } + + @DisplayName("모든 설문을 제출하지 않은 경우") + @Nested + class whenNotAllSubmitted { + + @DisplayName("false를 반환한다.") + @Test + void 모든_설문을_제출했는지_확인한다() { + // given + SurveyBundle surveyBundle = new SurveyBundle(); + + BalanceSurvey survey1 = + createBalanceSurvey("대학 동기 모임에서 나의 승진 이야기가 나왔습니다", surveyBundle, 1L); + BalanceSurvey survey2 = createBalanceSurvey("회사에서 팀 리더로 뽑혔습니다", surveyBundle, 2L); + MultipleChoiceSurvey survey3 = createMultipleChoiceSurvey("나의 행복 지수는", surveyBundle, 3L); + MultipleChoiceSurvey survey4 = createMultipleChoiceSurvey("나는 노는게 좋다.", surveyBundle, 4L); + + surveyBundle.getSurveys().addAll(List.of(survey1, survey2, survey3, survey4)); + + SurveySubmission submission1 = SurveySubmission.builder().survey(survey1).build(); + // when + boolean result = surveyBundle.isAllSubmitted(List.of(submission1)); + // then + then(result).isFalse(); + } + } } private BalanceSurvey createBalanceSurvey(String content, SurveyBundle surveyBundle, Long id) {