-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✅ Refactor: FoodServiceTest Mock으로 리팩토링 (#29) #32
Conversation
synoti21
commented
Oct 15, 2023
- 모든 FoodService 테스트 코드 mocking 완료
- Food 엔티티에 setId() 추가
- validateUser(), validateFood(), validateFavoriteFood() 추가
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다!
private void validateUser(Long userId) { | ||
if (!userRepository.existsById(userId)) | ||
throw new UserException(ResponseCode.USER_NOT_FOUND); | ||
} | ||
|
||
private void validateFood(Long foodId) { | ||
if (!foodRepository.existsById(foodId)) | ||
throw new FoodException(ResponseCode.FOOD_NOT_FOUND); | ||
} | ||
|
||
private void validateFavoriteFood(Long favoriteFoodId) { | ||
if (!favoriteFoodRepository.existsById(favoriteFoodId)) | ||
throw new FavoriteException(ResponseCode.FAVORITE_NOT_FOUND); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
보통 이렇게 두 가지 이상의 Service에서 같은 검증 로직을 공유하는 경우에는 util 패키지에 별도의 싱글톤 클래스를 선언하여 그 내부 메서드를 사용하는 방식을 채택하는 경우도 있습니다만, Service에 두개뿐이라 그렇게까지 할 필요는 없는 것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
조언 감사합니다!