Skip to content

feat(assertion): Add PrepAndExpectedTestData value type - #971

Merged
jeffjensen merged 1 commit into
mainfrom
938-prepandexpected-testdata
Sep 7, 2026
Merged

feat(assertion): Add PrepAndExpectedTestData value type#971
jeffjensen merged 1 commit into
mainfrom
938-prepandexpected-testdata

Conversation

@jeffjensen

@jeffjensen jeffjensen commented Sep 7, 2026

Copy link
Copy Markdown
Member

PrepAndExpectedTestCase.configureTest(), preTest(), and runTest() each take the same (VerifyTableDefinition[], String[] prep, String[] expected) triple. It describes one test scenario and is meaningless split apart, yet in a data-driven test it propagates through the @ParameterizedTest signature, every @MethodSource row, and any row-factory method built to keep those rows readable.

PrepAndExpectedTestData bundles the triple into one immutable value:

  • Defensive-copies each array in and out; normalizes null to empty.
  • A NONE constant and a prepOnly(String...) factory cover the common partial cases, replacing a separate empty constant per array type.
  • equals/hashCode/toString for whole-object assertions in tests.

PrepAndExpectedTestCase gains default configureTest(PrepAndExpectedTestData), preTest(PrepAndExpectedTestData), and runTest(PrepAndExpectedTestData, PrepAndExpectedTestCaseSteps) overloads that unpack the bundle and delegate to the existing array methods. Purely additive: no existing signature changes, no implementor breaks, and
DefaultPrepAndExpectedTestCase needs no edit.

Complements the annotation-driven configuration of issue 753, which serves configuration fixed per test method rather than varying per invocation.

Refs: 938

Claude-Session: https://claude.ai/code/session_01RgQW5ydR5upi3SiuW2oEu2

Summary by Sourcery

Bundle preparation, expected-data, and verification settings into an immutable test value and expose additive PrepAndExpectedTestCase overloads for data-driven scenarios.

New Features:

  • Add the immutable PrepAndExpectedTestData value type for bundling verification definitions, preparation files, and expected files, including shared empty and preparation-only scenarios.
  • Add bundle-based overloads for configuring, preparing, and running PrepAndExpectedTestCase instances while preserving existing APIs.

Enhancements:

  • Provide defensive copying, null normalization, value equality, hashing, and readable string representations for test scenario data.

Documentation:

  • Document the new test-data bundle and its use in PrepAndExpectedTestCase workflows.

Tests:

  • Add coverage for bundle immutability, convenience factories, value semantics, and delegation through the new test-case overloads.

Summary by CodeRabbit

  • New Features

    • Added a way to bundle verification, preparation, and expected data into a single reusable test-data value.
    • Added test API overloads that accept the bundled data, including shortcuts for no data and preparation-only scenarios.
    • Preserved existing test method usage.
  • Documentation

    • Added guidance and examples for using bundled test data with parameterized tests.
  • Tests

    • Added coverage for bundled data handling, immutability, equality, and test execution behavior.

@sourcery-ai

sourcery-ai Bot commented Sep 7, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds PrepAndExpectedTestData as an immutable bundle for verification, prep, and expected test inputs, then exposes additive default PrepAndExpectedTestCase overloads that delegate to the existing array-based API; tests and documentation cover immutability, convenience factories, value semantics, forwarding, and runtime behavior.

Sequence diagram for bundled test data delegation

sequenceDiagram
    participant Caller
    participant TestCase as PrepAndExpectedTestCase
    participant Data as PrepAndExpectedTestData

    Caller->>TestCase: runTest(Data, testSteps)
    TestCase->>Data: getVerifyTableDefinitions()
    Data-->>TestCase: copied definitions
    TestCase->>Data: getPrepDataFiles()
    Data-->>TestCase: copied prep files
    TestCase->>Data: getExpectedDataFiles()
    Data-->>TestCase: copied expected files
    TestCase->>TestCase: runTest(definitions, prep, expected, testSteps)
    TestCase-->>Caller: result
Loading

File-Level Changes

Change Details Files
Introduces an immutable value object for the three pieces of per-invocation test data.
  • Bundles verification definitions, prep files, and expected files.
  • Defensively copies arrays and converts null inputs to empty arrays.
  • Provides NONE and prepOnly factory conveniences.
  • Implements content-based equality, hashing, and diagnostic string rendering.
src/main/java/org/dbunit/PrepAndExpectedTestData.java
src/test/java/org/dbunit/PrepAndExpectedTestDataTest.java
Adds bundle-based convenience APIs without changing existing implementations or signatures.
  • Adds default configureTest and preTest overloads that unpack and delegate.
  • Adds a default runTest overload that forwards bundle contents and test steps.
  • Preserves compatibility with existing implementors and DefaultPrepAndExpectedTestCase.
src/main/java/org/dbunit/PrepAndExpectedTestCase.java
src/test/java/org/dbunit/PrepAndExpectedTestCaseTest.java
src/test/java/org/dbunit/DefaultPrepAndExpectedTestCaseTest.java
Documents and records the new public API and its intended data-driven testing use case.
  • Updates test-case and annotation documentation.
  • Adds the issue/release change-log entry.
src/site/asciidoc/testcases/PrepAndExpectedTestCase.adoc
src/site/asciidoc/testcases/annotations.adoc
src/changes/changes.xml

Possibly linked issues


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 Sep 7, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

Next included review available in 39 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: c5674472-91c3-40f9-ab3a-3e1d6fb95d12

📥 Commits

Reviewing files that changed from the base of the PR and between a6ed9ac and b0181b5.

📒 Files selected for processing (1)
  • src/main/java/org/dbunit/PrepAndExpectedTestData.java

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 29b73696-0f90-4b56-827e-29025bc24427

📥 Commits

Reviewing files that changed from the base of the PR and between 380d414 and a6ed9ac.

📒 Files selected for processing (8)
  • src/changes/changes.xml
  • src/main/java/org/dbunit/PrepAndExpectedTestCase.java
  • src/main/java/org/dbunit/PrepAndExpectedTestData.java
  • src/site/asciidoc/testcases/PrepAndExpectedTestCase.adoc
  • src/site/asciidoc/testcases/annotations.adoc
  • src/test/java/org/dbunit/DefaultPrepAndExpectedTestCaseTest.java
  • src/test/java/org/dbunit/PrepAndExpectedTestCaseTest.java
  • src/test/java/org/dbunit/PrepAndExpectedTestDataTest.java

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Adds immutable PrepAndExpectedTestData to bundle verification definitions and prep/expected files. Adds bundle-based overloads to PrepAndExpectedTestCase, with tests, documentation, and a changelog entry.

Changes

Prep and expected test data bundle

Layer / File(s) Summary
Immutable test-data contract
src/main/java/org/dbunit/PrepAndExpectedTestData.java, src/test/java/org/dbunit/PrepAndExpectedTestDataTest.java
Adds defensive copying, null normalization, NONE, prepOnly, equality, hashing, and string rendering. Tests cover these behaviors.
Bundle-based test execution
src/main/java/org/dbunit/PrepAndExpectedTestCase.java, src/test/java/org/dbunit/PrepAndExpectedTestCaseTest.java, src/test/java/org/dbunit/DefaultPrepAndExpectedTestCaseTest.java
Adds overloads for configuration, setup, and execution. Each overload delegates to the existing array-based method. Tests verify forwarding and execution behavior.
Documentation and release notes
src/site/asciidoc/testcases/PrepAndExpectedTestCase.adoc, src/site/asciidoc/testcases/annotations.adoc, src/changes/changes.xml
Documents the bundle API, parameterized-test usage, shared constants, factory method, and the 3.6.0-SNAPSHOT change.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to a6ed9

This adds an immutable bundled test-data argument and convenience overloads while preserving the existing array-based execution paths. The documented behavior is covered by tests, with no identified merge-blocking risk.

Sequence Diagram(s)

sequenceDiagram
  participant TestCase
  participant PrepAndExpectedTestCase
  participant ExistingArrayAPI
  TestCase->>PrepAndExpectedTestCase: call bundle-based overload
  PrepAndExpectedTestCase->>PrepAndExpectedTestCase: unpack bundled arrays
  PrepAndExpectedTestCase->>ExistingArrayAPI: delegate arrays and test steps
  ExistingArrayAPI-->>TestCase: return result or update test state
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 42 functions across 5 files. (3 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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 the PrepAndExpectedTestData value type. It is concise and relevant to the pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 42 functions across 5 files. (3 skipped: 3 unsupported.)

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 938-prepandexpected-testdata

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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/main/java/org/dbunit/PrepAndExpectedTestData.java" line_range="44-46" />
<code_context>
+ * <p>
+ * Instances are immutable: the constructor copies each array in, every getter
+ * copies its array out, and a {@code null} array is normalized to an empty one.
+ * The {@link VerifyTableDefinition} instances the array holds are shared rather
+ * than copied, matching how callers already use them - as {@code static final}
+ * constants treated as effectively immutable.
+ *
+ * @author Jeff Jensen
</code_context>
<issue_to_address>
**issue (bug_risk):** `PrepAndExpectedTestData` is not fully immutable: it only copies the `VerifyTableDefinition[]` container, while sharing each mutable `VerifyTableDefinition` instance. Mutating a definition after bundling changes the scenario represented by the value and can also change its `equals`/`hashCode` result after it has been placed in a hash-based collection.

**Triggers:** When a caller reuses a `VerifyTableDefinition` and later changes its verifier or sorting configuration.

**Suggested fix:** Deep-copy or otherwise freeze the contained `VerifyTableDefinition` instances, or narrow the immutability/value-type contract to state that the element objects must not be mutated after construction.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: src/main/java/org/dbunit/PrepAndExpectedTestData.java:46


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/main/java/org/dbunit/PrepAndExpectedTestData.java Outdated
PrepAndExpectedTestCase.configureTest(), preTest(), and runTest() each
take the same (VerifyTableDefinition[], String[] prep, String[] expected)
triple. It describes one test scenario and is meaningless split apart,
yet in a data-driven test it propagates through the @ParameterizedTest
signature, every @MethodSource row, and any row-factory method built to
keep those rows readable.

PrepAndExpectedTestData bundles the triple into one immutable value:

* Defensive-copies each array in and out; normalizes null to empty.
* A NONE constant and a prepOnly(String...) factory cover the common
  partial cases, replacing a separate empty constant per array type.
* equals/hashCode/toString for whole-object assertions in tests.

PrepAndExpectedTestCase gains default configureTest(PrepAndExpectedTestData),
preTest(PrepAndExpectedTestData), and runTest(PrepAndExpectedTestData,
PrepAndExpectedTestCaseSteps) overloads that unpack the bundle and
delegate to the existing array methods. Purely additive: no existing
signature changes, no implementor breaks, and
DefaultPrepAndExpectedTestCase needs no edit.

Complements the annotation-driven configuration of issue 753, which
serves configuration fixed per test method rather than varying per
invocation.

Refs: 938

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RgQW5ydR5upi3SiuW2oEu2
@jeffjensen
jeffjensen force-pushed the 938-prepandexpected-testdata branch from a6ed9ac to b0181b5 Compare September 7, 2026 19:03

@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.

Sourcery assessment

Approved.

@jeffjensen
jeffjensen merged commit 62975e3 into main Sep 7, 2026
29 checks passed
@jeffjensen
jeffjensen deleted the 938-prepandexpected-testdata branch September 7, 2026 20:18
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.

Bundle prep, expected, and verify definitions into a PrepAndExpectedTestData value type

1 participant