Refactor the logic and add unit test #1708
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Title:
Feature/refactor validation logic and add unit test
Description:
This PR add a unit test to check the situation that:
testProcessCreationFormWithBlankName()
,testProcessCreationFormWithDuplicateName()
,testProcessCreationFormWithInvalidBirthDate
,testProcessUpdateFormWithBlankName()
. Also classify them into each nested class. And add@NotBlank
validation to pet's name in case to avoid invalid situation. Refactor thePetController.java
logic, remove useless part.Problem:
Before this change, it does the useless object
ModuleAttribute
after comment@ModuleAttribute
. And a field in petname
can be null. And thePetControllerTests.java
didn't do the total tests to test each if branch.Solution:
PetController
logic, remove useless code from inner method and method params.@NotBlank
annotation ontoname
field.Type of Change
Please select the type of change you are making:
Changes:
@NotBlank
annotation toname
field.PetController
, delete attribute related code.Local Test ScreenShot:
Additional Information:
I've squash all the commits into a single one. And in my opinion, some unit tests are necessary and essential, so I nested them and write new tests. Also, the
name
field is the important identity, it can't benull
, so add@NotBlank
to avoid.If I made some mistakes or errors, plz tell me. Looking forward to your reply🥰.