Skip to content
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

Merged
merged 15 commits into from
Oct 15, 2023

Conversation

synoti21
Copy link
Contributor

  • 모든 FoodService 테스트 코드 mocking 완료
  • Food 엔티티에 setId() 추가
  • validateUser(), validateFood(), validateFavoriteFood() 추가

@synoti21 synoti21 added the refactor 리팩토링 label Oct 15, 2023
@synoti21 synoti21 requested a review from win-luck October 15, 2023 14:41
@synoti21 synoti21 self-assigned this Oct 15, 2023
@synoti21 synoti21 linked an issue Oct 15, 2023 that may be closed by this pull request
@win-luck win-luck changed the title Refactor: FoodServiceTest Mock으로 리팩토링 (#29) ✅ Refactor: FoodServiceTest Mock으로 리팩토링 (#29) Oct 15, 2023
Copy link
Contributor

@win-luck win-luck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!

Comment on lines +210 to +223
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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

보통 이렇게 두 가지 이상의 Service에서 같은 검증 로직을 공유하는 경우에는 util 패키지에 별도의 싱글톤 클래스를 선언하여 그 내부 메서드를 사용하는 방식을 채택하는 경우도 있습니다만, Service에 두개뿐이라 그렇게까지 할 필요는 없는 것 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

조언 감사합니다!

@synoti21 synoti21 merged commit 37e9a28 into master Oct 15, 2023
1 check passed
@synoti21 synoti21 deleted the refactor/29-foodServiceTest-mock branch October 15, 2023 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor 리팩토링
Projects
None yet
Development

Successfully merging this pull request may close these issues.

✅ Refactor: FoodServiceTest Mock으로 리팩토링 (#29)
2 participants