Skip to content

Test: add unit tests for VetResponse mapping#180

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

Test: add unit tests for VetResponse mapping#180
TatjanaTrajkovic merged 3 commits into
mainfrom
test/units_test_vet_response_dto

Conversation

@TatjanaTrajkovic

@TatjanaTrajkovic TatjanaTrajkovic commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Added VetResponseTest to verify DTO mapping from Vet entity Covered mapping of all fields including nested User and Clinic data Added test case for null clinic scenario
Used reflection to simulate JPA-generated IDs for User and Vet (@mapsid) Ensures correct handling of active status and optional fields

Summary by CodeRabbit

  • Tests
    • Added unit tests for veterinarian response mapping covering cases where a clinic is present or absent.
    • Verifies mapped fields (user ID, name, email, license, specialization, booking info, clinic name) and active/inactive status to ensure consistent response output.

Added VetResponseTest to verify DTO mapping from Vet entity
Covered mapping of all fields including nested User and Clinic data
Added test case for null clinic scenario
Used reflection to simulate JPA-generated IDs for User and Vet (@mapsid)
Ensures correct handling of active status and optional fields
@coderabbitai

coderabbitai Bot commented Apr 9, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@TatjanaTrajkovic has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 41 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 2 minutes and 41 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b61b57d0-6773-47ab-83ec-5cb2c4f2ed8e

📥 Commits

Reviewing files that changed from the base of the PR and between e72fee4 and 577f273.

📒 Files selected for processing (1)
  • src/test/java/org/example/vet1177/dto/response/vet/VetResponseTest.java
📝 Walkthrough

Walkthrough

Adds a new JUnit 5 package-private test class VetResponseTest with two tests validating VetResponse.from(vet) mapping for a vet with a non-null clinic and a vet whose user has a null clinic, including reflection helpers to set User.id and Vet.userId.

Changes

Cohort / File(s) Summary
VetResponse Test Suite
src/test/java/org/example/vet1177/dto/response/vet/VetResponseTest.java
Adds a new test class with two test cases that assert field mappings from VetVetResponse, covering non-null clinic and null clinic scenarios; includes private reflection helpers for setting User.id and Vet.userId.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • johanbriger
  • annikaholmqvist94

Poem

🐰 Hoppity test, a little paw,
Mapping vets with careful awe,
Clinics present or gone away,
Fields align — the assertions say,
A rabbit cheers the green test day.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.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 'Test: add unit tests for VetResponse mapping' clearly and directly describes the main change—adding unit tests for VetResponse DTO mapping, which aligns with the changeset that introduces VetResponseTest with comprehensive test coverage.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/units_test_vet_response_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: 1

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

27-31: Consider extracting reflection field setup into a small helper.

The reflective ID setup is repeated and brittle; a helper keeps tests shorter and easier to maintain.

Suggested refactor
 class VetResponseTest {
+    private static void setField(Object target, String fieldName, Object value) throws Exception {
+        Field field = target.getClass().getDeclaredField(fieldName);
+        field.setAccessible(true);
+        field.set(target, value);
+    }
@@
-        Field idField = User.class.getDeclaredField("id");
-        idField.setAccessible(true);
-        idField.set(user, userId);
+        setField(user, "id", userId);
@@
-        Field vetUserIdField = Vet.class.getDeclaredField("userId");
-        vetUserIdField.setAccessible(true);
-        vetUserIdField.set(vet, userId);
+        setField(vet, "userId", userId);
@@
-        Field idField = User.class.getDeclaredField("id");
-        idField.setAccessible(true);
-        idField.set(user, userId);
+        setField(user, "id", userId);

Also applies to: 39-41, 69-71

🤖 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/response/vet/VetResponseTest.java`
around lines 27 - 31, Extract the repeated reflection logic that sets private id
fields into a small reusable helper in the test class (e.g., a private static
method like setPrivateField(Object target, String fieldName, Object value) or
setId(Object target, Long id)); replace the duplicated blocks that create Field
idField, call setAccessible(true) and idField.set(...) for User and any other
classes with calls to that helper (references: User class, the idField variable
usage in VetResponseTest). Ensure the helper handles
NoSuchFieldException/IllegalAccessException by wrapping or rethrowing as a
runtime exception so tests fail clearly.
🤖 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/response/vet/VetResponseTest.java`:
- Around line 68-85: The test for null-clinic handling omits setting vet.userId
so VetResponse.from(vet) may read a null ID; update the test to set the vet's
userId (as done in the first test) before calling VetResponse.from(vet) — for
example, populate the User.id via reflection (Field idField on User) and then
set vet.setUserId(userId) or otherwise set vet.userId on the Vet instance; then
assert the response contains the expected userId while still asserting
clinicName() is null and isActive() is false to ensure ID mapping is validated
alongside null-clinic behavior.

---

Nitpick comments:
In `@src/test/java/org/example/vet1177/dto/response/vet/VetResponseTest.java`:
- Around line 27-31: Extract the repeated reflection logic that sets private id
fields into a small reusable helper in the test class (e.g., a private static
method like setPrivateField(Object target, String fieldName, Object value) or
setId(Object target, Long id)); replace the duplicated blocks that create Field
idField, call setAccessible(true) and idField.set(...) for User and any other
classes with calls to that helper (references: User class, the idField variable
usage in VetResponseTest). Ensure the helper handles
NoSuchFieldException/IllegalAccessException by wrapping or rethrowing as a
runtime exception so tests fail clearly.
🪄 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: 0c3dab23-e515-4b22-be58-5282e0aa0be8

📥 Commits

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

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

Comment thread src/test/java/org/example/vet1177/dto/response/vet/VetResponseTest.java Outdated

@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

🤖 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/response/vet/VetResponseTest.java`:
- Around line 21-24: The test instantiates User with new User() but the entity
only exposes a parameterized constructor, so update VetResponseTest to construct
User using the available User(...) constructor (provide a valid role and
password fixture values consistent with
src/main/java/org/example/vet1177/entities/User.java) instead of calling the
no-arg constructor; after construction, retain the existing setActive(...) and
setClinic(...) calls (and any other setters at lines 21 and 56-59) to preserve
subsequent test setup.
- Around line 18-20: The test creates a Clinic and calls a non-existent mutator
clinic.setName(...); update VetResponseTest to instantiate Clinic using the
available constructor instead of calling setName — e.g., replace the no-arg new
Clinic() + setName call with a constructor call that sets the name (new
Clinic("Happy Pets Clinic")) or otherwise use the Clinic constructor signature
provided by the Clinic class; adjust the test's Clinic creation in
VetResponseTest accordingly.
🪄 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: 01bad61c-8449-457c-88fe-cb2ffaba2666

📥 Commits

Reviewing files that changed from the base of the PR and between fcbea50 and e72fee4.

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

@TatjanaTrajkovic
TatjanaTrajkovic merged commit ceb8270 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 VetResponse DTO

2 participants