Test: add ActivityLogControllerTest with Spring Boot 4 setup#154
Conversation
📝 WalkthroughWalkthroughIntroduced a new Spring MVC test class 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 (1)
src/test/java/org/example/vet1177/controller/ActivityLogControllerTest.java (1)
70-75: Consider asserting response size to make the test stricter.Right now only element
0is validated. Adding an array-size assertion will catch accidental extra records in responses.Proposed tightening
+import static org.hamcrest.Matchers.hasSize; import static org.mockito.Mockito.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; @@ - mockMvc.perform(get("/api/activity-logs/record/" + recordId) + mockMvc.perform(get("/api/activity-logs/record/{recordId}", recordId) .header("userId", userId.toString())) .andExpect(status().isOk()) + .andExpect(jsonPath("$", hasSize(1))) .andExpect(jsonPath("$[0].description").value("Created case")) .andExpect(jsonPath("$[0].action").value("CASE_CREATED")) .andExpect(jsonPath("$[0].performedByName").value("Alice"));🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/test/java/org/example/vet1177/controller/ActivityLogControllerTest.java` around lines 70 - 75, The test currently only validates element 0 in the response from mockMvc.perform(get("/api/activity-logs/record/" + recordId) ...), so add an explicit array-size assertion (e.g., assert JSON array length == 1 using jsonPath("$.length()").value(1) or jsonPath("$", hasSize(1))) before the existing element-level assertions to ensure no extra records are returned; update the ActivityLogControllerTest mockMvc.perform chain to include that size check prior to the existing jsonPath checks for description/action/performedByName.
🤖 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/controller/ActivityLogControllerTest.java`:
- Around line 70-75: The test currently only validates element 0 in the response
from mockMvc.perform(get("/api/activity-logs/record/" + recordId) ...), so add
an explicit array-size assertion (e.g., assert JSON array length == 1 using
jsonPath("$.length()").value(1) or jsonPath("$", hasSize(1))) before the
existing element-level assertions to ensure no extra records are returned;
update the ActivityLogControllerTest mockMvc.perform chain to include that size
check prior to the existing jsonPath checks for
description/action/performedByName.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 99a612fd-0458-4ec1-9ec8-aaa413c7ce6c
📒 Files selected for processing (1)
src/test/java/org/example/vet1177/controller/ActivityLogControllerTest.java
Summary by CodeRabbit