diff --git a/docs/README.md b/docs/README.md index e69de29bb..5266eaee9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -0,0 +1,45 @@ +## 기능 구현 + +- InputView + - [x] 코치의 이름을 입력받는다. + - [x] 코치의 이름은 최소 2글자, 최대 4글자이다. + - [x] 먹지 못하는 메뉴가 없으면 빈 값을 입력한다. + +- Coach + - [x] 코치 이름의 길이는 2~4글자 사이다. + - [x] 각 코치는 최소 0개, 최대 2개의 못 먹는 메뉴가 있다. + +- Coaches + - [x] 코치는 최소 2명, 최대 5명까지 식사를 함께 한다. + - 각 코치들의 못 먹는 메뉴를 저장한다. + +- CoachMenus + - [x] 각 코치에게 한 주에 중복되지 않는 메뉴를 추천해야 한다. + +- Category + - [x] 1이면 일식, 2면 한식, 3이면 중식, 4면 아시안, 5면 양식을 추천한다. + +- ForbiddenMenu + - [x] 못 먹는 음식을 저장한다. + +- RecommendCategory + - [x] 한 주에 같은 카테고리는 최대 2회까지만 고를 수 있다. + +- RecommendMenu + - [x] 카테고리에 맞는 메뉴를 생성한다, + +- Menus + - [x] 카테고리에 포함되는 메뉴 목록을 List 형태로 반환한다. + +- OutputView + - 메뉴 추천 결과를 출력한다. + + + +## 에러 처리 + +- InputValidate + - [x] 사용자가 잘못된 값을 입력할 경우 IllegalArgumentException를 발생시키고, "[ERROR]"로 시작하는 에러 메시지를 출력 후 그 부분부터 입력을 다시 받는다. + Exception이 아닌 IllegalArgumentException, IllegalStateException 등과 같은 명확한 유형을 처리한다. + - [x] , 로 구분해서 입력한다. + - [x] 못 먹는 음식은 코치별 0~2개 이다. \ No newline at end of file diff --git a/src/main/java/menu/Application.java b/src/main/java/menu/Application.java index 6340b6f33..58518bccb 100644 --- a/src/main/java/menu/Application.java +++ b/src/main/java/menu/Application.java @@ -1,7 +1,10 @@ package menu; +import menu.controller.MenuController; + public class Application { public static void main(String[] args) { - // TODO: 프로그램 구현 + MenuController menuController = new MenuController(); + menuController.run(); } } diff --git a/src/main/java/menu/constants/Categories.java b/src/main/java/menu/constants/Categories.java new file mode 100644 index 000000000..ee5c91f66 --- /dev/null +++ b/src/main/java/menu/constants/Categories.java @@ -0,0 +1,27 @@ +package menu.constants; + +import java.util.Arrays; + +public enum Categories { + JAPANESE(1, "일식"), + KOREAN(2, "한식"), + CHINESE(3, "중식"), + AISIAN(4, "아시안"), + WESTERN(5, "양식"); + + private final int number; + private final String type; + + Categories(int number, String type) { + this.number = number; + this.type = type; + } + + public static String findCategory(int number) { + return Arrays.stream(values()) + .filter(categories -> categories.number == number) + .map(categories -> categories.type) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException(ErrorMessage.CATEGORY_NUMBER_ERROR.getMessage())); + } +} diff --git a/src/main/java/menu/constants/Days.java b/src/main/java/menu/constants/Days.java new file mode 100644 index 000000000..0b92ca2ee --- /dev/null +++ b/src/main/java/menu/constants/Days.java @@ -0,0 +1,30 @@ +package menu.constants; + +public enum Days { + MONDAY("월요일"), + TUESDAY("화요일"), + WEDNESDAY("수요일"), + THURSDAY("목요일"), + FRIDAY("금요일"); + + private static final String TAG = "구분"; + private final String day; + + Days(String day) { + this.day = day; + } + + public static String showDivisionDays() { + StringBuilder sb = new StringBuilder(); + sb.append(ScreenElement.FIRST_ELEMENT).append(TAG); + for (Days days : Days.values()) { + sb.append(ScreenElement.MIDDLE_DIVISION).append(days.getDay()); + } + sb.append(ScreenElement.LAST_ELEMENT); + return sb.toString(); + } + + public String getDay() { + return day; + } +} diff --git a/src/main/java/menu/constants/ErrorMessage.java b/src/main/java/menu/constants/ErrorMessage.java new file mode 100644 index 000000000..5694cde59 --- /dev/null +++ b/src/main/java/menu/constants/ErrorMessage.java @@ -0,0 +1,21 @@ +package menu.constants; + +public enum ErrorMessage { + DIVISION_COMMA_ERROR("(, 로 구분)되지 않았습니다."), + COACH_NAME_LENGTH_ERROR("코치 이름은 최소 2글자, 최대 4글자까지 입력가능 합니다."), + COACH_NUMBER_ERROR("코치는 최소 2명, 최대 5명자까지 입력가능 합니다."), + COACH_FORBIDDEN_MENU_NUMBER_ERROR("각 코치가 못 먹는 메뉴는 최소 0개, 최대 2개의 입니다."), + CATEGORY_NUMBER_ERROR("존재하지 않는 카테고리 번호입니다."), + MENU_TYPE_ERROR("존재하지 않는 음식종류 입니다."); + + private static final String error = "[ERROR] "; + private final String message; + + ErrorMessage(String message) { + this.message = message; + } + + public String getMessage() { + return error + message; + } +} diff --git a/src/main/java/menu/constants/Menus.java b/src/main/java/menu/constants/Menus.java new file mode 100644 index 000000000..016a5864e --- /dev/null +++ b/src/main/java/menu/constants/Menus.java @@ -0,0 +1,34 @@ +package menu.constants; + +import java.util.Arrays; +import java.util.List; +import java.util.function.Predicate; + +public enum Menus { + JAPANESE("일식", List.of("규동", "우동", "미소시루", "스시", "가츠동", "오니기리", "하이라이스", "라멘", "오코노미야끼")), + KOREAN("한식", List.of("김밥", "김치찌개", "쌈밥", "된장찌개", "비빔밥", "칼국수", "불고기", "떡볶이", "제육볶음")), + CHINES("중식", List.of("깐풍기", "볶음면", "동파육", "짜장면", "짬뽕", "마파두부", "탕수육", "토마토 달걀볶음", "고추잡채")), + ASIAN("아시안", List.of("팟타이", "카오 팟", "나시고렝", "파인애플 볶음밥", "쌀국수", "똠얌꿍", "반미", "월남쌈", "분짜")), + WESTERN("양식", List.of("라자냐", "그라탱", "뇨끼", "끼슈", "프렌치 토스트", "바게트", "스파게티", "피자", "파니니")); + + private final String type; + private final List foods; + + Menus(String type, List foods) { + this.type = type; + this.foods = foods; + } + + public static List findFoods(String type) { + return Arrays.stream(Menus.values()) + .filter(isSameType(type)) + .map(menus -> menus.foods) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException(ErrorMessage.MENU_TYPE_ERROR.getMessage())); + } + + private static Predicate isSameType(String type) { + return menus -> menus.type.equals(type); + } + +} diff --git a/src/main/java/menu/constants/ProgressMessage.java b/src/main/java/menu/constants/ProgressMessage.java new file mode 100644 index 000000000..5d50cbfe8 --- /dev/null +++ b/src/main/java/menu/constants/ProgressMessage.java @@ -0,0 +1,23 @@ +package menu.constants; + +public enum ProgressMessage { + START_MENU_RECOMMEND("점심 메뉴 추천을 시작합니다."), + INPUT_COACH_NAME("코치의 이름을 입력해 주세요. (, 로 구분)"), + INPUT_COACH_FORBIDDEN_MENU("%s(이)가 못 먹는 메뉴를 입력해 주세요."), + RECOMMEND_MENU_RESULT("메뉴 추천 결과입니다."), + FINISH_RECOMMEND("추천을 완료했습니다."); + private final String message; + + ProgressMessage(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + @Override + public String toString() { + return message; + } +} diff --git a/src/main/java/menu/constants/ScreenElement.java b/src/main/java/menu/constants/ScreenElement.java new file mode 100644 index 000000000..a60fedfff --- /dev/null +++ b/src/main/java/menu/constants/ScreenElement.java @@ -0,0 +1,21 @@ +package menu.constants; + +public enum ScreenElement { + FIRST_ELEMENT("[ "), + MIDDLE_DIVISION(" | "), + LAST_ELEMENT(" ]"); + private final String value; + + ScreenElement(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + @Override + public String toString() { + return value; + } +} diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java new file mode 100644 index 000000000..2acbbb99a --- /dev/null +++ b/src/main/java/menu/controller/MenuController.java @@ -0,0 +1,41 @@ +package menu.controller; + +import menu.domain.Coaches; +import menu.service.MenuService; +import menu.view.InputView; +import menu.view.OutputView; + +public class MenuController { + + private final MenuService menuService; + private final InputView inputView; + private final OutputView outputView; + + public MenuController() { + this.menuService = new MenuService(); + this.inputView = new InputView(); + this.outputView = new OutputView(); + } + + public void run() { + outputView.printStartMenuRecommend(); + Coaches coaches = inputView.inputCoachName(); + addCoachesForbiddenMenu(coaches); + + recommendMenu(coaches); + outputView.printResultMenu(menuService.showMenuResult()); + } + + private void addCoachesForbiddenMenu(Coaches coaches) { + coaches.getCoaches().forEach(coach -> { + String menu = inputView.inputForbiddenMenus(coach); + coach.addForbiddenMenu(menu); + }); + } + + private void recommendMenu(Coaches coaches) { + while (menuService.isRecommending()) { + menuService.addRecommendMenu(coaches); + } + } +} diff --git a/src/main/java/menu/domain/Coach.java b/src/main/java/menu/domain/Coach.java new file mode 100644 index 000000000..004dab282 --- /dev/null +++ b/src/main/java/menu/domain/Coach.java @@ -0,0 +1,35 @@ +package menu.domain; + +import menu.constants.ErrorMessage; + +public class Coach { + + private static final int MIN_NAME_LENGTH = 2; + private static final int MAX_NAME_LENGTH = 4; + private final ForbiddenMenu forbiddenMenu; + private final String name; + + public Coach(String name) { + validateCoachNameLength(name); + this.name = name; + this.forbiddenMenu = new ForbiddenMenu(); + } + + private void validateCoachNameLength(String name) { + if (name.length() < MIN_NAME_LENGTH || name.length() > MAX_NAME_LENGTH) { + throw new IllegalArgumentException(ErrorMessage.COACH_NAME_LENGTH_ERROR.getMessage()); + } + } + + public void addForbiddenMenu(String menu) { + forbiddenMenu.addForbiddenMenu(menu); + } + + public boolean isNotContainRecommendMenuInForbidden(String menu) { + return forbiddenMenu.isNotContainRecommendMenuInForbidden(menu); + } + + public String getName() { + return name; + } +} diff --git a/src/main/java/menu/domain/CoachMenus.java b/src/main/java/menu/domain/CoachMenus.java new file mode 100644 index 000000000..a98895a66 --- /dev/null +++ b/src/main/java/menu/domain/CoachMenus.java @@ -0,0 +1,51 @@ +package menu.domain; + +import menu.constants.ScreenElement; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class CoachMenus { + private final RecommendMenu recommendMenu; + private final Map> coachMenus; + + public CoachMenus() { + this.recommendMenu = new RecommendMenu(); + this.coachMenus = new HashMap<>(); + } + + public void addCoachMenu(Coach coach, List menus) { + while (true) { + String menu = recommendMenu.getMenu(menus); + List recommendMenus = coachMenus.getOrDefault(coach, new ArrayList<>()); + if (canRecommendMenu(coach, menu)) { + recommendMenus.add(menu); + coachMenus.put(coach, recommendMenus); + break; + } + } + } + + private boolean canRecommendMenu(Coach coach, String menu) { + return coach.isNotContainRecommendMenuInForbidden(menu) && isNotDuplicateMenu(coach, menu); + } + + private boolean isNotDuplicateMenu(Coach coach, String menu) { + List menus = coachMenus.getOrDefault(coach, new ArrayList<>()); + return !menus.contains(menu); + } + + public String showCoachMenus() { + return coachMenus.keySet().stream() + .map(coach -> { + String menus = coachMenus.get(coach).stream() + .collect(Collectors.joining(ScreenElement.MIDDLE_DIVISION.getValue())); + return ScreenElement.FIRST_ELEMENT + coach.getName() + + ScreenElement.MIDDLE_DIVISION + menus + ScreenElement.LAST_ELEMENT; + }) + .collect(Collectors.joining("\n")) + "\n"; + } +} diff --git a/src/main/java/menu/domain/Coaches.java b/src/main/java/menu/domain/Coaches.java new file mode 100644 index 000000000..ff3b17ee0 --- /dev/null +++ b/src/main/java/menu/domain/Coaches.java @@ -0,0 +1,40 @@ +package menu.domain; + +import menu.constants.ErrorMessage; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static menu.view.InputValidator.DIVISION; + +public class Coaches { + + private static final int MIN_COACH_NUMBER = 2; + private static final int MAX_COACH_NUMBER = 5; + private final List coaches = new ArrayList<>(); + + public Coaches(String names) { + String[] coachNames = names.split(DIVISION); + validateCoachNumber(coachNames.length); + addCoaches(coachNames); + } + + private void validateCoachNumber(int number) { + if (number < MIN_COACH_NUMBER || number > MAX_COACH_NUMBER) { + throw new IllegalArgumentException(ErrorMessage.COACH_NUMBER_ERROR.getMessage()); + } + } + + private void addCoaches(String[] coachNames) { + coaches.addAll(Arrays.stream(coachNames) + .map(String::trim) + .map(Coach::new) + .collect(Collectors.toList())); + } + + public List getCoaches() { + return coaches; + } +} diff --git a/src/main/java/menu/domain/ForbiddenMenu.java b/src/main/java/menu/domain/ForbiddenMenu.java new file mode 100644 index 000000000..1df011aed --- /dev/null +++ b/src/main/java/menu/domain/ForbiddenMenu.java @@ -0,0 +1,23 @@ +package menu.domain; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static menu.view.InputValidator.DIVISION; + +public class ForbiddenMenu { + + private final List forbiddenMenus = new ArrayList<>(); + + public void addForbiddenMenu(String menus) { + forbiddenMenus.addAll(Arrays.stream(menus.split(DIVISION)) + .map(String::trim) + .collect(Collectors.toList())); + } + + public boolean isNotContainRecommendMenuInForbidden(String menu) { + return !forbiddenMenus.contains(menu); + } +} diff --git a/src/main/java/menu/domain/RecommendCategory.java b/src/main/java/menu/domain/RecommendCategory.java new file mode 100644 index 000000000..ff8d4e83f --- /dev/null +++ b/src/main/java/menu/domain/RecommendCategory.java @@ -0,0 +1,52 @@ +package menu.domain; + +import camp.nextstep.edu.missionutils.Randoms; +import menu.constants.Categories; +import menu.constants.ScreenElement; + +import java.util.ArrayList; +import java.util.List; + +public class RecommendCategory { + + private static final int MAX_DUPLICATE_COUNT = 2; + private static final int MIN_CATEGORY_NUM = 1; + private static final int MAX_CATEGORY_NUM = 5; + private static final String TAG = "카테고리"; + private final List categories = new ArrayList<>(); + + + public boolean isAddingRandomCategory() { + String category = Categories.findCategory(Randoms.pickNumberInRange(MIN_CATEGORY_NUM, MAX_CATEGORY_NUM)); + if (canAddCategory(category)) { + categories.add(category); + return true; + } + return false; + } + + private boolean canAddCategory(String newCategory) { + long count = categories.stream() + .filter(category -> category.equals(newCategory)) + .count(); + return count < MAX_DUPLICATE_COUNT; + } + + public boolean canRecommendCategory() { + return categories.size() < MAX_CATEGORY_NUM; + } + + public String getDaysCategory() { + return categories.get(categories.size() - 1); + } + + public String showRecommendCategory() { + StringBuilder sb = new StringBuilder(); + sb.append(ScreenElement.FIRST_ELEMENT).append(TAG); + for (String category : categories) { + sb.append(ScreenElement.MIDDLE_DIVISION).append(category); + } + sb.append(ScreenElement.LAST_ELEMENT); + return sb.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/menu/domain/RecommendMenu.java b/src/main/java/menu/domain/RecommendMenu.java new file mode 100644 index 000000000..ea0d929cf --- /dev/null +++ b/src/main/java/menu/domain/RecommendMenu.java @@ -0,0 +1,12 @@ +package menu.domain; + +import camp.nextstep.edu.missionutils.Randoms; + +import java.util.List; + +public class RecommendMenu { + + public String getMenu(List menus) { + return Randoms.shuffle(menus).get(0); + } +} diff --git a/src/main/java/menu/service/MenuService.java b/src/main/java/menu/service/MenuService.java new file mode 100644 index 000000000..97be8606a --- /dev/null +++ b/src/main/java/menu/service/MenuService.java @@ -0,0 +1,40 @@ +package menu.service; + +import menu.constants.Menus; +import menu.domain.Coach; +import menu.domain.CoachMenus; +import menu.domain.Coaches; +import menu.domain.RecommendCategory; + +import java.util.List; + +public class MenuService { + + private final RecommendCategory recommendCategory; + private final CoachMenus coachMenus; + + public MenuService() { + this.recommendCategory = new RecommendCategory(); + this.coachMenus = new CoachMenus(); + } + + public void addRecommendMenu(Coaches coaches) { + if (recommendCategory.isAddingRandomCategory()) { + for (Coach coach : coaches.getCoaches()) { + String category = recommendCategory.getDaysCategory(); + List menus = Menus.findFoods(category); + coachMenus.addCoachMenu(coach, menus); + } + } + } + + public boolean isRecommending() { + return recommendCategory.canRecommendCategory(); + } + + public String showMenuResult() { + return recommendCategory.showRecommendCategory() + + "\n" + + coachMenus.showCoachMenus(); + } +} diff --git a/src/main/java/menu/view/InputValidator.java b/src/main/java/menu/view/InputValidator.java new file mode 100644 index 000000000..4d3e2ad7e --- /dev/null +++ b/src/main/java/menu/view/InputValidator.java @@ -0,0 +1,22 @@ +package menu.view; + +import menu.constants.ErrorMessage; + +public class InputValidator { + + public static final String DIVISION = ","; + private static final int MAX_FORBIDDEN_MENU_SIZE = 2; + + public void validateContainComma(String names) { + if (!names.contains(DIVISION)) { + throw new IllegalArgumentException(ErrorMessage.DIVISION_COMMA_ERROR.getMessage()); + } + } + + public void validateForbiddenMenuNumber(String menus) { + String[] menuNames = menus.split(DIVISION); + if (menuNames.length > MAX_FORBIDDEN_MENU_SIZE) { + throw new IllegalArgumentException(ErrorMessage.COACH_FORBIDDEN_MENU_NUMBER_ERROR.getMessage()); + } + } +} diff --git a/src/main/java/menu/view/InputView.java b/src/main/java/menu/view/InputView.java new file mode 100644 index 000000000..c6d8a23de --- /dev/null +++ b/src/main/java/menu/view/InputView.java @@ -0,0 +1,44 @@ +package menu.view; + +import menu.domain.Coach; +import menu.domain.Coaches; + +import java.util.Scanner; +import java.util.function.Supplier; + +public class InputView { + + private final InputValidator inputValidator = new InputValidator(); + private final OutputView outputView = new OutputView(); + private final Scanner scanner = new Scanner(System.in); + + public Coaches inputCoachName() { + return read(() -> { + outputView.printProgressCoachNameMessage(); + String names = scanner.next(); + outputView.printEnter(); + inputValidator.validateContainComma(names); + return new Coaches(names); + }); + } + + public String inputForbiddenMenus(Coach coach) { + return read(() -> { + outputView.printProgressCoachForbiddenMessage(coach.getName()); + String menus = scanner.next(); + outputView.printEnter(); + inputValidator.validateForbiddenMenuNumber(menus); + return menus; + }); + } + + private T read(Supplier supplier) { + while (true) { + try { + return supplier.get(); + } catch (IllegalArgumentException e) { + outputView.printErrorMessage(e.getMessage()); + } + } + } +} diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java new file mode 100644 index 000000000..590caa201 --- /dev/null +++ b/src/main/java/menu/view/OutputView.java @@ -0,0 +1,35 @@ +package menu.view; + +import menu.constants.Days; +import menu.constants.ProgressMessage; + +public class OutputView { + + public void printStartMenuRecommend() { + System.out.println(ProgressMessage.START_MENU_RECOMMEND); + printEnter(); + } + + public void printErrorMessage(String error) { + System.out.println(error); + } + + public void printProgressCoachNameMessage() { + System.out.println(ProgressMessage.INPUT_COACH_NAME); + } + + public void printProgressCoachForbiddenMessage(String name) { + System.out.printf((ProgressMessage.INPUT_COACH_FORBIDDEN_MENU.getMessage()) + "%n", name); + } + + public void printResultMenu(String result) { + System.out.println(ProgressMessage.RECOMMEND_MENU_RESULT); + System.out.println(Days.showDivisionDays()); + System.out.println(result); + System.out.println(ProgressMessage.FINISH_RECOMMEND); + } + + public void printEnter() { + System.out.println(); + } +} diff --git a/src/test/java/menu/CategoriesTest.java b/src/test/java/menu/CategoriesTest.java new file mode 100644 index 000000000..2858cc68c --- /dev/null +++ b/src/test/java/menu/CategoriesTest.java @@ -0,0 +1,16 @@ +package menu; + +import menu.constants.Categories; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; +class CategoriesTest { + + @Test + @DisplayName("숫자에 맞는 카테고리를 찾는지 확인한다.") + void findCategoryByNumber(){ + String category = Categories.findCategory(1); + assertThat(category).isEqualTo("일식"); + } + +} diff --git a/src/test/java/menu/CoachTest.java b/src/test/java/menu/CoachTest.java new file mode 100644 index 000000000..61a858076 --- /dev/null +++ b/src/test/java/menu/CoachTest.java @@ -0,0 +1,20 @@ +package menu; + +import menu.domain.Coach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +class CoachTest { + + private static final String error = "[ERROR] "; + + @Test + @DisplayName("코치 이름이 2~4글자가 아니면 에러가 발생한다.") + void validateCoachNameLength() { + assertThatThrownBy(() -> new Coach("준")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(error); + } +} diff --git a/src/test/java/menu/CoachesTest.java b/src/test/java/menu/CoachesTest.java new file mode 100644 index 000000000..7b0f65a79 --- /dev/null +++ b/src/test/java/menu/CoachesTest.java @@ -0,0 +1,35 @@ +package menu; + +import menu.domain.Coach; +import menu.domain.Coaches; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.*; + +public class CoachesTest { + + private static final String error = "[ERROR] "; + + @Test + @DisplayName("코치의 수가 2~5명 사이가 아니라면 에러가 발생한다.") + void validateCoachNumbers() { + assertThatThrownBy(() -> new Coaches("토미")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(error); + } + + @Test + @DisplayName("코치들이 저장이 되는지 확인한다.") + void saveCoaches() { + Coaches coaches = new Coaches("토미,제임스,포코"); + + List getCoach = coaches.getCoaches(); + + List names = getCoach.stream().map(Coach::getName).collect(Collectors.toList()); + assertThat(names).contains("토미", "제임스", "포코"); + } +} diff --git a/src/test/java/menu/DaysTest.java b/src/test/java/menu/DaysTest.java new file mode 100644 index 000000000..0f2700b7e --- /dev/null +++ b/src/test/java/menu/DaysTest.java @@ -0,0 +1,16 @@ +package menu; + +import menu.constants.Days; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.*; +class DaysTest { + + @Test + @DisplayName("요일에 맞게 출력하는지 확인한다.") + void showDivisionDays(){ + String days = Days.showDivisionDays(); + assertThat(days).isEqualTo("[ 구분 | 월요일 | 화요일 | 수요일 | 목요일 | 금요일 ]"); + } +} diff --git a/src/test/java/menu/ForbiddenMenuTest.java b/src/test/java/menu/ForbiddenMenuTest.java new file mode 100644 index 000000000..43d3e43b5 --- /dev/null +++ b/src/test/java/menu/ForbiddenMenuTest.java @@ -0,0 +1,19 @@ +package menu; +import menu.domain.ForbiddenMenu; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.*; +class ForbiddenMenuTest { + ForbiddenMenu forbiddenMenu = new ForbiddenMenu(); + @Test + @DisplayName("못 먹는 음식을 저장하고 추천 음식이 포함되지 않으면 true를 반환한다.") + void saveForbiddenMenuAndCheckDuplicate(){ + forbiddenMenu.addForbiddenMenu("우동,스시"); + + boolean isNotContain = forbiddenMenu.isNotContainRecommendMenuInForbidden("비빔밥"); + + assertThat(isNotContain).isTrue(); + } + +} diff --git a/src/test/java/menu/InputValidatorTest.java b/src/test/java/menu/InputValidatorTest.java new file mode 100644 index 000000000..19fdb5207 --- /dev/null +++ b/src/test/java/menu/InputValidatorTest.java @@ -0,0 +1,28 @@ +package menu; + +import menu.view.InputValidator; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +class InputValidatorTest { + private static final String error = "[ERROR] "; + InputValidator inputValidator = new InputValidator(); + + @Test + @DisplayName("입력한 값에 ,를 포함하고 있지 않으면 에러가 발생한다.") + void validateContainComma() { + assertThatThrownBy(() -> inputValidator.validateContainComma("토미/제임스/포코")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(error); + } + + @Test + @DisplayName("코치들의 못 먹는 음식이 최대 2가지가 아니라면 에러가 발생한다.") + void validateForbiddenMenuNumber() { + assertThatThrownBy(() -> inputValidator.validateForbiddenMenuNumber("우동,스시,비빔밥")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(error); + } +} diff --git a/src/test/java/menu/MenusTest.java b/src/test/java/menu/MenusTest.java new file mode 100644 index 000000000..d1cb5538f --- /dev/null +++ b/src/test/java/menu/MenusTest.java @@ -0,0 +1,19 @@ +package menu; + +import menu.constants.Menus; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.*; +public class MenusTest { + + @Test + @DisplayName("타입에 맞는 음식 종류들을 찾을 수 있다.") + void findMenusByType(){ + List menus = Menus.findFoods("일식"); + assertThat(menus).isEqualTo(List.of("규동", "우동", "미소시루", "스시", "가츠동", "오니기리", "하이라이스", "라멘", "오코노미야끼")); + } + +} diff --git a/src/test/java/menu/RecommendCategoryTest.java b/src/test/java/menu/RecommendCategoryTest.java new file mode 100644 index 000000000..6156968f9 --- /dev/null +++ b/src/test/java/menu/RecommendCategoryTest.java @@ -0,0 +1,20 @@ +package menu; +import menu.domain.RecommendCategory; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.*; +class RecommendCategoryTest { + + @Test + @DisplayName("카테고리가 최대 2번 중복되지 않았으면 추가되어 메뉴를 추천할 수 있다.") + void saveCategoryReturnTrue(){ + RecommendCategory recommendCategory = new RecommendCategory(); + + boolean canAdd = recommendCategory.isAddingRandomCategory(); + boolean canRecommend = recommendCategory.canRecommendCategory(); + + assertThat(canAdd).isTrue(); + assertThat(canRecommend).isTrue(); + } +}