Skip to content

Preserve legacy Hamcrest class matcher semantics in AssertJ migrations - #1250

Merged
jkschneider merged 3 commits into
mainfrom
factory/testing1211-e4-class-matcher-safety
Oct 26, 2026
Merged

jkschneider merged 3 commits into
mainfrom
factory/testing1211-e4-class-matcher-safety

Conversation

@jkschneider

@jkschneider jkschneider commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Legacy Hamcrest is(Class) checks an object's type. The AssertJ migrations currently treat it as value equality: assertThat("value", is(String.class)) becomes an assertion comparing the string with String.class. Preserve these legacy class matchers in both HamcrestIsMatcherToAssertJ and HamcrestHasPropertyToAssertJ.

Distinguish the legacy overload from modern Class-valued equality using the instantiated parameter and Matcher value types. Retain ambiguous raw, erased, or incomplete metadata conservatively. Modern Class-valued equality and an explicitly Object-valued equality argument remain eligible for migration. The Hamcrest 1.3 dependency is test runtime only.

Validation:

  • Normally attributed legacy class, array, and property regressions fail on the baseline while valid equality controls pass. Partial declaration/parameter and erased Class metadata controls also reproduce the unsafe rewrite before correction. All 28 focused tests pass without skips.
  • The exact-head native module check reports 2,334 tests, zero failures/errors, and nine existing skips. The native test worker is JDK 21.
  • Both genuine uploaded artifacts use the same 71 dependency JAR hashes and classpath order. Candidate JAR source identity and native class bytes match; only the two anonymous visitors and the new helper change, with 713 other main class files identical. Credential scans are clear.
  • Actual uploaded-JAR transformations cover 21 immutable compiler/runtime cases against real Hamcrest 1.3/3.0 and AssertJ APIs, including four controlled metadata variants after normal attributed parsing. All originals and candidate outputs compile with javac --release 8; all 21 outcomes match and all candidate outputs are idempotent. The baseline has two array compiler failures and 13 strict behavioral divergences; this candidate resolves 12.
  • One pre-existing modern property-equality difference remains: both baseline and candidate call its getter four times instead of once, with identical emitted source. This PR does not change that behavior. No full consumer application build is claimed.
  • Complete paired comparison covers both recipes across 1,679 unique repositories in two disjoint cohorts (839 + 840), including all 1,352 MatcherAssert callers. Every repository has equal source-file counts between baseline and candidate. Changed-file rows decrease from 14,074 to 14,054, retaining 20 whole files; candidate changed-file keys are a subset of baseline. There are no new source errors and six identical pre-existing source error rows. Final-head CGP CI passes (20261026201828-JUSOO).

Addresses item E4 of #1211. The aggregate issue remains open.

Co-authored-by: Moderne Factory factory@moderne.io

jkschneider and others added 3 commits October 26, 2026 14:26
Co-authored-by: Moderne Factory <factory@moderne.io>
Co-authored-by: Moderne Factory <factory@moderne.io>
Co-authored-by: Moderne Factory <factory@moderne.io>
@jkschneider jkschneider added the mod-factory Recipe fixes developed and verified by Moderne Factory label Oct 26, 2026
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Oct 26, 2026
@jkschneider
jkschneider merged commit 39a46a0 into main Oct 26, 2026
1 check passed
@jkschneider
jkschneider deleted the factory/testing1211-e4-class-matcher-safety branch October 26, 2026 21:12
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod-factory Recipe fixes developed and verified by Moderne Factory

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant