diff --git a/src/main/java/com/atwoz/member/domain/info/hobby/HobbyName.java b/src/main/java/com/atwoz/member/domain/info/hobby/HobbyName.java index d57df97c..fd34e5e3 100644 --- a/src/main/java/com/atwoz/member/domain/info/hobby/HobbyName.java +++ b/src/main/java/com/atwoz/member/domain/info/hobby/HobbyName.java @@ -51,24 +51,34 @@ public enum HobbyName { } public static List findAllByNames(final List names) { - validateSize(names); + validateNames(names); return names.stream() .map(HobbyName::from) .toList(); } - public static void validateSize(final List names) { + private static void validateNames(final List names) { + validateIsNotEmptyNames(names); + validateIsUniqueNames(names); + validateIsNotOverMaxSizeOfHobby(names); + } + + private static void validateIsNotEmptyNames(final List names) { if (names.isEmpty()) { throw new HobbySizeException(); } + } + private static void validateIsUniqueNames(final List names) { Set uniqueNames = new HashSet<>(names); if (uniqueNames.size() != names.size()) { throw new HobbyDuplicateException(); } + } + private static void validateIsNotOverMaxSizeOfHobby(final List names) { int validSize = Arrays.stream(values()) - .filter(hobbyName -> uniqueNames.contains(hobbyName.getName())) + .filter(hobbyName -> names.contains(hobbyName.getName())) .toList() .size(); if (validSize > MAX_SIZE) {