Test/unit tests vet request dto#183
Conversation
* Added unit tests to verify Bean Validation constraints on VetRequest * Covered required fields (@NotNull, @notblank) and size limits (@SiZe) * Ensured valid input passes without violations * Verified invalid inputs produce expected validation errors * Improves API input validation reliability and test coverage
* Added unit tests to verify Bean Validation constraints on VetRequest * Covered required fields (@NotNull, @notblank) and size limits (@SiZe) * Ensured valid input passes without violations * Verified invalid inputs produce expected validation errors * Improves API input validation reliability and test coverage
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a new JUnit 5 test class Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/test/java/org/example/vet1177/dto/request/vet/VetRequestTest.java (1)
22-78: Add tests for remainingVetRequestconstraints (specialization,bookingInfo) and boundary values.Current suite skips
@Size(max = 250)and@Size(max = 500), and does not verify exact boundary acceptance (50/250/500).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/test/java/org/example/vet1177/dto/request/vet/VetRequestTest.java` around lines 22 - 78, Add tests in VetRequestTest to cover the remaining VetRequest constraints and exact boundary values: add a test that asserts a licenseId of length 50 is valid (function: should_pass_when_licenseId_length_50), add tests for specialization max 250 (should_pass_when_specialization_length_250 and should_fail_when_specialization_length_251), and add tests for bookingInfo max 500 (should_pass_when_bookingInfo_length_500 and should_fail_when_bookingInfo_length_501); construct VetRequest instances with UUID.randomUUID() and the exact-length strings, validate with validator.validate(request) and assertEmpty for the valid bounds and assertFalse for the one-above limits to exercise `@Size`(max=50/250/500) on VetRequest.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/test/java/org/example/vet1177/dto/request/vet/VetRequestTest.java`:
- Around line 4-5: The tests in VetRequestTest create a ValidatorFactory and
Validator in a `@BeforeEach` which leaks resources; change to a class-level
lifecycle: make ValidatorFactory factory and Validator validator static fields,
initialize them in a `@BeforeAll` method and close the factory in an `@AfterAll`
method, and update any setup/reference code that currently uses the
instance-level `@BeforeEach` so the tests use the shared static validator without
recreating the factory per test.
- Line 47: Tests in VetRequestTest only assert that "violations" is non-empty
but don't assert which property failed; add a helper in the VetRequestTest class
(e.g., assertViolationPropertyPath or assertContainsViolationForProperty) that
accepts the Set<ConstraintViolation<?>> and an expected property path string,
iterates the violations to collect violation.getPropertyPath().toString(), and
asserts the expected property path is present; replace the existing
assertFalse(violations.isEmpty()) checks in the test cases with calls to this
helper (using the same local variable violations) to verify the specific field
that caused the validation failure.
---
Nitpick comments:
In `@src/test/java/org/example/vet1177/dto/request/vet/VetRequestTest.java`:
- Around line 22-78: Add tests in VetRequestTest to cover the remaining
VetRequest constraints and exact boundary values: add a test that asserts a
licenseId of length 50 is valid (function:
should_pass_when_licenseId_length_50), add tests for specialization max 250
(should_pass_when_specialization_length_250 and
should_fail_when_specialization_length_251), and add tests for bookingInfo max
500 (should_pass_when_bookingInfo_length_500 and
should_fail_when_bookingInfo_length_501); construct VetRequest instances with
UUID.randomUUID() and the exact-length strings, validate with
validator.validate(request) and assertEmpty for the valid bounds and assertFalse
for the one-above limits to exercise `@Size`(max=50/250/500) on VetRequest.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 572c1ff7-563a-4786-9511-a2ae7a536f10
📒 Files selected for processing (1)
src/test/java/org/example/vet1177/dto/request/vet/VetRequestTest.java
* Added helper method to assert specific constraint violations per field * Replaced generic "violations not empty" checks with precise field validation * Ensures tests fail only when incorrect fields are validated * Improves robustness and accuracy of validation test coverage
Summary by CodeRabbit