Add TicketCommentService test suite - #35
Conversation
…tility methods for user and ticket setup
…CommentServiceTest`
…etCommentServiceTest`
…icketCommentServiceTest`
…ketCommentServiceTest`
… `TicketCommentServiceTest`
… `TicketCommentServiceTest`
…ents in `TicketCommentServiceTest`
… exception in `TicketCommentServiceTest`
…izing annotations and formatting
📝 WalkthroughWalkthroughAdds a comprehensive JUnit 5 test suite for Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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/alfs/services/TicketCommentServiceTest.java (2)
291-305: Minor: missingsavenever-called verification.Unlike the other forbidden-path tests (e.g., lines 288, 271, 237), this one omits
verify(ticketCommentRepository, never()).save(any());. Adding it keeps the forbidden-case assertions consistent.♻️ Suggested addition
assertEquals(HttpStatus.FORBIDDEN, ex.getStatusCode()); + verify(ticketCommentRepository, never()).save(any()); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/test/java/org/example/alfs/services/TicketCommentServiceTest.java` around lines 291 - 305, Add a verification that ticketCommentRepository.save is never called in the anonymous_withNoToken_shouldThrowForbidden test: after asserting the ResponseStatusException and its FORBIDDEN status, call verify(ticketCommentRepository, never()).save(any()) to match the other forbidden-path tests and ensure no save was attempted by ticketCommentService.addComment when ticketRepository.findById(1L) returns the anonymous ticket.
119-124: Nit: misplaced// Act/// Assertcomments.In these three tests the
when(...)stubbing lines are under// Actwhile the actual service call is under// Assert. Swap them to// Arrangeand// Act + Assertto match the other tests' Arrange-Act-Assert structure.Also applies to: 137-142, 155-160
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/test/java/org/example/alfs/services/TicketCommentServiceTest.java` around lines 119 - 124, Rename the misplaced comments: change the "// Act" comment that currently precedes the stubbing lines (when(ticketRepository.findById(1L)), when(ticketCommentRepository.save(...)), when(ticketCommentMapper.entityToViewDTO(...))) to "// Arrange", and change the comment that currently labels the service invocation (the call that follows these stubs and is currently under "// Assert") to "// Act + Assert" so the test follows Arrange → Act(+Assert). Apply the same change pattern to the other two similar blocks that contain the same stubbing + service invocation sequence.
🤖 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/alfs/services/TicketCommentServiceTest.java`:
- Around line 291-305: Add a verification that ticketCommentRepository.save is
never called in the anonymous_withNoToken_shouldThrowForbidden test: after
asserting the ResponseStatusException and its FORBIDDEN status, call
verify(ticketCommentRepository, never()).save(any()) to match the other
forbidden-path tests and ensure no save was attempted by
ticketCommentService.addComment when ticketRepository.findById(1L) returns the
anonymous ticket.
- Around line 119-124: Rename the misplaced comments: change the "// Act"
comment that currently precedes the stubbing lines
(when(ticketRepository.findById(1L)), when(ticketCommentRepository.save(...)),
when(ticketCommentMapper.entityToViewDTO(...))) to "// Arrange", and change the
comment that currently labels the service invocation (the call that follows
these stubs and is currently under "// Assert") to "// Act + Assert" so the test
follows Arrange → Act(+Assert). Apply the same change pattern to the other two
similar blocks that contain the same stubbing + service invocation sequence.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 447bec76-df1d-4c44-9b95-9722187404ef
📒 Files selected for processing (1)
src/test/java/org/example/alfs/services/TicketCommentServiceTest.java
…orbidden in `TicketCommentServiceTest`
TicketCommentService test suite
Summary by CodeRabbit