Skip to content

feat(assertion): Add DefaultPrepAndExpectedTestCase.setFailureHandler() - #911

Merged
jeffjensen merged 1 commit into
mainfrom
865-prepandexpectedtestcase-failurehandler
Aug 6, 2026
Merged

feat(assertion): Add DefaultPrepAndExpectedTestCase.setFailureHandler()#911
jeffjensen merged 1 commit into
mainfrom
865-prepandexpectedtestcase-failurehandler

Conversation

@jeffjensen

@jeffjensen jeffjensen commented Aug 6, 2026

Copy link
Copy Markdown
Member

Summary

  • DefaultPrepAndExpectedTestCase.verifyData() always compared tables via Assertion.assertWithValueComparer(ITable, ITable, Column[], ValueComparer, Map), which internally builds its own DefaultFailureHandler and throws on the first mismatch found — there was no way to plug in a different FailureHandler.
  • Add a failureHandler property (getter/setter), defaulting to null so compareData() keeps using the additionalColumnInfo-based Assertion.assertWithValueComparer(...) overload (and its DefaultFailureHandler) unchanged; when set, compareData() uses the FailureHandler-based overload with the configured handler instead — e.g. a DiffCollectingFailureHandler to collect every Difference instead of failing fast.
  • Add unit tests in DefaultPrepAndExpectedTestCaseTest covering the null-default (unchanged) path and the configured-handler (collects-differences-instead-of-throwing) path.

Fixes #865

Test plan

  • ./mvnw clean test — 1969 unit tests pass
  • CI matrix across all 9 databases

🤖 Generated with Claude Code

Summary by Sourcery

Allow DefaultPrepAndExpectedTestCase to use a configurable FailureHandler when verifying data while preserving the existing fail-fast default behavior.

New Features:

  • Add an optional FailureHandler property with getter and setter on DefaultPrepAndExpectedTestCase to customize how verifyData() handles assertion failures.

Documentation:

  • Document the new FailureHandler behavior for DefaultPrepAndExpectedTestCase in class Javadoc and update the 3.4.1-SNAPSHOT release notes in changes.xml.

Tests:

  • Add unit tests validating the default null FailureHandler behavior and the use of DiffCollectingFailureHandler to collect differences instead of throwing.

Summary by CodeRabbit

  • New Features

    • Added optional failure handling for data verification.
    • Verification continues to fail immediately by default.
    • Configured handlers can collect mismatches without interrupting verification.
  • Documentation

    • Documented failure-handler configuration and its default behavior.
    • Updated the 3.4.1-SNAPSHOT release description.

@sourcery-ai

sourcery-ai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds an optional FailureHandler to DefaultPrepAndExpectedTestCase so verifyData()/compareData() can use a caller-supplied handler instead of always failing fast with the default, and introduces tests plus changelog updates to cover and document the new behavior.

Sequence diagram for DefaultPrepAndExpectedTestCase.compareData() failure handling

sequenceDiagram
    participant TestCase as DefaultPrepAndExpectedTestCase
    participant Assertion
    participant FailureHandler

    TestCase->>TestCase: verifyData()
    TestCase->>TestCase: compareData(expectedTable, actualTable, ...)

    alt failureHandler is null
        TestCase->>Assertion: assertWithValueComparer(expectedTable, actualTable, additionalColumnInfo, defaultValueComparer, columnValueComparers)
        Assertion-->>TestCase: uses DefaultFailureHandler (fail-fast)
    else failureHandler is set
        TestCase->>Assertion: assertWithValueComparer(expectedTable, actualTable, failureHandler, defaultValueComparer, columnValueComparers)
        Assertion->>FailureHandler: delegate mismatches to supplied handler
    end
Loading

File-Level Changes

Change Details Files
Make verifyData()/compareData() use an optional, configurable FailureHandler while preserving the previous fail-fast default behavior when unset.
  • Introduce a private FailureHandler field with Javadoc describing the default-null behavior and its interaction with compareData().
  • Update compareData() to branch between the existing DefaultFailureHandler-backed assertWithValueComparer overload and the FailureHandler-based overload when a handler is configured.
  • Add public getFailureHandler()/setFailureHandler(FailureHandler) accessors with @SInCE tags for external configuration.
  • Extend class-level documentation to explain the default fail-fast behavior and how to use DiffCollectingFailureHandler to collect all differences.
src/main/java/org/dbunit/DefaultPrepAndExpectedTestCase.java
Add unit tests validating both the default (no handler) behavior and the configured FailureHandler behavior for verifyData().
  • Import DiffCollectingFailureHandler for use in tests.
  • Add a test asserting that the default failureHandler is null on a freshly constructed test case.
  • Add a test confirming that verifyData() without a configured FailureHandler still throws on a mismatch (fail-fast).
  • Add a test confirming that verifyData() with a DiffCollectingFailureHandler configured does not throw and records the mismatch in the handler’s diff list.
src/test/java/org/dbunit/DefaultPrepAndExpectedTestCaseTest.java
Document the new FailureHandler configuration option in the changelog entry for the upcoming 3.4.1-SNAPSHOT release. src/changes/changes.xml

Assessment against linked issues

Issue Objective Addressed Explanation
#865 Add a configurable FailureHandler property (getter and setter) to DefaultPrepAndExpectedTestCase, defaulting to null.
#865 Update compareData()/verifyData() so that when failureHandler is null it preserves the existing behavior using Assertion.assertWithValueComparer(..., Column[], ...), and when failureHandler is set it uses the FailureHandler-based Assertion.assertWithValueComparer(..., FailureHandler, ...) overload.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jeffjensen, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 44 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7d03707d-0ae3-4bb3-9c0a-67d1921146d1

📥 Commits

Reviewing files that changed from the base of the PR and between 7ebd6e5 and dcef8a5.

📒 Files selected for processing (3)
  • src/changes/changes.xml
  • src/main/java/org/dbunit/DefaultPrepAndExpectedTestCase.java
  • src/test/java/org/dbunit/DefaultPrepAndExpectedTestCaseTest.java
📝 Walkthrough

Walkthrough

DefaultPrepAndExpectedTestCase now accepts an optional FailureHandler. Default verification remains fail-fast. A configured handler receives comparison differences. Tests cover both behaviors, and the change is documented in the release notes.

Changes

Failure handler support

Layer / File(s) Summary
Failure handler configuration and comparison dispatch
src/main/java/org/dbunit/DefaultPrepAndExpectedTestCase.java
The class stores an optional FailureHandler, exposes getter and setter methods, and selects the default or configured assertion overload.
Failure-handler validation and release notes
src/test/java/org/dbunit/DefaultPrepAndExpectedTestCaseTest.java, src/changes/changes.xml
Tests cover the null default, fail-fast mismatches, and collected differences. Release notes document the new support.

Estimated code review effort: 2 (Simple) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Test
  participant DefaultPrepAndExpectedTestCase
  participant Assertion
  participant FailureHandler

  Test->>DefaultPrepAndExpectedTestCase: verifyData()
  DefaultPrepAndExpectedTestCase->>Assertion: compareData()
  alt No configured handler
    Assertion->>Assertion: use default fail-fast handler
    Assertion-->>Test: throw Error on mismatch
  else Configured handler
    DefaultPrepAndExpectedTestCase->>Assertion: pass FailureHandler
    Assertion->>FailureHandler: collect mismatch
    Assertion-->>Test: complete without throwing
  end
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding configurable failure-handler support to DefaultPrepAndExpectedTestCase.
Linked Issues check ✅ Passed The changes implement issue #865 by adding getter/setter support, preserving null-handler fail-fast behavior, and using configured handlers for comparisons.
Out of Scope Changes check ✅ Passed The changelog, implementation, and tests are directly related to the configured FailureHandler objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 865-prepandexpectedtestcase-failurehandler

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The Javadoc on getFailureHandler/setFailureHandler uses @see {@link #failureHandler} which is a bit redundant and non-idiomatic; consider simplifying to @see #failureHandler or inlining the reference in the descriptive text instead.
  • In testVerifyData_withMismatchAndNoFailureHandlerConfigured_throwsError, asserting against the broad Error type makes the contract less clear; consider asserting the concrete comparison failure type (e.g., DbComparisonFailure or the specific Error subtype actually thrown) to better document the behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The Javadoc on getFailureHandler/setFailureHandler uses `@see {@link #failureHandler}` which is a bit redundant and non-idiomatic; consider simplifying to `@see #failureHandler` or inlining the reference in the descriptive text instead.
- In testVerifyData_withMismatchAndNoFailureHandlerConfigured_throwsError, asserting against the broad Error type makes the contract less clear; consider asserting the concrete comparison failure type (e.g., DbComparisonFailure or the specific Error subtype actually thrown) to better document the behavior.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/java/org/dbunit/DefaultPrepAndExpectedTestCase.java`:
- Around line 71-77: Update the JavaDoc in DefaultPrepAndExpectedTestCase so the
sentence introduced by verifyData() starts with a capitalized subject rather
than beginning directly with the method name. Keep the existing explanation
about DefaultFailureHandler and setFailureHandler(FailureHandler) unchanged, but
rewrite the topic text to read as a complete sentence with a capital letter and
proper punctuation.
🪄 Autofix

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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0703c4b2-118d-403f-8b3a-f1a537b66865

📥 Commits

Reviewing files that changed from the base of the PR and between 7ebd6e5 and 2e1c5a0.

📒 Files selected for processing (3)
  • src/changes/changes.xml
  • src/main/java/org/dbunit/DefaultPrepAndExpectedTestCase.java
  • src/test/java/org/dbunit/DefaultPrepAndExpectedTestCaseTest.java

Comment thread src/main/java/org/dbunit/DefaultPrepAndExpectedTestCase.java
Some tests want DiffCollectingFailureHandler to collect every mismatch
instead of failing on the first one, but that should not become the
default. Add a failureHandler property, defaulting to null so
compareData() keeps using Assertion's own additionalColumnInfo-based
DefaultFailureHandler unchanged; when set, compareData() uses the
configured FailureHandler instead.

Refs: 865
@jeffjensen
jeffjensen force-pushed the 865-prepandexpectedtestcase-failurehandler branch from 2e1c5a0 to dcef8a5 Compare August 6, 2026 14:30
@jeffjensen

Copy link
Copy Markdown
Member Author

Addressed the review feedback in dcef8a5 (amended, single commit):

  • Sourcery@see {@link #failureHandler}. on the getter/setter was non-idiomatic and inconsistent with every other field's Javadoc in this class (@see #databaseTester, @see #dataFileLoader, etc.); simplified to @see #failureHandler to match.
  • SourcerytestVerifyData_withMismatchAndNoFailureHandlerConfigured_throwsError asserted the broad Error type; traced DefaultFailureHandler.handle(Difference)DefaultFailureFactory.createFailure(message, expected, actual) to confirm the concrete type is DbComparisonFailure, and tightened the assertion to that (re-ran the test to confirm it still passes).
  • CodeRabbit — reworded the class Javadoc paragraph so it opens with a capitalized subject (The {@code verifyData()} method hands assertion failures to...) instead of starting mid-sentence with a lowercase method call.

Full unit suite (1969 tests) green after the changes; force-pushed once.

@jeffjensen
jeffjensen merged commit daa8dcd into main Aug 6, 2026
29 checks passed
@jeffjensen
jeffjensen deleted the 865-prepandexpectedtestcase-failurehandler branch August 6, 2026 16:58
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.

Allow configuring the FailureHandler used by DefaultPrepAndExpectedTestCase

1 participant