-
Notifications
You must be signed in to change notification settings - Fork 168
[2기-유민환] SpringBoot Part1 Weekly Mission 제출합니다. #186
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
[2기-유민환] SpringBoot Part1 Weekly Mission 제출합니다. #186
Conversation
bosuksh
left a comment
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.
안녕하세요 민환님
과제하느라 수고 많으셨어요.
코드도 굉장히 깔끔하고 리뷰할 점이 그렇게 많지는 않았던 것 같네요~!
몇개 코멘트 달았으니 확인해주세요
질문에 대해서 답변을 드리자면
- checked Exception을 모두 만들어주면 좋겠지만, 사실 그럴 상황이 되지 못할 경우가 더 많습니다. 그렇기에 꼭 필요한 Exception 위주로 먼저 해주고, 한꺼번에 처리할 수 있는 Exception을 만들어서 한꺼번에 처리할 수 있는건 처리해주는것도 좋은 방법 일 것 같네요. 예를 들어 입력이 잘 못되었을 경우 사용하는 Exception을 만들어서 여기저기서 사용하는 거죠
- Exception을 적절한 변환을 통해 처리하는 방법은 충분히 가능한 방법이라고 생각합니다~!
- logger에 경우에는 아래에도 코멘트를 남겼지만, 에러 로그라고 해서 모두 찍어줄 필요는 없고, 에러가 발생했을 때 크리티컬한 부분 위주로 찍어주는게 좋을 듯 싶어요! 예를 들어, 레포지토리에서 데이터를 못가져온 경우같은 곳이요! 너무 많은 로깅은 성능 저하를 일으킬 수 있거든요~
- Resource로 관리하지 않고 사용하는 FileUserRepository에서 @value 를 이용해서 주입받아도 저는 크게 상관이 없다고 생각하네요! 처음에는 최대한 단순하게 만드는걸 선호해서요
- Mock하는 경우는 주로 mocking 프레임워크인 mockito 같은 것을 사용합니다. Mockig 프레임워크를 사용하면 간단하게 input과 output을 설정할 수 있어요. Mocking 프레임워크에 대한건 아래 링크를 걸어놨으니 확인해주세요
- 검증에 대한 책임은 본인이 설정하기 나름이지만 민환님이 설정하신 검증에 대한 책임은 좋은것 같아요
| </appender> | ||
|
|
||
| <root level="info"> | ||
| <appender-ref ref="CONSOLE"/> |
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.
log level info를 콘솔로 해두다보니 console프로그램에서 로그도 같이 찍히는 현상이 발생하네요~
이부분은 콘솔프로그램에서 영향이 가니 피하는게 좋겠죠?
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.
요구사항만 생각하다보니 콘솔에 영향을 가는 것을 생각을 못했네요 😂
| public List<User> findBlackUsers() { | ||
| List<User> users = new ArrayList<>(); | ||
| try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(userResource.getInputStream()))) { | ||
| addBlackUsers(users, bufferedReader); | ||
| } catch (IOException e) { | ||
| throw new IllegalArgumentException(ERROR_WRONG_FILE); | ||
| } | ||
| logger.info("BlackUsers read at File => {}", users); | ||
| return users; | ||
| } |
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.
이부분은 블랙리스트에 추가하는 메소드가 있으면 이렇게 하는게 맞다고 생각하는데
블랙리스트에 추가하는 메소드가 없기 때문에 인스턴스 생성시 미리 가져오는걸 생각해봐도 좋을것 같습니다~!
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 saveVoucherAtFile(Voucher voucher) { | ||
| try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(FILE_NAME, true))) { | ||
| objectOutputStream.writeObject(voucher); | ||
| } catch (IOException e) { | ||
| throw new IllegalArgumentException(ERROR_WRONG_FILE); | ||
| } | ||
| } |
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.
save에서 같은 역할을 해주기 때문에 save안에서 구현해도 될 것 같네요~
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.
클린 코드를 한다고 기계적으로 메서드 추출을 하다보니 중복되게 만든 것 같습니다 😂
| class VoucherServiceTest { | ||
|
|
||
| VoucherService voucherService = new VoucherService(new VoucherRepository() { | ||
| @Override | ||
| public Voucher save(Voucher voucher) { | ||
| return voucher; | ||
| } | ||
|
|
||
| @Override | ||
| public List<Voucher> findAll() { | ||
| try { | ||
| return Arrays.asList(new FixedAmountVoucher(UUID.randomUUID(), 10L), | ||
| new PercentDiscountVoucher(UUID.randomUUID(), 20L)); | ||
| } catch (Exception ignored) { | ||
| } | ||
| return null; | ||
| } | ||
| }); |
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.
이부분은 mock 프레임워크를 이용해서 구현해보면 좋을 것 같네요
그 예로 Mockito를 사용하면 클래스를 구현하지 않고 바로 값을 넣을수 있습니다.
https://lemontia.tistory.com/915
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.
어제 강의를 통해 Mock에 대해 배울 수 있었습니다.
제가 사용한 방식은 Stub이더군요
Mockito에 대한 내용 감사합니다!
| import org.prgms.voucherProgram.exception.WrongDiscountAmountException; | ||
| import org.prgms.voucherProgram.exception.WrongDiscountPercentException; | ||
|
|
||
| class FileVoucherRepositoryTest { |
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.
바우처를 가져오지 못한 테스트케이스도 추가하면 좋겠네요
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.
테스트 커버리지를 높이도록 노력해야겠습니다..
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public class VoucherProgram { |
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.
logging을 찍는 이유는, 어떤 에러를 트레이싱하기 위해서 찍는 경우가 많은데요.
이 클래스에서 찍는 에러는 대부분 사용자가 잘못입력했을 때, 즉 시스템 말고 사용자의 문제로 인해서 exception이 발생한 경우이고 그 에러에 대해서는 화면으로 출력을 해주기 때문에 사용자가 인지하고 수정할 것입니다.
그렇기 때문에 이부분의 데이터를 모아서 어떤 통계정 사용이든, 다른 용도로 사용할게 아니라면 굳이 찍을 필요는 없을 것 같아요
로그도 결국 IO를 하는 과정이기 때문에 너무 많은 로깅은 성능의 저하를 일으킬 수 있습니다.
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.
의도한 에러는 로그를 찍을 필요가 없고 의도치 않은 에러는 로그로 관리해야 한다는 뜻으로 받아드리면 될까요?
|
안녕하세요 아만드님! 질문
|
📌 과제 설명
exit,create,list,blacklist)를 지원합니다.jar로도 실행가능하도록 하였습니다.👩💻 요구 사항과 구현 내용
Console
AppConfiguration
VoucherProgram
exit,create,list,blacklist)exit요청이 들어온 경우 프로그램을 종료합니다.list요청이 들어온 경우voucherService에게 저장되어 있는 voucher 정보를 요청합니다.create요청이 들어온 경우 voucher종류와 할인값을 입력받습니다.voucherService에게 voucher 생성을 요청합니다.blacklist요청이 들어온 경우userService에게 저장된 블랙 리스트 정보를 요청합니다.📁 entity
📁 exception
📁 repository
📁 service
✅ PR 포인트 & 궁금한 점
이번에는 checked exception을 사용하기 위해 재정의하여 만들어 보았는 데 꼭 해주는 것이 좋을까요?
FileVoucherRepository의 경우 Exception을 throws로 처리하게 되면 메서드 시그니처가 변해 try-catch를 통해 unchecked exception으로 변환해주었습니다.
logger를 처음 사용해봤는 데 제대로 사용한 지 모르겠습니다.
현재는 블랙리스트 파일만 Resource로 가져왔습니다. Voucher파일 Resource로 가져왔을 때 IDE상에서는 정상적이였지만 jar 실행에서는 에러가 발생합니다.
테스트에서 아래와 같이 사용해보았는 데 저렇게 하는 것이 Mock객체를 사용하는 방법이 맞나요?
검증에 대한 기준이 아직 잡히지 않는 것 같습니다.