diff --git a/docs/README.md b/docs/README.md index e69de29bb..98ab49238 100644 --- a/docs/README.md +++ b/docs/README.md @@ -0,0 +1,30 @@ +# 우테코 menu 문제 + +## 기능 목록 +- inputView + - [x] 메뉴 추천 받을 코치 이름 입력 + - [x] 코치 이름은 최소 2글자, 최대 4글자이다. + - [x] 코치는 최소 2명, 최대 5명까지 식사를 함께 한다. + - [x] 각 코치가 못 먹는 메뉴를 입력 + - [x] 최소 0개, 최대 2개까지 못 먹는 메뉴가 있다. (, 로 구분해서 입력한다.) + +- outputView + - 메뉴 추천 결과 출력 + +- recommend + - [x] 월, 화, 수, 목, 금 각 요일 마다 추천할 카테고리를 무작위로 정한다. + - [x] 각 코치가 요일에 먹을 메뉴를 추천한다. + +- category + - [x] 한 주에 같은 카테고리는 최대 2회까지만 고르며 생성 + +- menu + - [x] 각 코치에게 한 주에 중복되지 않는 메뉴를 추천해야 한다. + +## 에러 처리 + +- inputValidator + - [x] 잘못된 값을 입력할 경우 `IllegalArgumentException`를 발생시키고, "[ERROR]"로 시작하는 에러 메시지를 출력 후 그 부분부터 입력을 다시 받는다. + - [x] 코치 이름은 최소 2글자, 최대 4글자이다. + - [x] 코치는 최소 2명, 최대 5명까지 식사를 함께 한다. + - [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..16ccfa07c 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.StartRecommend(); } } diff --git a/src/main/java/menu/constant/Categories.java b/src/main/java/menu/constant/Categories.java new file mode 100644 index 000000000..fd6dfad9f --- /dev/null +++ b/src/main/java/menu/constant/Categories.java @@ -0,0 +1,37 @@ +package menu.constant; + +import java.util.Arrays; +import java.util.function.Predicate; + +public enum Categories { + JAPANESE(1, "일식"), + KOREAN(2, "한식"), + CHINESE(3, "중식"), + ASIAN(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 getType(int number) { + return Arrays.stream(Categories.values()) + .filter(isSameNumber(number)) + .map(categories -> categories.type) + .findFirst() + .orElse(null); + } + + private static Predicate isSameNumber(int number) { + return categories -> categories.number == number; + } + + public String findType(){ + return type; + } +} diff --git a/src/main/java/menu/constant/Days.java b/src/main/java/menu/constant/Days.java new file mode 100644 index 000000000..eeb3229ff --- /dev/null +++ b/src/main/java/menu/constant/Days.java @@ -0,0 +1,27 @@ +package menu.constant; + +public enum Days { + MONDAY("월요일"), + TUESDAY("화요일"), + WEDNESDAY("수요일"), + THURSDAY("목요일"), + FRIDAY("금요일"); + + private static final String DIVISION = "구분"; + private final String value; + + Days(String value) { + this.value = value; + } + + public static String outputDays() { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(OutputElement.FIRST_ELEMENT).append(DIVISION); + for (Days days :Days.values()){ + stringBuilder.append(OutputElement.MIDDLE_ELEMENT) + .append(days.value); + } + stringBuilder.append(OutputElement.LAST_ELEMENT); + return stringBuilder.toString(); + } +} diff --git a/src/main/java/menu/constant/ErrorMessage.java b/src/main/java/menu/constant/ErrorMessage.java new file mode 100644 index 000000000..980337a2b --- /dev/null +++ b/src/main/java/menu/constant/ErrorMessage.java @@ -0,0 +1,21 @@ +package menu.constant; + +public enum ErrorMessage { + + COACH_NAME_LENGTH_ERROR("코치 이름은 %d~%d글자 사이로 입력되어야 합니다."), + COACH_NAME_NUMBER_ERROR("코치는 최소 %d명, 최대 %d명 입력되어야 합니다."), + + INPUT_COMMA_ERROR("',' 로 구분되어 이름을 입력해주세요."); + + private static final String prefix = "[ERROR] "; + private final String message; + + ErrorMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return prefix + message; + } +} diff --git a/src/main/java/menu/constant/Menus.java b/src/main/java/menu/constant/Menus.java new file mode 100644 index 000000000..b69965215 --- /dev/null +++ b/src/main/java/menu/constant/Menus.java @@ -0,0 +1,33 @@ +package menu.constant; + +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 getFoods(String type) { + return Arrays.stream(Menus.values()) + .filter(isSameType(type)) + .map(menus -> menus.foods) + .findFirst() + .orElse(null); + } + + private static Predicate isSameType(String type) { + return menus -> menus.type.equals(type); + } +} diff --git a/src/main/java/menu/constant/OutputElement.java b/src/main/java/menu/constant/OutputElement.java new file mode 100644 index 000000000..4aa4acb71 --- /dev/null +++ b/src/main/java/menu/constant/OutputElement.java @@ -0,0 +1,20 @@ +package menu.constant; + +public enum OutputElement { + FIRST_ELEMENT("[ "), + MIDDLE_ELEMENT(" | "), + LAST_ELEMENT(" ]"), + NEXT_ELEMENT("\n"); + + + private final String element; + + OutputElement(String element) { + this.element = element; + } + + @Override + public String toString() { + return element; + } +} diff --git a/src/main/java/menu/constant/ProcessMessage.java b/src/main/java/menu/constant/ProcessMessage.java new file mode 100644 index 000000000..e050b5b39 --- /dev/null +++ b/src/main/java/menu/constant/ProcessMessage.java @@ -0,0 +1,20 @@ +package menu.constant; + +public enum ProcessMessage { + INPUT_COACH_NAME("코치의 이름을 입력해 주세요. (, 로 구분)"), + INPUT_FORBIDDEN_MENU("%s(이)가 못 먹는 메뉴를 입력해 주세요."), + OUTPUT_START_MENU("점심 메뉴 추천을 시작합니다."), + OUTPUT_RESULT_MENU("메뉴 추천 결과입니다."), + OUTPUT_FINISH_MENU("추천을 완료했습니다."); + + private final String message; + + ProcessMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return message; + } +} diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java new file mode 100644 index 000000000..2d8076cc0 --- /dev/null +++ b/src/main/java/menu/controller/MenuController.java @@ -0,0 +1,35 @@ +package menu.controller; + +import menu.model.CoachNames; +import menu.model.ForbiddenMenu; +import menu.model.RecommendCategory; +import menu.model.RecommendMenu; +import menu.view.InputView; +import menu.view.OutputView; + +public class MenuController { + + private final InputView inputView; + private final OutputView outputView; + private final RecommendCategory recommendCategory; + private final RecommendMenu recommendMenu; + + public MenuController() { + this.inputView = new InputView(); + this.outputView = new OutputView(); + this.recommendCategory = new RecommendCategory(); + this.recommendMenu = new RecommendMenu(); + } + + public void StartRecommend(){ + outputView.printStartMenu(); + CoachNames coachNames = inputView.readCoachName(); + ForbiddenMenu forbiddenMenu = inputView.readForbiddenMenu(coachNames); + + while (recommendCategory.isRecommending()){ + recommendCategory.createRecommendCategory(); + recommendMenu.createRecommendMenu(coachNames, forbiddenMenu, recommendCategory); + } + outputView.printRecommendResult(recommendMenu, recommendCategory); + } +} diff --git a/src/main/java/menu/model/CoachNames.java b/src/main/java/menu/model/CoachNames.java new file mode 100644 index 000000000..1ef1ebe1d --- /dev/null +++ b/src/main/java/menu/model/CoachNames.java @@ -0,0 +1,46 @@ +package menu.model; + +import menu.constant.ErrorMessage; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class CoachNames { + + private final static int MIN_NAME_LENGTH = 2; + private final static int MAX_NAME_LENGTH = 4; + private final static int MIN_COACH_COUNT = 2; + private final static int MAX_COACH_COUNT = 5; + private final static String BY_COMMA = ","; + private final List coachNames = new ArrayList<>(); + + public CoachNames(String name) { + Arrays.stream(name.split(BY_COMMA)) + .forEach(this::addValidateCoachName); + validateCoachNumber(); + } + + private void addValidateCoachName(String name){ + validateCoachNameLength(name); + coachNames.add(name); + } + + private void validateCoachNameLength(String name) { + if (name.length() < MIN_NAME_LENGTH || name.length() > MAX_NAME_LENGTH) { + throw new IllegalArgumentException( + String.format(ErrorMessage.COACH_NAME_LENGTH_ERROR.toString(), MIN_NAME_LENGTH, MAX_NAME_LENGTH)); + } + } + + private void validateCoachNumber(){ + if (coachNames.size() < MIN_COACH_COUNT || coachNames.size() > MAX_COACH_COUNT){ + throw new IllegalArgumentException( + String.format(ErrorMessage.COACH_NAME_NUMBER_ERROR.toString(), MIN_COACH_COUNT, MAX_COACH_COUNT)); + } + } + + public List getCoachNames() { + return coachNames; + } +} diff --git a/src/main/java/menu/model/ForbiddenMenu.java b/src/main/java/menu/model/ForbiddenMenu.java new file mode 100644 index 000000000..9ae67260b --- /dev/null +++ b/src/main/java/menu/model/ForbiddenMenu.java @@ -0,0 +1,24 @@ +package menu.model; + +import java.util.*; +import java.util.stream.Collectors; + +public class ForbiddenMenu { + + private final Map> forbiddenMenus = new HashMap<>(); + + public void add(String name, String forbiddenMenu) { + forbiddenMenus.put(name, Arrays.stream(forbiddenMenu.split(",")).collect(Collectors.toList())); + } + + public boolean isNotContainForbiddenMenu(String name, String menu){ + return forbiddenMenus + .getOrDefault(name, Collections.emptyList()) + .stream() + .noneMatch(forbiddenMenu -> forbiddenMenu.equals(menu)); + } + + public Map> getForbiddenMenus() { + return forbiddenMenus; + } +} diff --git a/src/main/java/menu/model/RecommendCategory.java b/src/main/java/menu/model/RecommendCategory.java new file mode 100644 index 000000000..d7dbc4c22 --- /dev/null +++ b/src/main/java/menu/model/RecommendCategory.java @@ -0,0 +1,66 @@ +package menu.model; + +import camp.nextstep.edu.missionutils.Randoms; +import menu.constant.Categories; +import menu.constant.OutputElement; + +import java.util.ArrayList; +import java.util.List; + +public class RecommendCategory { + + private static final String CATEGORY = "카테고리"; + private static final int CATEGORY_COUNT = 5; + private static final int MAX_DUPLICATE_COUNT = 2; + private final List categories = new ArrayList<>(); + private int curCategory = 0; + + public void createRecommendCategory() { + String newCategory = Categories.getType(Randoms.pickNumberInRange(1, 5)); + if (canAddCategory(newCategory)){ + categories.add(newCategory); + } + } + + private boolean canAddCategory(String newCategory) { + long count = categories.stream() + .filter(category -> category.equals(newCategory)) + .count(); + return count < MAX_DUPLICATE_COUNT; + } + + public boolean isRecommending(){ + return categories.size() < CATEGORY_COUNT; + } + + public void nextCategory(){ + curCategory++; + } + + public int getCurCategory() { + return curCategory; + } + + + public List getCategories() { + return categories; + } + + public int getCategoryCount(){ + return categories.size(); + } + + @Override + public String toString() { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(OutputElement.FIRST_ELEMENT).append(CATEGORY); + for (String category : categories){ + stringBuilder.append(OutputElement.MIDDLE_ELEMENT) + .append(category); + } + stringBuilder.append(OutputElement.LAST_ELEMENT); + return stringBuilder.toString(); + } +} + + diff --git a/src/main/java/menu/model/RecommendMenu.java b/src/main/java/menu/model/RecommendMenu.java new file mode 100644 index 000000000..2962f2b0a --- /dev/null +++ b/src/main/java/menu/model/RecommendMenu.java @@ -0,0 +1,66 @@ +package menu.model; + +import camp.nextstep.edu.missionutils.Randoms; +import menu.constant.Menus; +import menu.constant.OutputElement; + +import java.util.*; + +public class RecommendMenu { + + private final Map> menus = new HashMap<>(); + + public void createRecommendMenu(CoachNames coachNames, ForbiddenMenu forbiddenMenu + , RecommendCategory recommendCategory){ + for (String coach : coachNames.getCoachNames()){ + addMenu(forbiddenMenu, recommendCategory, coach); + } + recommendCategory.nextCategory(); + } + + private void addMenu(ForbiddenMenu forbiddenMenu, RecommendCategory recommendCategory, String coach) { + List categories = recommendCategory.getCategories(); + while (isRecommendsMenu(coach, recommendCategory)){ + List menu = Menus.getFoods(categories.get(recommendCategory.getCurCategory())); + String menuName = Randoms.shuffle(menu).get(0); + if (canAddMenu(coach, menuName, forbiddenMenu)){ + List coachMenus = menus.getOrDefault(coach, new ArrayList<>()); + coachMenus.add(menuName); + menus.put(coach, coachMenus); + } + } + } + + private boolean isRecommendsMenu(String coach, RecommendCategory recommendCategory) { + List coachMenus = menus.getOrDefault(coach, Collections.emptyList()); + return coachMenus.size() < recommendCategory.getCategoryCount(); + } + + private boolean canAddMenu(String coach, String menuName, ForbiddenMenu forbiddenMenu) { + boolean isNotDuplicate = menus.getOrDefault(coach, Collections.emptyList()) + .stream() + .noneMatch(menu -> menu.equals(menuName)); + boolean isNotContainForbiddenMenu = forbiddenMenu.isNotContainForbiddenMenu(coach, menuName); + return isNotDuplicate && isNotContainForbiddenMenu; + } + + public Map> getMenus() { + return menus; + } + + @Override + public String toString() { + StringBuilder stringBuilder = new StringBuilder(); + for (String coach: menus.keySet()){ + stringBuilder.append(OutputElement.FIRST_ELEMENT).append(coach); + + for (String menu: menus.get(coach)){ + stringBuilder.append(OutputElement.MIDDLE_ELEMENT) + .append(menu); + } + stringBuilder.append(OutputElement.LAST_ELEMENT).append(OutputElement.NEXT_ELEMENT); + } + return stringBuilder.toString(); + } + +} diff --git a/src/main/java/menu/view/InputView.java b/src/main/java/menu/view/InputView.java new file mode 100644 index 000000000..988fb61d2 --- /dev/null +++ b/src/main/java/menu/view/InputView.java @@ -0,0 +1,60 @@ +package menu.view; + +import camp.nextstep.edu.missionutils.Console; +import menu.model.CoachNames; +import menu.model.ForbiddenMenu; +import menu.view.validate.InputValidator; + + +public class InputView { + + private final OutputView outputView = new OutputView(); + private final InputValidator inputValidator = new InputValidator(); + + public CoachNames readCoachName(){ + CoachNames coachNames; + do { + coachNames = inputCoachName(); + }while (coachNames == null); + return coachNames; + } + + + private CoachNames inputCoachName(){ + outputView.printCoachNameMessage(); + String coachName = Console.readLine(); + outputView.printEnter(); + try{ + inputValidator.validateCommaContain(coachName); + return new CoachNames(coachName); + } catch (IllegalArgumentException e){ + outputView.printErrorMessage(e.getMessage()); + return null; + } + } + + public ForbiddenMenu readForbiddenMenu(CoachNames coachNames){ + ForbiddenMenu forbiddenMenu; + do { + forbiddenMenu = inputForbiddenMenu(coachNames); + }while (forbiddenMenu == null); + return forbiddenMenu; + } + + private ForbiddenMenu inputForbiddenMenu(CoachNames coachNames){ + ForbiddenMenu forbiddenMenu = new ForbiddenMenu(); + for (String coachName: coachNames.getCoachNames()){ + outputView.printCoachesForbiddenMenu(coachName); + String inputMenu = Console.readLine(); + outputView.printEnter(); + try { + inputValidator.validateForbiddenMenuCount(inputMenu); + forbiddenMenu.add(coachName, inputMenu); + }catch (IllegalArgumentException e){ + outputView.printErrorMessage(e.getMessage()); + return null; + } + } + return forbiddenMenu; + } +} diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java new file mode 100644 index 000000000..5ad610f42 --- /dev/null +++ b/src/main/java/menu/view/OutputView.java @@ -0,0 +1,38 @@ +package menu.view; + +import menu.model.RecommendCategory; +import menu.model.RecommendMenu; +import menu.constant.Days; +import menu.constant.ProcessMessage; + +public class OutputView { + + public void printCoachNameMessage(){ + System.out.println(ProcessMessage.INPUT_COACH_NAME); + } + + public void printErrorMessage(String error){ + System.out.println(error); + } + + public void printCoachesForbiddenMenu(String name) { + System.out.println(String.format(ProcessMessage.INPUT_FORBIDDEN_MENU.toString(), name)); + } + + public void printStartMenu() { + System.out.println(ProcessMessage.OUTPUT_START_MENU); + printEnter(); + } + + public void printEnter(){ + System.out.println(); + } + + public void printRecommendResult(RecommendMenu recommendMenu, RecommendCategory recommendCategory) { + System.out.println(ProcessMessage.OUTPUT_RESULT_MENU); + System.out.println(Days.outputDays()); + System.out.println(recommendCategory); + System.out.println(recommendMenu); + System.out.println(ProcessMessage.OUTPUT_FINISH_MENU); + } +} diff --git a/src/main/java/menu/view/validate/InputValidator.java b/src/main/java/menu/view/validate/InputValidator.java new file mode 100644 index 000000000..02caeb55f --- /dev/null +++ b/src/main/java/menu/view/validate/InputValidator.java @@ -0,0 +1,24 @@ +package menu.view.validate; + +import menu.constant.ErrorMessage; + +import java.util.Arrays; + +public class InputValidator { + + private static final String DIVISION = ","; + private static final int MAX_FORBIDDEN_MENU_COUNT = 2; + + public void validateCommaContain(String coachName){ + if (!coachName.contains(DIVISION)){ + throw new IllegalArgumentException(ErrorMessage.INPUT_COMMA_ERROR.toString()); + } + } + + public void validateForbiddenMenuCount(String forbiddenMenu){ + long forbiddenMenuCount = Arrays.stream(forbiddenMenu.split(",")).count(); + if(forbiddenMenuCount > MAX_FORBIDDEN_MENU_COUNT){ + throw new IllegalArgumentException(ErrorMessage.INPUT_COMMA_ERROR.toString()); + } + } +} diff --git a/src/test/java/menu/CategoryTest.java b/src/test/java/menu/CategoryTest.java new file mode 100644 index 000000000..4910e87cc --- /dev/null +++ b/src/test/java/menu/CategoryTest.java @@ -0,0 +1,54 @@ +package menu; + +import menu.constant.Categories; +import menu.model.RecommendCategory; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; + +import java.util.List; + +class CategoryTest { + + RecommendCategory recommendCategory = new RecommendCategory(); + + @Test + @DisplayName("추천 카테고리가 카테고리 수 만큼 저장이 되는지 확인한다.") + void checkSaveRecommendCategoriesCount(){ + //given + while (recommendCategory.isRecommending()){ + recommendCategory.createRecommendCategory(); + } + + //when + List categories = recommendCategory.getCategories(); + + //then + assertThat(categories.size()).isEqualTo(5); + } + + @Test + @DisplayName("추천 카테고리에 카테고리 중 일부가 저장되는지 확인한다.") + void checkRecommendCategories(){ + //given + recommendCategory.createRecommendCategory(); + + //when + List categories = recommendCategory.getCategories(); + + //then + assertThat(categories).containsAnyOf( + Categories.JAPANESE.findType(), + Categories.KOREAN.findType(), + Categories.CHINESE.findType(), + Categories.ASIAN.findType(), + Categories.WESTERN.findType()); + } + + @Test + @DisplayName("숫자에 맞는 카테고리 타입이 반환되는지 확인한다.") + void checkCorrectMappingCategoryType(){ + String type = Categories.getType(1); + assertThat(type).isEqualTo("일식"); + } +} diff --git a/src/test/java/menu/CoachNameTest.java b/src/test/java/menu/CoachNameTest.java new file mode 100644 index 000000000..f855b7f29 --- /dev/null +++ b/src/test/java/menu/CoachNameTest.java @@ -0,0 +1,42 @@ +package menu; + +import menu.model.CoachNames; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.*; + +class CoachNameTest { + + private static final String errorMessage = "[ERROR]"; + + @Test + @DisplayName("',' 로 구분되어 코치 이름이 List에 저장되는지 확인한다.") + void checkSaveCoachNames(){ + CoachNames coachNames = new CoachNames("토미,제임스,포코"); + + List names = coachNames.getCoachNames(); + + assertThat(names).containsExactly("토미", "제임스", "포코"); + } + + @Test + @DisplayName("코치 이름이 2~4글자 사이로 작성하지 않으면 에러가 발생한다.") + void validateCoachNameLength(){ + assertThatThrownBy(() -> new CoachNames("토미,제임스123,포코")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(errorMessage); + + } + + @Test + @DisplayName("코치는 최소 2명, 최대 5명으로 작성하지 않으면 에러가 발생한다.") + void validateCoachNumber(){ + assertThatThrownBy(() -> new CoachNames("토미,제임스,포코,우테코,네이버,카카오")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(errorMessage); + + } +} diff --git a/src/test/java/menu/ForbiddenMenuTest.java b/src/test/java/menu/ForbiddenMenuTest.java new file mode 100644 index 000000000..8e6bc032f --- /dev/null +++ b/src/test/java/menu/ForbiddenMenuTest.java @@ -0,0 +1,34 @@ +package menu; + +import menu.model.ForbiddenMenu; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; + +import java.util.List; +import java.util.Map; + +class ForbiddenMenuTest { + + ForbiddenMenu forbiddenMenu = new ForbiddenMenu(); + + @Test + @DisplayName("코치 별로 못 먹는 메뉴가 저장되는지 확인한다.") + void checkSaveCoachForbiddenMenu(){ + //given + forbiddenMenu.add("토미", "우동,스시"); + + //when + Map> forbiddenMenus = forbiddenMenu.getForbiddenMenus(); + + //then + assertThat(forbiddenMenus) + .containsEntry("토미", List.of("우동", "스시")); + } + + @Test + @DisplayName("못 먹는 음식이 없을 경우 true를 반환한다.") + void isNotContainForbiddenMenu(){ + assertThat(forbiddenMenu.isNotContainForbiddenMenu("토미", "비빔밥")).isTrue(); + } +} diff --git a/src/test/java/menu/InputValidateTest.java b/src/test/java/menu/InputValidateTest.java new file mode 100644 index 000000000..a6f30a005 --- /dev/null +++ b/src/test/java/menu/InputValidateTest.java @@ -0,0 +1,29 @@ +package menu; + +import menu.view.validate.InputValidator; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; + +class InputValidateTest { + + private static final String errorMessage = "[ERROR]"; + InputValidator inputValidator = new InputValidator(); + + @Test + @DisplayName("코치 이름이 ','로 구분되어 입력 받지 못하면 에러가 발생한다.") + void validateSplitComma(){ + assertThatThrownBy(() -> inputValidator.validateCommaContain("토미/제임스/포코")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(errorMessage); + + } + + @Test + @DisplayName("못 먹는 메뉴의 개수가 최소 0개, 최대 2개가 아니면 에러가 발생한다.") + void validateForbiddenMenuCount(){ + assertThatThrownBy(() -> inputValidator.validateForbiddenMenuCount("우동,스시,비빔밥")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(errorMessage); + } +} diff --git a/src/test/java/menu/MenuTest.java b/src/test/java/menu/MenuTest.java new file mode 100644 index 000000000..3e6040788 --- /dev/null +++ b/src/test/java/menu/MenuTest.java @@ -0,0 +1,40 @@ +package menu; + +import menu.constant.Menus; +import menu.model.CoachNames; +import menu.model.ForbiddenMenu; +import menu.model.RecommendCategory; +import menu.model.RecommendMenu; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.*; + + +class MenuTest { + + CoachNames coachNames = new CoachNames("토미,제임스,포코"); + ForbiddenMenu forbiddenMenu = new ForbiddenMenu(); + + + + @Test + @DisplayName("추천된 메뉴가 코치 수 만큼 저장되는지 확인한다.") + void checkSaveRecommendMenus(){ + RecommendMenu recommendMenu = new RecommendMenu(); + RecommendCategory recommendCategory = new RecommendCategory(); + recommendCategory.createRecommendCategory(); + recommendMenu.createRecommendMenu(coachNames, forbiddenMenu, recommendCategory); + + assertThat(recommendMenu.getMenus().size()).isEqualTo(3); + } + + @Test + @DisplayName("type에 맞는 음식들이 반환되는지 확인한다.") + void checkCorrectMappingMenu(){ + List menus = Menus.getFoods("일식"); + assertThat(menus).isEqualTo(List.of("규동", "우동", "미소시루", "스시", "가츠동", "오니기리", "하이라이스", "라멘", "오코노미야끼")); + } +}