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 the logic and add unit test #1708

Conversation

wickdynex
Copy link
Contributor

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 the PetController.java logic, remove useless part.


Problem:

Before this change, it does the useless object ModuleAttribute after comment @ModuleAttribute. And a field in pet name can be null. And the PetControllerTests.java didn't do the total tests to test each if branch.

  • Unused Code
  • Nullability Issues
  • Incomplete Test Coverage

Solution:

  • Refactor the PetController logic, remove useless code from inner method and method params.
  • Add @NotBlank annotation onto name field.
  • Write unit test to each if branch, and test it correctness.

Type of Change

Please select the type of change you are making:

  • Bug fix (non-breaking change that fixes an issue)
  • Test (unit tests added)
  • Refactor (code restructuring)
  • Add validate annotation

Changes:

  • Add @NotBlank annotation to name field.
  • Refactor the PetController, delete attribute related code.
  • Add new unit test to each if branch.

Local Test ScreenShot:

image

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 be null, so add @NotBlank to avoid.
If I made some mistakes or errors, plz tell me. Looking forward to your reply🥰.

-<add>: add `@NotBlank` validation to pet's name.
-<refactor>: delete useless code and add unit test to check duplicate Pet name validation logic.
-<modify>: add `Id` to pet in unit test.
-<refactor>: classify unit test.

<modify>: adjust code format.
@dsyer dsyer merged commit 50866de into spring-projects:main Nov 8, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants