Skip to content

Test:chore: add unit tests for Vet entity#179

Merged
TatjanaTrajkovic merged 1 commit into
mainfrom
test/unit_tests_vet_entity
Apr 10, 2026
Merged

Test:chore: add unit tests for Vet entity#179
TatjanaTrajkovic merged 1 commit into
mainfrom
test/unit_tests_vet_entity

Conversation

@TatjanaTrajkovic

@TatjanaTrajkovic TatjanaTrajkovic commented Apr 9, 2026

Copy link
Copy Markdown
Contributor
  • Test constructor initialization
  • Test getters and setters
  • Verify default state
  • Align tests with JPA ID generation (@GeneratedValue, @mapsid)

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for veterinarian entity construction, field assignment, and state validation to improve code reliability.

- Test constructor initialization
- Test getters and setters
- Verify default state
- Align tests with JPA ID generation (@GeneratedValue, @mapsid)
@coderabbitai

coderabbitai Bot commented Apr 9, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

A new JUnit 5 test class was added to verify the Vet entity's constructor overloads, getter/setter behavior, null field initialization from the empty constructor, and userId nullability before persistence.

Changes

Cohort / File(s) Summary
Vet Entity Tests
src/test/java/org/example/vet1177/entities/VetTest.java
Added four test methods validating Vet constructor variants, getter/setter functionality, null field behavior with empty constructor, and userId behavior before entity persistence.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • lindaeskilsson
  • annikaholmqvist94

Poem

🐰 Tests for vets, all neat and clean,
Four methods strong to verify the scene,
Constructors checked, getters proven true,
Null fields dance—our Vet shines through!
Hop along, code is now complete! 🐇

🚥 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 'Test:chore: add unit tests for Vet entity' clearly and specifically describes the main change: adding unit tests for the Vet entity. It directly matches the changeset content.

✏️ 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_entity

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.

@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.

🧹 Nitpick comments (2)
src/test/java/org/example/vet1177/entities/VetTest.java (2)

86-91: Remove trailing free-form comments at file end.

These notes look like temporary checklist text and add noise after the class body.

🧹 Suggested cleanup
-//Testa:
-//
-//Konstruktor med alla fält sätter user, licenseId, specialization och bookingInfo korrekt
-//getUserId() returnerar null innan persist
-//getUser() är null när inte satt
-//Setters fungerar för licenseId, specialization och bookingInfo
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/org/example/vet1177/entities/VetTest.java` around lines 86 -
91, Remove the trailing free-form checklist comments that appear after the
VetTest class body; locate the comments at the end of the file in the VetTest
class (they are plain comment lines describing constructor/getters/setters
behavior) and delete them so only the class and its tests remain—ensure no other
test code is removed and the file ends immediately after the closing brace of
class VetTest.

12-16: Extract repeated User test fixture setup to a helper.

The same User initialization is duplicated in multiple tests. Consolidating it will improve readability and reduce drift risk when fields evolve.

♻️ Suggested refactor
 class VetTest {
+    private User createVetUser() {
+        User user = new User();
+        user.setName("Test User");
+        user.setEmail("test@test.com");
+        user.setPasswordHash("123");
+        user.setRole(Role.VET);
+        return user;
+    }
 
     `@Test`
     void shouldCreateVetWithConstructor() {
         // Arrange
-        User user = new User();
-        user.setName("Test User");
-        user.setEmail("test@test.com");
-        user.setPasswordHash("123");
-        user.setRole(Role.VET);
+        User user = createVetUser();
@@
     void shouldSetAndGetFieldsCorrectly() {
         // Arrange
         Vet vet = new Vet();
-        User user = new User();
-        user.setName("Test User");
-        user.setEmail("test@test.com");
-        user.setPasswordHash("123");
-        user.setRole(Role.VET);
+        User user = createVetUser();
@@
     void userIdShouldBeNullBeforePersist() {
         // Arrange
-        User user = new User();
-        user.setName("Test User");
-        user.setEmail("test@test.com");
-        user.setPasswordHash("123");
-        user.setRole(Role.VET);
+        User user = createVetUser();

Also applies to: 36-40, 70-74

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/org/example/vet1177/entities/VetTest.java` around lines 12 -
16, Extract the duplicated User fixture into a single helper method inside the
VetTest class (e.g., private static User buildTestUser() or createTestUser())
that sets name="Test User", email="test@test.com", passwordHash="123", and
role=Role.VET; then replace the repeated inline initialization blocks (the
blocks that call new User(), setName, setEmail, setPasswordHash, setRole) with
calls to this helper in all tests (including the occurrences around lines shown)
so all tests reuse the same factory and future field changes are made in one
place.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/test/java/org/example/vet1177/entities/VetTest.java`:
- Around line 86-91: Remove the trailing free-form checklist comments that
appear after the VetTest class body; locate the comments at the end of the file
in the VetTest class (they are plain comment lines describing
constructor/getters/setters behavior) and delete them so only the class and its
tests remain—ensure no other test code is removed and the file ends immediately
after the closing brace of class VetTest.
- Around line 12-16: Extract the duplicated User fixture into a single helper
method inside the VetTest class (e.g., private static User buildTestUser() or
createTestUser()) that sets name="Test User", email="test@test.com",
passwordHash="123", and role=Role.VET; then replace the repeated inline
initialization blocks (the blocks that call new User(), setName, setEmail,
setPasswordHash, setRole) with calls to this helper in all tests (including the
occurrences around lines shown) so all tests reuse the same factory and future
field changes are made in one place.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f2fe0ccc-c2b4-4690-9164-d46fdb08ff01

📥 Commits

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

📒 Files selected for processing (1)
  • src/test/java/org/example/vet1177/entities/VetTest.java

@TatjanaTrajkovic TatjanaTrajkovic self-assigned this Apr 9, 2026
@TatjanaTrajkovic
TatjanaTrajkovic merged commit 7f4db7d 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: VetEntityTest – konstruktor och getters

1 participant