From 52cb71e345bdeef87f09b4a81113acbd51c8ea7d Mon Sep 17 00:00:00 2001 From: donghyunkim Date: Wed, 29 May 2024 22:00:44 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20checkstyle=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cafe/BusinessHourOpenCheckerTest.java | 964 +++++++++--------- 1 file changed, 482 insertions(+), 482 deletions(-) diff --git a/src/test/java/com/example/demo/domain/cafe/BusinessHourOpenCheckerTest.java b/src/test/java/com/example/demo/domain/cafe/BusinessHourOpenCheckerTest.java index e477a97..1f4a8f8 100644 --- a/src/test/java/com/example/demo/domain/cafe/BusinessHourOpenCheckerTest.java +++ b/src/test/java/com/example/demo/domain/cafe/BusinessHourOpenCheckerTest.java @@ -1,11 +1,6 @@ package com.example.demo.domain.cafe; -import com.example.demo.exception.CafegoryException; -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; +import static org.assertj.core.api.Assertions.*; import java.time.DayOfWeek; import java.time.LocalDateTime; @@ -14,234 +9,239 @@ import java.util.List; import java.util.stream.Stream; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +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; + +import com.example.demo.exception.CafegoryException; public class BusinessHourOpenCheckerTest { - private BusinessHourOpenChecker openChecker = new BusinessHourOpenChecker(); - - @Test - @DisplayName("현재시간이 요일에 맞는 영업시간에 포함하면 open이다") - void contains_Nowtime_Then_Open() { - //given - LocalDateTime now = LocalDateTime.of(2024, 1, 29, 12, 0, 0); - DayOfWeek dayOfWeek = now.getDayOfWeek(); - LocalTime startTime = LocalTime.of(9, 0); - LocalTime endTime = LocalTime.of(21, 0); - //when - boolean isOpen = openChecker.checkByNowTime(dayOfWeek, startTime, endTime, now); - //then - assertThat(isOpen).isTrue(); - } - - @Test - @DisplayName("현재시간이 요일에 맞는 영업 시작시간이랑 일치하면 open이다") - void when_NowTime_Is_StartTime_Then_Open() { - //given - LocalDateTime now = LocalDateTime.of(2024, 1, 29, 9, 0, 0); - DayOfWeek dayOfWeek = now.getDayOfWeek(); - LocalTime startTime = LocalTime.of(9, 0); - LocalTime endTime = LocalTime.of(21, 0); - //when - boolean isOpen = openChecker.checkByNowTime(dayOfWeek, startTime, endTime, now); - //then - assertThat(isOpen).isTrue(); - } - - @Test - @DisplayName("현재시간이 요일에 맞는 영업 종료시작이랑 일치하면 close이다") - void when_NowTime_Is_EndTime_Then_Close() { - //given - LocalDateTime now = LocalDateTime.of(2024, 1, 29, 21, 0, 0); - DayOfWeek dayOfWeek = now.getDayOfWeek(); - LocalTime startTime = LocalTime.of(9, 0); - LocalTime endTime = LocalTime.of(21, 0); - //when - boolean isOpen = openChecker.checkByNowTime(dayOfWeek, startTime, endTime, now); - //then - assertThat(isOpen).isFalse(); - } - - @Test - @DisplayName("현재시간이 요일에 맞는 영업 종료시간 1초전이라면 open이다") - void when_NowTime_Is_EndTime_Before_1Sec_Then_Close() { - //given - LocalDateTime now = LocalDateTime.of(2024, 1, 29, 20, 59, 59); - DayOfWeek dayOfWeek = now.getDayOfWeek(); - LocalTime startTime = LocalTime.of(9, 0); - LocalTime endTime = LocalTime.of(21, 0); - //when - boolean isOpen = openChecker.checkByNowTime(dayOfWeek, startTime, endTime, now); - //then - assertThat(isOpen).isTrue(); - } - - @ParameterizedTest - @MethodSource("provideLocalDateTime") - @DisplayName("BusinessHours를 가지고 영업시간을 체크한다.") - void checkWithBusinessHours(LocalDateTime now, boolean expected) { - List businessHours = new ArrayList<>(); - - BusinessHour monday = BusinessHour.builder() - .day("MONDAY") - .startTime(LocalTime.of(9, 0)) - .endTime(LocalTime.of(21, 0)) - .build(); - BusinessHour tuesday = BusinessHour.builder() - .day("TUESDAY") - .startTime(LocalTime.of(9, 0)) - .endTime(LocalTime.of(21, 0)) - .build(); - BusinessHour wednesday = BusinessHour.builder() - .day("WEDNESDAY") - .startTime(LocalTime.of(9, 0)) - .endTime(LocalTime.of(21, 0)) - .build(); - - businessHours.add(monday); - businessHours.add(tuesday); - businessHours.add(wednesday); - - //when - boolean isOpen = openChecker.checkWithBusinessHours(businessHours, now); - //then - assertThat(isOpen).isEqualTo(expected); - } - - private static Stream provideLocalDateTime() { - return Stream.of( - // LocalDateTime now, boolean expected - Arguments.of(LocalDateTime.of(2024, 1, 29, 12, 30, 0), true), - Arguments.of(LocalDateTime.of(2024, 1, 31, 8, 30, 0), false) - ); - } - - @ParameterizedTest - @MethodSource("provideLocalDateTime2") - @DisplayName("카페가 24시간 운영한다.") - void check_businessHours_when_cafe_is_always_open(LocalDateTime now, boolean expected) { - List businessHours = new ArrayList<>(); - - BusinessHour monday = BusinessHour.builder() - .day("MONDAY") - .startTime(LocalTime.of(0, 0)) - .endTime(LocalTime.MAX) - .build(); - BusinessHour tuesday = BusinessHour.builder() - .day("TUESDAY") - .startTime(LocalTime.of(0, 0)) - .endTime(LocalTime.MAX) - .build(); - BusinessHour wednesday = BusinessHour.builder() - .day("WEDNESDAY") - .startTime(LocalTime.of(0, 0)) - .endTime(LocalTime.MAX) - .build(); - - businessHours.add(monday); - businessHours.add(tuesday); - businessHours.add(wednesday); - - //when - boolean isOpen = openChecker.checkWithBusinessHours(businessHours, now); - //then - assertThat(isOpen).isEqualTo(expected); - } - - private static Stream provideLocalDateTime2() { - return Stream.of( - // LocalDateTime now, boolean expected - Arguments.of(LocalDateTime.of(2024, 1, 29, 12, 30, 0), true), - Arguments.of(LocalDateTime.of(2024, 1, 29, 23, 59, 59), true), - Arguments.of(LocalDateTime.of(2024, 1, 29, 23, 59, 59, 999_999_998), true), - Arguments.of(LocalDateTime.of(2024, 1, 29, 23, 59, 59, 999_999_999), true) - ); - } - - @ParameterizedTest - @MethodSource("provideLocalDateTime3") - @DisplayName("카페가 새벽2시까지 운영한다.") - void check_businessHours_when_cafe_is_open_2am(LocalDateTime now, boolean expected) { - List businessHours = new ArrayList<>(); - - BusinessHour monday = BusinessHour.builder() - .day("MONDAY") - .startTime(LocalTime.of(9, 0)) - .endTime(LocalTime.of(2, 0)) - .build(); - BusinessHour tuesday = BusinessHour.builder() - .day("TUESDAY") - .startTime(LocalTime.of(9, 0)) - .endTime(LocalTime.of(2, 0)) - .build(); - BusinessHour wednesday = BusinessHour.builder() - .day("WEDNESDAY") - .startTime(LocalTime.of(9, 0)) - .endTime(LocalTime.of(2, 0)) - .build(); - - businessHours.add(monday); - businessHours.add(tuesday); - businessHours.add(wednesday); - - //when - boolean isOpen = openChecker.checkWithBusinessHours(businessHours, now); - //then - assertThat(isOpen).isEqualTo(expected); - } - - private static Stream provideLocalDateTime3() { - return Stream.of( - // LocalDateTime now, boolean expected - Arguments.of(LocalDateTime.of(2024, 1, 30, 1, 59, 59), true), - Arguments.of(LocalDateTime.of(2024, 1, 30, 2, 0, 0), false) - ); - } - - @ParameterizedTest - @MethodSource("provideLocalDateTime4") - @DisplayName("평일은 일찍마감하고, 금토는 24시간 오픈한다.") - void check_businessHours_when_businessHour_is_different_depend_on_weekdays_and_weekends(LocalDateTime now, - boolean expected) { - List businessHours = new ArrayList<>(); - - BusinessHour monday = BusinessHour.builder() - .day("MONDAY") - .startTime(LocalTime.of(9, 0)) - .endTime(LocalTime.of(22, 0)) - .build(); - BusinessHour tuesday = BusinessHour.builder() - .day("TUESDAY") - .startTime(LocalTime.of(9, 0)) - .endTime(LocalTime.of(22, 0)) - .build(); - BusinessHour friday = BusinessHour.builder() - .day("FRIDAY") - .startTime(LocalTime.of(9, 0)) - .endTime(LocalTime.MAX) - .build(); - BusinessHour saturday = BusinessHour.builder() - .day("SATURDAY") - .startTime(LocalTime.of(0, 0)) - .endTime(LocalTime.MAX) - .build(); - BusinessHour sunday = BusinessHour.builder() - .day("SUNDAY") - .startTime(LocalTime.of(0, 0)) - .endTime(LocalTime.of(22, 0)) - .build(); - - businessHours.add(monday); - businessHours.add(tuesday); - businessHours.add(friday); - businessHours.add(saturday); - businessHours.add(sunday); - - //when - boolean isOpen = openChecker.checkWithBusinessHours(businessHours, now); - //then - assertThat(isOpen).isEqualTo(expected); + private BusinessHourOpenChecker openChecker = new BusinessHourOpenChecker(); + + @Test + @DisplayName("현재시간이 요일에 맞는 영업시간에 포함하면 open이다") + void contains_Nowtime_Then_Open() { + //given + LocalDateTime now = LocalDateTime.of(2024, 1, 29, 12, 0, 0); + DayOfWeek dayOfWeek = now.getDayOfWeek(); + LocalTime startTime = LocalTime.of(9, 0); + LocalTime endTime = LocalTime.of(21, 0); + //when + boolean isOpen = openChecker.checkByNowTime(dayOfWeek, startTime, endTime, now); + //then + assertThat(isOpen).isTrue(); + } + + @Test + @DisplayName("현재시간이 요일에 맞는 영업 시작시간이랑 일치하면 open이다") + void when_NowTime_Is_StartTime_Then_Open() { + //given + LocalDateTime now = LocalDateTime.of(2024, 1, 29, 9, 0, 0); + DayOfWeek dayOfWeek = now.getDayOfWeek(); + LocalTime startTime = LocalTime.of(9, 0); + LocalTime endTime = LocalTime.of(21, 0); + //when + boolean isOpen = openChecker.checkByNowTime(dayOfWeek, startTime, endTime, now); + //then + assertThat(isOpen).isTrue(); + } + + @Test + @DisplayName("현재시간이 요일에 맞는 영업 종료시작이랑 일치하면 close이다") + void when_NowTime_Is_EndTime_Then_Close() { + //given + LocalDateTime now = LocalDateTime.of(2024, 1, 29, 21, 0, 0); + DayOfWeek dayOfWeek = now.getDayOfWeek(); + LocalTime startTime = LocalTime.of(9, 0); + LocalTime endTime = LocalTime.of(21, 0); + //when + boolean isOpen = openChecker.checkByNowTime(dayOfWeek, startTime, endTime, now); + //then + assertThat(isOpen).isFalse(); + } + + @Test + @DisplayName("현재시간이 요일에 맞는 영업 종료시간 1초전이라면 open이다") + void when_NowTime_Is_EndTime_Before_1Sec_Then_Close() { + //given + LocalDateTime now = LocalDateTime.of(2024, 1, 29, 20, 59, 59); + DayOfWeek dayOfWeek = now.getDayOfWeek(); + LocalTime startTime = LocalTime.of(9, 0); + LocalTime endTime = LocalTime.of(21, 0); + //when + boolean isOpen = openChecker.checkByNowTime(dayOfWeek, startTime, endTime, now); + //then + assertThat(isOpen).isTrue(); + } + + @ParameterizedTest + @MethodSource("provideLocalDateTime") + @DisplayName("BusinessHours를 가지고 영업시간을 체크한다.") + void checkWithBusinessHours(LocalDateTime now, boolean expected) { + List businessHours = new ArrayList<>(); + + BusinessHour monday = BusinessHour.builder() + .day("MONDAY") + .startTime(LocalTime.of(9, 0)) + .endTime(LocalTime.of(21, 0)) + .build(); + BusinessHour tuesday = BusinessHour.builder() + .day("TUESDAY") + .startTime(LocalTime.of(9, 0)) + .endTime(LocalTime.of(21, 0)) + .build(); + BusinessHour wednesday = BusinessHour.builder() + .day("WEDNESDAY") + .startTime(LocalTime.of(9, 0)) + .endTime(LocalTime.of(21, 0)) + .build(); + + businessHours.add(monday); + businessHours.add(tuesday); + businessHours.add(wednesday); + + //when + boolean isOpen = openChecker.checkWithBusinessHours(businessHours, now); + //then + assertThat(isOpen).isEqualTo(expected); + } + + private static Stream provideLocalDateTime() { + return Stream.of( + // LocalDateTime now, boolean expected + Arguments.of(LocalDateTime.of(2024, 1, 29, 12, 30, 0), true), + Arguments.of(LocalDateTime.of(2024, 1, 31, 8, 30, 0), false) + ); + } + + @ParameterizedTest + @MethodSource("provideLocalDateTime2") + @DisplayName("카페가 24시간 운영한다.") + void check_businessHours_when_cafe_is_always_open(LocalDateTime now, boolean expected) { + List businessHours = new ArrayList<>(); + + BusinessHour monday = BusinessHour.builder() + .day("MONDAY") + .startTime(LocalTime.of(0, 0)) + .endTime(LocalTime.MAX) + .build(); + BusinessHour tuesday = BusinessHour.builder() + .day("TUESDAY") + .startTime(LocalTime.of(0, 0)) + .endTime(LocalTime.MAX) + .build(); + BusinessHour wednesday = BusinessHour.builder() + .day("WEDNESDAY") + .startTime(LocalTime.of(0, 0)) + .endTime(LocalTime.MAX) + .build(); + + businessHours.add(monday); + businessHours.add(tuesday); + businessHours.add(wednesday); + + //when + boolean isOpen = openChecker.checkWithBusinessHours(businessHours, now); + //then + assertThat(isOpen).isEqualTo(expected); + } + + private static Stream provideLocalDateTime2() { + return Stream.of( + // LocalDateTime now, boolean expected + Arguments.of(LocalDateTime.of(2024, 1, 29, 12, 30, 0), true), + Arguments.of(LocalDateTime.of(2024, 1, 29, 23, 59, 59), true), + Arguments.of(LocalDateTime.of(2024, 1, 29, 23, 59, 59, 999_999_998), true), + Arguments.of(LocalDateTime.of(2024, 1, 29, 23, 59, 59, 999_999_999), true) + ); + } + + @ParameterizedTest + @MethodSource("provideLocalDateTime3") + @DisplayName("카페가 새벽2시까지 운영한다.") + void check_businessHours_when_cafe_is_open_2am(LocalDateTime now, boolean expected) { + List businessHours = new ArrayList<>(); + + BusinessHour monday = BusinessHour.builder() + .day("MONDAY") + .startTime(LocalTime.of(9, 0)) + .endTime(LocalTime.of(2, 0)) + .build(); + BusinessHour tuesday = BusinessHour.builder() + .day("TUESDAY") + .startTime(LocalTime.of(9, 0)) + .endTime(LocalTime.of(2, 0)) + .build(); + BusinessHour wednesday = BusinessHour.builder() + .day("WEDNESDAY") + .startTime(LocalTime.of(9, 0)) + .endTime(LocalTime.of(2, 0)) + .build(); + + businessHours.add(monday); + businessHours.add(tuesday); + businessHours.add(wednesday); + + //when + boolean isOpen = openChecker.checkWithBusinessHours(businessHours, now); + //then + assertThat(isOpen).isEqualTo(expected); + } + + private static Stream provideLocalDateTime3() { + return Stream.of( + // LocalDateTime now, boolean expected + Arguments.of(LocalDateTime.of(2024, 1, 30, 1, 59, 59), true), + Arguments.of(LocalDateTime.of(2024, 1, 30, 2, 0, 0), false) + ); + } + + @ParameterizedTest + @MethodSource("provideLocalDateTime4") + @DisplayName("평일은 일찍마감하고, 금토는 24시간 오픈한다.") + void check_businessHours_when_businessHour_is_different_depend_on_weekdays_and_weekends(LocalDateTime now, + boolean expected) { + List businessHours = new ArrayList<>(); + + BusinessHour monday = BusinessHour.builder() + .day("MONDAY") + .startTime(LocalTime.of(9, 0)) + .endTime(LocalTime.of(22, 0)) + .build(); + BusinessHour tuesday = BusinessHour.builder() + .day("TUESDAY") + .startTime(LocalTime.of(9, 0)) + .endTime(LocalTime.of(22, 0)) + .build(); + BusinessHour friday = BusinessHour.builder() + .day("FRIDAY") + .startTime(LocalTime.of(9, 0)) + .endTime(LocalTime.MAX) + .build(); + BusinessHour saturday = BusinessHour.builder() + .day("SATURDAY") + .startTime(LocalTime.of(0, 0)) + .endTime(LocalTime.MAX) + .build(); + BusinessHour sunday = BusinessHour.builder() + .day("SUNDAY") + .startTime(LocalTime.of(0, 0)) + .endTime(LocalTime.of(22, 0)) + .build(); + + businessHours.add(monday); + businessHours.add(tuesday); + businessHours.add(friday); + businessHours.add(saturday); + businessHours.add(sunday); + + //when + boolean isOpen = openChecker.checkWithBusinessHours(businessHours, now); + //then + assertThat(isOpen).isEqualTo(expected); /* 365일 24시간 운영할때와는 다르게, 요일마다 운영시간이 다를때는 LocalTime.Max의 시간에서 영업중이도록 구현하지 않았다. @@ -252,256 +252,256 @@ void check_businessHours_when_businessHour_is_different_depend_on_weekdays_and_w //then assertThat(isOpen3).isTrue(); */ - } - - private static Stream provideLocalDateTime4() { - return Stream.of( - // LocalDateTime now, boolean expected - Arguments.of(LocalDateTime.of(2024, 1, 29, 12, 30), true), - Arguments.of(LocalDateTime.of(2024, 2, 2, 23, 59, 59, 999_999_998), true), - Arguments.of(LocalDateTime.of(2024, 2, 3, 0, 0), true), - Arguments.of(LocalDateTime.of(2024, 2, 4, 21, 59, 59, 999_999_999), true), - Arguments.of(LocalDateTime.of(2024, 2, 4, 22, 0, 0), false) - ); - } - - @Test - @DisplayName("DayOfWeek Enum상수가 가지고 있는 요일이 BusinessHours에 존재하지 않으면 예외가 터진다.") - void checkDayOfWeekWithBusinessHours() { - List businessHours = new ArrayList<>(); - BusinessHour weekends = BusinessHour.builder() - .day("WEEKENDS") - .startTime(LocalTime.of(9, 0)) - .endTime(LocalTime.of(21, 0)) - .build(); - businessHours.add(weekends); - - //when - LocalDateTime now = LocalDateTime.of(2024, 1, 29, 12, 30, 0); - //then - assertThatThrownBy(() -> openChecker.checkWithBusinessHours(businessHours, now)) - .isInstanceOf(CafegoryException.class); - } - - @ParameterizedTest - @MethodSource("provideChosenTimeAndExpected") - @DisplayName("영업시간 시간사이에 선택된 시간이 포함한다.") - void when_check_chosen_hours_between_businessHours_then_contains(LocalTime chosenStartTime, LocalTime chosenEndTime, - boolean expected) { - //given - LocalTime businessStartTime = LocalTime.of(9, 0); - LocalTime businessEndTime = LocalTime.of(21, 0); - - //when - boolean isBetween = openChecker.checkBetweenBusinessHours(businessStartTime, businessEndTime, - chosenStartTime, chosenEndTime); - //then - assertThat(isBetween).isEqualTo(expected); - } - - private static Stream provideChosenTimeAndExpected() { - return Stream.of( - // LocalTime chosenStartTime - // LocalTime chosenEndTime, - // boolean expected - Arguments.of( - LocalTime.of(9, 0), - LocalTime.of(21, 0), - true - ), - Arguments.of( - LocalTime.of(9, 0, 0, 1), - LocalTime.of(21, 0), - true - ), - Arguments.of( - LocalTime.of(9, 0), - LocalTime.of(20, 59, 59, 999_999_999), - true - ), - Arguments.of( - LocalTime.of(9, 0, 0, 1), - LocalTime.of(20, 59, 59, 999_999_999), - true - ) - ); - } - - @ParameterizedTest - @MethodSource("provideChosenTimeAndExpected2") - @DisplayName("영업시간 사이에 선택된 시간이 포함되지 않는다.") - void when_check_chosen_hours_between_businessHours_then_not_contains(LocalTime chosenStartTime, - LocalTime chosenEndTime, - boolean expected) { - //given - LocalTime businessStartTime = LocalTime.of(9, 0); - LocalTime businessEndTime = LocalTime.of(21, 0); - - //when - boolean isBetween = openChecker.checkBetweenBusinessHours(businessStartTime, businessEndTime, - chosenStartTime, chosenEndTime); - //then - assertThat(isBetween).isEqualTo(expected); - } - - private static Stream provideChosenTimeAndExpected2() { - return Stream.of( - // LocalTime chosenStartTime - // LocalTime chosenEndTime, - // boolean expected - Arguments.of( - LocalTime.of(8, 59, 59, 999_999_999), - LocalTime.of(21, 0), - false - ), - Arguments.of( - LocalTime.of(9, 0, 0), - LocalTime.of(21, 0, 0, 1), - false - ), - Arguments.of( - LocalTime.of(8, 59, 59, 999_999_999), - LocalTime.of(21, 0, 0, 1), - false - ) - ); - } - - @Test - @DisplayName("영업시간이 0시부터 24시까지일 경우") - void when_businessHour_is_0_to_24() { - //given - LocalTime businessStartTime = LocalTime.of(0, 0); - LocalTime businessEndTime = LocalTime.MAX; - - //when - LocalTime chosenStartTime1 = LocalTime.of(0, 0); - LocalTime chosenEndTime = LocalTime.MAX; - boolean isBetween = openChecker.checkBetweenBusinessHours(businessStartTime, businessEndTime, - chosenStartTime1, chosenEndTime); - //then - assertThat(isBetween).isTrue(); - - } - - @ParameterizedTest - @MethodSource("provideChosenTimeAndExpected3") - @DisplayName("영업시간이 밤22시부터 새벽2시까지일 경우") - void when_businessHour_is_22_to_2(LocalTime chosenStartTime, LocalTime chosenEndTime, - boolean expected) { - //given - LocalTime businessStartTime = LocalTime.of(22, 0); - LocalTime businessEndTime = LocalTime.of(2, 0); - - //when - boolean isBetween = openChecker.checkBetweenBusinessHours(businessStartTime, businessEndTime, - chosenStartTime, chosenEndTime); - //then - assertThat(isBetween).isEqualTo(expected); - } - - private static Stream provideChosenTimeAndExpected3() { - return Stream.of( - // LocalTime chosenStartTime - // LocalTime chosenEndTime, - // boolean expected - Arguments.of( - LocalTime.of(22, 0), - LocalTime.of(2, 0), - true - ), - Arguments.of( - LocalTime.of(22, 0, 0, 1), - LocalTime.of(2, 0), - true - ), - Arguments.of( - LocalTime.of(21, 59, 59, 999_999_999), - LocalTime.of(2, 0), - false - ), - Arguments.of( - LocalTime.of(22, 0, 0), - LocalTime.of(2, 0, 0, 1), - false - ), - Arguments.of( - LocalTime.of(0, 0), - LocalTime.MAX, - false - ) - ); - } - - @ParameterizedTest - @MethodSource("provideChosenTimeAndExpected4") - @DisplayName("영업시간이 7시부터 새벽2시까지일 경우") - void when_businessHour_is_7_to_2(LocalTime chosenStartTime, LocalTime chosenEndTime, - boolean expected) { - //given - LocalTime businessStartTime = LocalTime.of(7, 0); - LocalTime businessEndTime = LocalTime.of(2, 0); - - //when - boolean isBetween = openChecker.checkBetweenBusinessHours(businessStartTime, businessEndTime, - chosenStartTime, chosenEndTime); - //then - assertThat(isBetween).isEqualTo(expected); - } - - private static Stream provideChosenTimeAndExpected4() { - return Stream.of( - Arguments.of( - LocalTime.of(6, 59, 59, 999_999_999), - LocalTime.of(8, 0), - false - ), - Arguments.of( - LocalTime.of(7, 0), - LocalTime.of(8, 0), - true - ), - Arguments.of( - LocalTime.of(12, 0), - LocalTime.of(13, 0), - true - ), - Arguments.of( - LocalTime.of(23, 0), - LocalTime.MAX, - true - ), - Arguments.of( - LocalTime.of(23, 0), - LocalTime.of(0, 0), - true - ), - Arguments.of( - LocalTime.of(23, 0), - LocalTime.of(2, 0), - true - ), - Arguments.of( - LocalTime.of(23, 0), - LocalTime.of(2, 0, 0, 1), - false - ), - Arguments.of( - LocalTime.of(0, 0), - LocalTime.of(1, 0), - true - ), - Arguments.of( - LocalTime.of(0, 0), - LocalTime.of(2, 0), - true - ), - Arguments.of( - LocalTime.of(0, 0), - LocalTime.of(2, 0, 0, 1), - false - ) - ); - } + } + + private static Stream provideLocalDateTime4() { + return Stream.of( + // LocalDateTime now, boolean expected + Arguments.of(LocalDateTime.of(2024, 1, 29, 12, 30), true), + Arguments.of(LocalDateTime.of(2024, 2, 2, 23, 59, 59, 999_999_998), true), + Arguments.of(LocalDateTime.of(2024, 2, 3, 0, 0), true), + Arguments.of(LocalDateTime.of(2024, 2, 4, 21, 59, 59, 999_999_999), true), + Arguments.of(LocalDateTime.of(2024, 2, 4, 22, 0, 0), false) + ); + } + + @Test + @DisplayName("DayOfWeek Enum상수가 가지고 있는 요일이 BusinessHours에 존재하지 않으면 예외가 터진다.") + void checkDayOfWeekWithBusinessHours() { + List businessHours = new ArrayList<>(); + BusinessHour weekends = BusinessHour.builder() + .day("WEEKENDS") + .startTime(LocalTime.of(9, 0)) + .endTime(LocalTime.of(21, 0)) + .build(); + businessHours.add(weekends); + + //when + LocalDateTime now = LocalDateTime.of(2024, 1, 29, 12, 30, 0); + //then + assertThatThrownBy(() -> openChecker.checkWithBusinessHours(businessHours, now)) + .isInstanceOf(CafegoryException.class); + } + + @ParameterizedTest + @MethodSource("provideChosenTimeAndExpected") + @DisplayName("영업시간 시간사이에 선택된 시간이 포함한다.") + void when_check_chosen_hours_between_businessHours_then_contains(LocalTime chosenStartTime, LocalTime chosenEndTime, + boolean expected) { + //given + LocalTime businessStartTime = LocalTime.of(9, 0); + LocalTime businessEndTime = LocalTime.of(21, 0); + + //when + boolean isBetween = openChecker.checkBetweenBusinessHours(businessStartTime, businessEndTime, + chosenStartTime, chosenEndTime); + //then + assertThat(isBetween).isEqualTo(expected); + } + + private static Stream provideChosenTimeAndExpected() { + return Stream.of( + // LocalTime chosenStartTime + // LocalTime chosenEndTime, + // boolean expected + Arguments.of( + LocalTime.of(9, 0), + LocalTime.of(21, 0), + true + ), + Arguments.of( + LocalTime.of(9, 0, 0, 1), + LocalTime.of(21, 0), + true + ), + Arguments.of( + LocalTime.of(9, 0), + LocalTime.of(20, 59, 59, 999_999_999), + true + ), + Arguments.of( + LocalTime.of(9, 0, 0, 1), + LocalTime.of(20, 59, 59, 999_999_999), + true + ) + ); + } + + @ParameterizedTest + @MethodSource("provideChosenTimeAndExpected2") + @DisplayName("영업시간 사이에 선택된 시간이 포함되지 않는다.") + void when_check_chosen_hours_between_businessHours_then_not_contains(LocalTime chosenStartTime, + LocalTime chosenEndTime, + boolean expected) { + //given + LocalTime businessStartTime = LocalTime.of(9, 0); + LocalTime businessEndTime = LocalTime.of(21, 0); + + //when + boolean isBetween = openChecker.checkBetweenBusinessHours(businessStartTime, businessEndTime, + chosenStartTime, chosenEndTime); + //then + assertThat(isBetween).isEqualTo(expected); + } + + private static Stream provideChosenTimeAndExpected2() { + return Stream.of( + // LocalTime chosenStartTime + // LocalTime chosenEndTime, + // boolean expected + Arguments.of( + LocalTime.of(8, 59, 59, 999_999_999), + LocalTime.of(21, 0), + false + ), + Arguments.of( + LocalTime.of(9, 0, 0), + LocalTime.of(21, 0, 0, 1), + false + ), + Arguments.of( + LocalTime.of(8, 59, 59, 999_999_999), + LocalTime.of(21, 0, 0, 1), + false + ) + ); + } + + @Test + @DisplayName("영업시간이 0시부터 24시까지일 경우") + void when_businessHour_is_0_to_24() { + //given + LocalTime businessStartTime = LocalTime.of(0, 0); + LocalTime businessEndTime = LocalTime.MAX; + + //when + LocalTime chosenStartTime1 = LocalTime.of(0, 0); + LocalTime chosenEndTime = LocalTime.MAX; + boolean isBetween = openChecker.checkBetweenBusinessHours(businessStartTime, businessEndTime, + chosenStartTime1, chosenEndTime); + //then + assertThat(isBetween).isTrue(); + + } + + @ParameterizedTest + @MethodSource("provideChosenTimeAndExpected3") + @DisplayName("영업시간이 밤22시부터 새벽2시까지일 경우") + void when_businessHour_is_22_to_2(LocalTime chosenStartTime, LocalTime chosenEndTime, + boolean expected) { + //given + LocalTime businessStartTime = LocalTime.of(22, 0); + LocalTime businessEndTime = LocalTime.of(2, 0); + + //when + boolean isBetween = openChecker.checkBetweenBusinessHours(businessStartTime, businessEndTime, + chosenStartTime, chosenEndTime); + //then + assertThat(isBetween).isEqualTo(expected); + } + + private static Stream provideChosenTimeAndExpected3() { + return Stream.of( + // LocalTime chosenStartTime + // LocalTime chosenEndTime, + // boolean expected + Arguments.of( + LocalTime.of(22, 0), + LocalTime.of(2, 0), + true + ), + Arguments.of( + LocalTime.of(22, 0, 0, 1), + LocalTime.of(2, 0), + true + ), + Arguments.of( + LocalTime.of(21, 59, 59, 999_999_999), + LocalTime.of(2, 0), + false + ), + Arguments.of( + LocalTime.of(22, 0, 0), + LocalTime.of(2, 0, 0, 1), + false + ), + Arguments.of( + LocalTime.of(0, 0), + LocalTime.MAX, + false + ) + ); + } + + @ParameterizedTest + @MethodSource("provideChosenTimeAndExpected4") + @DisplayName("영업시간이 7시부터 새벽2시까지일 경우") + void when_businessHour_is_7_to_2(LocalTime chosenStartTime, LocalTime chosenEndTime, + boolean expected) { + //given + LocalTime businessStartTime = LocalTime.of(7, 0); + LocalTime businessEndTime = LocalTime.of(2, 0); + + //when + boolean isBetween = openChecker.checkBetweenBusinessHours(businessStartTime, businessEndTime, + chosenStartTime, chosenEndTime); + //then + assertThat(isBetween).isEqualTo(expected); + } + + private static Stream provideChosenTimeAndExpected4() { + return Stream.of( + Arguments.of( + LocalTime.of(6, 59, 59, 999_999_999), + LocalTime.of(8, 0), + false + ), + Arguments.of( + LocalTime.of(7, 0), + LocalTime.of(8, 0), + true + ), + Arguments.of( + LocalTime.of(12, 0), + LocalTime.of(13, 0), + true + ), + Arguments.of( + LocalTime.of(23, 0), + LocalTime.MAX, + true + ), + Arguments.of( + LocalTime.of(23, 0), + LocalTime.of(0, 0), + true + ), + Arguments.of( + LocalTime.of(23, 0), + LocalTime.of(2, 0), + true + ), + Arguments.of( + LocalTime.of(23, 0), + LocalTime.of(2, 0, 0, 1), + false + ), + Arguments.of( + LocalTime.of(0, 0), + LocalTime.of(1, 0), + true + ), + Arguments.of( + LocalTime.of(0, 0), + LocalTime.of(2, 0), + true + ), + Arguments.of( + LocalTime.of(0, 0), + LocalTime.of(2, 0, 0, 1), + false + ) + ); + } }