Skip to content

Preserve parameterized toString assertions - #1094

Open
martinfrancois wants to merge 1 commit into
openrewrite:mainfrom
martinfrancois:agent/repro-simplify-assertj-parameterized-tostring
Open

Preserve parameterized toString assertions#1094
martinfrancois wants to merge 1 commit into
openrewrite:mainfrom
martinfrancois:agent/repro-simplify-assertj-parameterized-tostring

Conversation

@martinfrancois

@martinfrancois martinfrancois commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Suggested review order: 19 of 52 (Score: 6.5)
Review first: openrewrite/rewrite-migrate-java#1206

What's changed?

Leaves parameterized toString assertions unchanged. The existing simplification remains active for zero-argument toString() calls whose semantics match AssertJ's hasToString(String) assertion.

What's your motivation?

Recipe: org.openrewrite.java.testing.assertj.SimplifyChainedAssertJAssertions.

I found this by running org.openrewrite.java.testing.assertj.SimplifyChainedAssertJAssertions from org.openrewrite.recipe:rewrite-testing-frameworks:3.42.0 on LocalLogTailerTest.java in Symphony-Trello at a8013f27. I reproduced the same result with the latest released recipe artifact, org.openrewrite.recipe:rewrite-testing-frameworks:3.44.0. ./mvnw -DskipTests test-compile then fails because AssertJ has no overload accepting the generated arguments.

Before

assertThat(stdout.toString(StandardCharsets.UTF_8)).isEqualTo(expected);

Actual after the recipe

assertThat(stdout).hasToString(StandardCharsets.UTF_8, expected);

Expected after the recipe

(unchanged)

The generated call passes a Charset where AssertJ expects the single expected String. The transformed target fails compilation with incompatible types: Charset cannot be converted to String.

Confirmed real-world execution

Anything in particular you'd like reviewers to focus on?

Please review the zero-argument boundary. A parameterized toString call performs conversion work that hasToString does not represent.

Have you considered any alternatives or workarounds?

Dropping the charset would change behavior because ByteArrayOutputStream.toString(Charset) does not use the same conversion contract as Object.toString().

Any additional context

Pre-existing tests changed: SimplifyChainedAssertJAssertionsTest.java.collectionReplacements (updated).

  • Target commit: martinfrancois/symphony-trello@a8013f27
  • Discovery release: org.openrewrite.recipe:rewrite-testing-frameworks:3.42.0
  • Latest verification release: org.openrewrite.recipe:rewrite-testing-frameworks:3.44.0
  • Focused tests: SimplifyChainedAssertJAssertionsTest

This change was prepared with AI assistance. I reviewed the target execution evidence, implementation, tests, and contribution text.

Checklist

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Aug 15, 2026
@martinfrancois martinfrancois changed the title Preserve parameterized ByteArrayOutputStream.toString assertions Preserve parameterized toString assertions Aug 15, 2026
@martinfrancois
martinfrancois force-pushed the agent/repro-simplify-assertj-parameterized-tostring branch from a78bfec to 683fdb4 Compare August 15, 2026 22:40
@martinfrancois
martinfrancois force-pushed the agent/repro-simplify-assertj-parameterized-tostring branch from 683fdb4 to 9b0ad81 Compare August 16, 2026 02:53
@martinfrancois
martinfrancois marked this pull request as ready for review August 17, 2026 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant