Skip to content

Conversation

@codesungrape
Copy link
Collaborator

This PR performs a technical refactor of BookServiceTest.java to improve test reliability, reduce code redundancy, and enforce stricter assertion logic.
The primary goal is to ensure tests verify the data mapping logic (input passed to the repository) rather than just the mock's return value, mitigating the risk of false positives.

Key Changes:

  • Implemented ArgumentCaptor:
    • Updated testCreateBook_Success and testCreateBook_VeryLongFields_Success to capture and inspect the object passed to save().
    • This ensures the Service layer correctly maps DTO fields to the Entity before persistence.
  • Reduced Redundancy:
    • Consolidated multiple "Invalid Title" tests (Null, Empty, Blank) into a single @ParameterizedTest using @NullAndEmptySource and @valuesource.
    • Merged the "Special Characters" test case into the main success test.
  • Code Hygiene:
    • Removed legacy comments and AI feedback notes.
    • Fixed Checkstyle violations.

Why this matters:
Previously, tests could pass even if the Service layer truncated or altered data, because we were asserting against the Mock's configured response. Using ArgumentCaptor validates the actual transformation logic within the Service.

Checklist:
[x] - Tests pass
[x] - CI/CD passes

Copilot AI review requested due to automatic review settings November 20, 2025 12:01
Copilot finished reviewing on behalf of codesungrape November 20, 2025 12:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors BookServiceTest.java to improve test reliability by using ArgumentCaptor to verify actual data transformations rather than relying solely on mock return values. The refactor consolidates redundant tests into parameterized tests and removes legacy comments.

Key Changes:

  • Introduced ArgumentCaptor in create and delete tests to verify data mapping before persistence
  • Consolidated null/empty/blank title validation tests into a single @ParameterizedTest
  • Merged special characters test into the main success test case

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codesungrape codesungrape merged commit fabccec into main Nov 20, 2025
1 check passed
@codesungrape codesungrape deleted the Refactor-use-ArgumentCaptor-in-tests branch November 20, 2025 12:46
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.

2 participants