Test:chore: add unit tests for Vet entity#179
Conversation
- Test constructor initialization - Test getters and setters - Verify default state - Align tests with JPA ID generation (@GeneratedValue, @mapsid)
📝 WalkthroughWalkthroughA 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
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.
🧹 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 repeatedUsertest fixture setup to a helper.The same
Userinitialization 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
📒 Files selected for processing (1)
src/test/java/org/example/vet1177/entities/VetTest.java
Summary by CodeRabbit