Skip to content

Test/unit tests vet request dto#183

Merged
TatjanaTrajkovic merged 3 commits into
mainfrom
test/unit_tests_vet_request_dto
Apr 10, 2026
Merged

Test/unit tests vet request dto#183
TatjanaTrajkovic merged 3 commits into
mainfrom
test/unit_tests_vet_request_dto

Conversation

@TatjanaTrajkovic

@TatjanaTrajkovic TatjanaTrajkovic commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Tests
    • Added a new test suite for request validation that initializes validation in setup.
    • Includes a positive test for a fully valid request and three negative tests covering a missing required identifier, a blank value, and an over-length value.
    • Added a helper assertion to check for specific validation violations.

* 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
@coderabbitai

coderabbitai Bot commented Apr 9, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 555f2883-95e7-445a-943c-4224d13956fc

📥 Commits

Reviewing files that changed from the base of the PR and between b15ae6d and 7716ec3.

📒 Files selected for processing (1)
  • src/test/java/org/example/vet1177/dto/request/vet/VetRequestTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/java/org/example/vet1177/dto/request/vet/VetRequestTest.java

📝 Walkthrough

Walkthrough

Adds a new JUnit 5 test class VetRequestTest that initializes a Jakarta Bean Validation Validator and contains four tests validating VetRequest constraints: one valid case and three invalid cases (null userId, blank licenseId, and overly long licenseId).

Changes

Cohort / File(s) Summary
VetRequest Validation Tests
src/test/java/org/example/vet1177/dto/request/vet/VetRequestTest.java
Added a new test class (≈79 lines) that sets up a Validator and includes four tests: valid input, userId null, licenseId blank, and licenseId too long; includes a helper assertHasViolation(...) to check field-specific violations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • annikaholmqvist94
  • lindaeskilsson

Poem

🐰 I hopped through fields of code tonight,
Checking lengths and nulls by moonlight,
A blank, a long one, and one that's true,
I nudged each constraint — yes, they all knew. 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding unit tests for the VetRequest DTO using JUnit 5 and Bean Validation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/unit_tests_vet_request_dto

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@TatjanaTrajkovic TatjanaTrajkovic linked an issue Apr 9, 2026 that may be closed by this pull request

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/test/java/org/example/vet1177/dto/request/vet/VetRequestTest.java (1)

22-78: Add tests for remaining VetRequest constraints (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

📥 Commits

Reviewing files that changed from the base of the PR and between 5a74e27 and b15ae6d.

📒 Files selected for processing (1)
  • src/test/java/org/example/vet1177/dto/request/vet/VetRequestTest.java

Comment thread src/test/java/org/example/vet1177/dto/request/vet/VetRequestTest.java Outdated
@TatjanaTrajkovic TatjanaTrajkovic self-assigned this Apr 9, 2026
* 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
@TatjanaTrajkovic
TatjanaTrajkovic merged commit a4c514c into main Apr 10, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test: add unit tests for VetRequest

1 participant