Skip to content

Keep the message overloads of TestNG assertThrows/expectThrows in TestNgAssertThrowsToAssertThat - #1240

Merged
timtebeek merged 1 commit into
mainfrom
tim/h1-issue-1211-fix
Oct 25, 2026
Merged

timtebeek merged 1 commit into
mainfrom
tim/h1-issue-1211-fix

Conversation

@timtebeek

Copy link
Copy Markdown
Member

TestNgAssertThrowsToAssertThat passed the first two arguments to its template whatever the overload, so assertThrows("msg", IllegalStateException.class, () -> ..) became assertThatExceptionOfType("msg").isThrownBy(IllegalStateException.class) and the lambda was dropped. The same happened to expectThrows(String, Class, ThrowingRunnable).

For the three-argument overloads the message now becomes the description, as in assertThatExceptionOfType(IllegalStateException.class).as("msg").isThrownBy(() -> ..). The template now takes the type as Class<? extends Throwable> instead of a raw Class. A raw ThrowableTypeAssert erases the SELF return type of as(..), which left isThrownBy without type attribution.

Verified with ./gradlew test --offline --tests 'org.openrewrite.java.testing.testng.*' (44 tests, all passing), including new tests for both message overloads.

Fixes item H1 of #1211.

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Oct 25, 2026
@timtebeek
timtebeek enabled auto-merge (squash) October 25, 2026 22:11
@timtebeek
timtebeek merged commit 73c23f3 into main Oct 25, 2026
1 check passed
@timtebeek
timtebeek deleted the tim/h1-issue-1211-fix branch October 25, 2026 22:16
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant