Skip to content

Add JUnit 5 tests for 5 least-covered service/API classes#137

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1775709327-improve-test-coverage
Open

Add JUnit 5 tests for 5 least-covered service/API classes#137
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1775709327-improve-test-coverage

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Apr 9, 2026

Copy link
Copy Markdown

Summary

Adds unit tests for the 5 least-covered classes in the service layer and API exception handling, identified via JaCoCo coverage analysis. All tests are additive — no production code was modified.

Baseline coverage: 33% instruction coverage → 37% after these tests (110 tests total, up from 68).

New Test Class Target Class Prior Coverage Pattern
ArticleCommandServiceTest (7 tests) ArticleCommandService 6.7% Mockito @Mock/@InjectMocks
CommentQueryServiceCursorTest (9 tests) CommentQueryService 51.2% Mockito, focuses on findByArticleIdWithCursor
CustomizeExceptionHandlerTest (7 tests) CustomizeExceptionHandler 63.4% Direct instantiation + mocked exceptions
UserServiceTest (8 tests) UserService 71.4% Mockito with mocked PasswordEncoder
CursorPagerTest (11 tests) CursorPager 73.3% Plain unit tests, no mocks

Each test class covers happy path, error cases, and edge cases (e.g., null user, empty lists, nested constraint violation paths).

Review & Testing Checklist for Human

  • ArticleCommandServiceTest.should_create_article_with_null_tag_list asserts NullPointerException — this documents current behavior where null tag list causes an NPE in Article constructor. Verify this is acceptable rather than masking a bug that should be fixed with graceful handling.
  • UserServiceTest mocks bypass Spring's @Validated — the @UpdateUserConstraint validator logic (UpdateUserValidator) is never exercised by these tests. The tests verify User.update() delegation but not duplicate-email/username validation. This is by design for unit tests but worth noting.
  • CustomizeExceptionHandlerTest does NOT cover handleMethodArgumentNotValid (the @Override method). The handler has 4 exception-handling methods but only 3 are tested. Consider whether this gap matters.
  • Run ./gradlew test jacocoTestReport locally and verify all 110 tests pass. The build will report a JaCoCo verification failure (37% < 80% threshold) which is expected — overall coverage is still dragged down by the untested GraphQL layer.

Notes

  • The @SuppressWarnings("unchecked") usage in CustomizeExceptionHandlerTest is necessary due to Mockito's generic type limitations when mocking ConstraintViolation<?> and ConstraintDescriptor<?>. The doReturn().when() pattern is used instead of when().thenReturn() to work around wildcard capture issues.
  • Overall project coverage remains at 37% (below the 80% JaCoCo threshold) primarily because the GraphQL datafetcher/mutation layer (~12 classes) has near-zero coverage and was out of scope for this PR.

Link to Devin session: https://partner-workshops.devinenterprise.com/sessions/2bbc0116e91f42988ece07e935d863af


Open with Devin

- ArticleCommandServiceTest: tests create/update article flows
- CommentQueryServiceCursorTest: tests cursor pagination, following status
- CustomizeExceptionHandlerTest: tests all exception handler methods
- UserServiceTest: tests user creation and update operations
- CursorPagerTest: tests pagination direction, cursors, edge cases

Coverage improved from 33% to 37% instruction coverage.
New tests: 42 test methods covering happy path, error, and edge cases.
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant