-
Notifications
You must be signed in to change notification settings - Fork 41
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
Robert test branch #39
base: main
Are you sure you want to change the base?
Conversation
|
||
@GetMapping(value = "/retrieve/{userId}") | ||
@ResponseBody | ||
public List<PaymentDto> retrieve(@NonNull final @PathVariable String userId) { |
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.
What benefit does @NonNull
provide here?
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.
I added the @nonnull annotation here to make sure that a NullPointerException would be thrown if this method is ever called without userId since userId is required for this method.
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.
I just tested this some more by making curl calls to the API on my terminal. It seems like even if I don't provide a userId the API just treats this as a userId with the value of EMPTYSTRING so I think you are right and this check is not needed. I think the only way userId will be null is if someone specifically passes in an encoded version of null and when I tested that, it was causing the API to throw a BadRequest exception so I think this is already handled.
final List<Integer> ids = IntStream.range(1, 10).boxed().collect(Collectors.toList()); | ||
|
||
this.payments = ids.stream().map(id -> createPaymentDto(Integer.toString(id))) | ||
.collect(Collectors.toList()); |
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.
ids
variable is unnecessary since it's only used once. You can combine these statements together.
this.payments = IntStream.range(1, 10).boxed()
.map(id -> createPaymentDto(Integer.toString(id)))
.collect(Collectors.toList())
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.
Good call out. I have refactored the code and fixed this to removed the redundant variable.
@@ -48,7 +48,7 @@ public <T extends Collection<Payment>> List<PaymentDto> convertPayments(final T | |||
public PaymentDto convertPayment(final Payment payment){ | |||
final String cardNumber = payment.getCardNumber(); | |||
final PaymentDto dto = mapperFacade.map(payment, PaymentDto.class); | |||
dto.setCardNumberLast4(cardNumber.substring(cardNumber.length() - 5)); | |||
dto.setCardNumberLast4(cardNumber.substring(cardNumber.length() - 4)); |
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.
Good job catching this bug! 👍🏻
Details
Revision 2:
Refactoring PaymentController and PaymentControllerTest code to revmove redundant variables.
Why Are We Making This Change?
What Is Changing In This Review?
How Was This Tested?