From f194cfea682b8d3e6cb8d5ff059bede760fd133c Mon Sep 17 00:00:00 2001 From: seunghye218 Date: Tue, 6 Aug 2024 17:12:54 +0900 Subject: [PATCH] =?UTF-8?q?test:=20AvailableDates=20=EB=B0=8F=20TimeslotIn?= =?UTF-8?q?terval=20=EC=B6=94=EA=B0=80=EB=90=9C=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=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 --- .../availabledate/AvailableDatesTest.java | 44 +++++++++++++++++++ .../domain/timeslot/TimeslotIntervalTest.java | 25 +++++++++++ 2 files changed, 69 insertions(+) diff --git a/backend/src/test/java/kr/momo/domain/availabledate/AvailableDatesTest.java b/backend/src/test/java/kr/momo/domain/availabledate/AvailableDatesTest.java index 597e17889..da08b58e1 100644 --- a/backend/src/test/java/kr/momo/domain/availabledate/AvailableDatesTest.java +++ b/backend/src/test/java/kr/momo/domain/availabledate/AvailableDatesTest.java @@ -6,6 +6,7 @@ import java.time.LocalDate; import java.util.List; +import java.util.stream.Stream; import kr.momo.domain.meeting.Meeting; import kr.momo.exception.MomoException; import kr.momo.exception.code.AvailableDateErrorCode; @@ -13,7 +14,9 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.MethodSource; class AvailableDatesTest { @@ -98,4 +101,45 @@ void isAnyBefore(int plusDays1, int plusDays2, int plusDays3, boolean expected) assertThat(result).isEqualTo(expected); } + + @DisplayName("start일자부터 end일 사이의 모든 날짜가 가능한 날짜인지 확인한다.") + @ParameterizedTest + @MethodSource("isNotConsecutiveDayProvider") + void isNotConsecutiveDay(List dates, LocalDate startDate, LocalDate endDate, boolean expected) { + AvailableDates availableDates = new AvailableDates(dates, null); + + boolean actual = availableDates.isNotConsecutiveDay(startDate, endDate); + + assertThat(actual).isEqualTo(expected); + } + + private static Stream isNotConsecutiveDayProvider() { + return Stream.of( + Arguments.of( + List.of( + LocalDate.of(2024, 8, 1), + LocalDate.of(2024, 8, 2), + LocalDate.of(2024, 8, 3) + ), + LocalDate.of(2024, 8, 1), + LocalDate.of(2024, 8, 3), + false), + Arguments.of( + List.of( + LocalDate.of(2024, 8, 1), + LocalDate.of(2024, 8, 3) + ), + LocalDate.of(2024, 8, 1), + LocalDate.of(2024, 8, 3), + true), + Arguments.of( + List.of( + LocalDate.of(2024, 8, 2), + LocalDate.of(2024, 8, 3) + ), + LocalDate.of(2024, 8, 1), + LocalDate.of(2024, 8, 3), + true) + ); + } } diff --git a/backend/src/test/java/kr/momo/domain/timeslot/TimeslotIntervalTest.java b/backend/src/test/java/kr/momo/domain/timeslot/TimeslotIntervalTest.java index 62377b28c..ae841558d 100644 --- a/backend/src/test/java/kr/momo/domain/timeslot/TimeslotIntervalTest.java +++ b/backend/src/test/java/kr/momo/domain/timeslot/TimeslotIntervalTest.java @@ -5,10 +5,14 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.time.LocalTime; +import java.util.stream.Stream; import kr.momo.exception.MomoException; import kr.momo.exception.code.ScheduleErrorCode; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; class TimeslotIntervalTest { @@ -40,4 +44,25 @@ public void successfulCreationForSameStartAndEndTime() { assertThatNoException() .isThrownBy(() -> new TimeslotInterval(LocalTime.of(23, 30), LocalTime.of(23, 30))); } + + @DisplayName("주어진 시작 시간, 끝 시간이 포함되어 있는지 확인한다.") + @ParameterizedTest + @MethodSource("isTimeInRangeProvider") + void isTimeInRange(LocalTime startTime, LocalTime endTime, boolean expected) { + TimeslotInterval timeslotInterval = new TimeslotInterval(Timeslot.TIME_0100, Timeslot.TIME_0200); + + boolean actual = timeslotInterval.isTimeInRange(startTime, endTime); + + assertThat(actual).isEqualTo(expected); + } + + private static Stream isTimeInRangeProvider() { + return Stream.of( + Arguments.of( + LocalTime.of(1, 0), + LocalTime.of(2, 30), true), + Arguments.of( + LocalTime.of(2, 0), + LocalTime.of(3, 0), false)); + } }