Skip to content

[FLINK-39876][tests] Migrate flink-streaming-java assertions to AssertJ - #28835

Open
spuru9 wants to merge 1 commit into
apache:masterfrom
spuru9:feature/junit5-streaming-java-assertj
Open

[FLINK-39876][tests] Migrate flink-streaming-java assertions to AssertJ#28835
spuru9 wants to merge 1 commit into
apache:masterfrom
spuru9:feature/junit5-streaming-java-assertj

Conversation

@spuru9

@spuru9 spuru9 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What is the purpose of the change

flink-streaming-java is already on JUnit 5 (FLINK-25544), but ten test classes still used
Hamcrest — either bridged into AssertJ via HamcrestCondition.matching(...) or through the
MockitoHamcrest argument matchers. This removes the last of them, per
§7 Testing:
"Don't use Hamcrest, JUnit assertions and assert directive". Test-only; no production code
is touched.

Brief change log

  • TypeSafeMatcher/FeatureMatcher wrapped in HamcrestCondition.matching(...) become native
    AssertJ Conditions.
  • MockitoHamcrest.argThat(...) becomes ArgumentMatchers.argThat(...), with the Hamcrest
    matchers it wrapped expressed as predicates; CheckpointExceptionMatcher now implements
    Mockito's ArgumentMatcher instead of Hamcrest's BaseMatcher.
  • Drops the unused EqualsResourceSpecMatcher from StreamGraphGeneratorTest.

Verifying this change

This change is a trivial rework / code cleanup without any test coverage.

Covered by the tests it touches (99 tests, passing). To confirm no assertion became vacuously
true, each new predicate was inverted in turn and the tests using it failed as expected.
Checkstyle and Spotless are clean.

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): no
  • The public API, i.e., is any changed class annotated with @Public(Evolving): no
  • The serializers: no
  • The runtime per-record code paths (performance sensitive): no
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
  • The S3 file system connector: no

Documentation

  • Does this pull request introduce a new feature? no
  • If yes, how is the feature documented? not applicable

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Code (Claude Opus 5)

@spuru9
spuru9 marked this pull request as draft July 28, 2026 16:36
@flinkbot

flinkbot commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

@spuru9

spuru9 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

As per the https://flink.apache.org/how-to-contribute/code-style-and-quality-common/#7-testing
We used a combination of JUnit4 and use Hamcrest because of its better expressiveness, but we have move towards JUnit5 and AssertJ. So, making this migration.

@spuru9
spuru9 force-pushed the feature/junit5-streaming-java-assertj branch from 08a6354 to d30fea1 Compare July 28, 2026 17:38
@spuru9
spuru9 marked this pull request as ready for review July 28, 2026 17:42
The contributor guide asks for JUnit 5 and AssertJ and states "Don't use
Hamcrest, JUnit assertions and `assert` directive". flink-streaming-java was
already on JUnit 5 (FLINK-25544), but ten test classes still reached for
Hamcrest. This removes the last of them.

* TypeSafeMatcher and FeatureMatcher instances that were bridged into AssertJ
  via HamcrestCondition.matching() become native AssertJ Conditions.
* MockitoHamcrest.argThat() becomes Mockito's own ArgumentMatchers.argThat().
  The Hamcrest matchers it wrapped (containsInAnyOrder, contains, hasEntry,
  allOf) are expressed as predicates, which also removes the casts their
  call sites needed. CheckpointExceptionMatcher now implements Mockito's
  ArgumentMatcher rather than Hamcrest's BaseMatcher.
* Drops the unused EqualsResourceSpecMatcher from StreamGraphGeneratorTest.

The replacements keep the semantics of the matchers they replace, which AssertJ
and Mockito do not provide for free: the predicates reject null explicitly,
because TypeSafeMatcher never invoked matchesSafely() on a null actual;
containsInAnyOrder counts duplicates; and the map matcher checks for the
expected entries rather than map equality, as hasEntry did.

No production code is touched. Each migrated predicate was inverted in turn to
confirm the tests using it fail.

Generated-by: Claude Code (Claude Opus 5)
@spuru9
spuru9 force-pushed the feature/junit5-streaming-java-assertj branch from d30fea1 to 0efae72 Compare July 28, 2026 18:31
@spuru9

spuru9 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

cc: @snuyanzin @raminqaf

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