test: add unit tests for PetController#196
Conversation
|
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 (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughA new Spring MVC test class Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✅ 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
🤖 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/controller/PetControllerTest.java`:
- Around line 104-115: Add a new test method alongside
createPet_whenForbidden_shouldReturn403 that simulates petService.createPet
throwing a RuntimeException and asserts the controller maps it to HTTP 500;
specifically, mock petService.createPet(...) to thenThrow(new
RuntimeException("...")), call mockMvc.perform(post("/pets")...) with the same
.with(authenticatedAs(vet)), .header("currentUserId", UUID.randomUUID()),
.contentType(MediaType.APPLICATION_JSON) and
.content(objectMapper.writeValueAsString(validPetRequest())), and
expect(status().isInternalServerError()) to verify the mapping.
- Line 3: Change the incorrect import for ObjectMapper in PetControllerTest:
replace the current tools.jackson.databind import with
com.fasterxml.jackson.databind.ObjectMapper so the test class
(PetControllerTest) compiles; update the import statement at the top of the file
and ensure any usages of ObjectMapper in the test remain unchanged (e.g., fields
or methods referencing ObjectMapper).
🪄 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: 82c26e23-51c6-41dc-84a8-e8b6651cedbc
📒 Files selected for processing (1)
src/test/java/org/example/vet1177/controller/PetControllerTest.java
Closes #145
Täcker POST /pets, GET /pets/{petId}, GET /pets/owner/{ownerId}, PUT /pets/{petId} och DELETE /pets/{petId} inklusive happy path, valideringsfel, 403 och 404.
Summary by CodeRabbit