openrewrite / rewrite-testing-frameworks

OpenRewrite recipes that perform common Java testing migration tasks.
Apache License 2.0
68 stars 59 forks source link

When migrating from JUnit to AssertJ, rely on context to provide better assertions #387

Open rahulsom opened 11 months ago

rahulsom commented 11 months ago

What problem are you trying to solve?

I'm converting JUnit assertions to AssertJ assertions.

Describe the solution you'd like

In the example here - https://docs.openrewrite.org/recipes/java/testing/assertj/junitasserttruetoassertthat

assertTrue(notification() != null && notification() > 0);

is turned into

assertThat(notification() != null && notification() > 0).isTrue();

The more useful conversion would be

assertThat(notification()).isNotNull().isGreaterThan(0)

Have you considered any alternatives or workarounds?

N/A

Additional context

Are you interested in contributing this feature to OpenRewrite?

timtebeek commented 11 months ago

Hi @rahulsom , thanks for reporting this suggestion here! It sounds like this issue could tie in with the work being done on https://github.com/openrewrite/rewrite-testing-frameworks/issues/348, which will make it's way into our AssertJ best practices. In particular I think we can split the && first into two assertion statements, and then collapse those statements using the recipe developed in https://github.com/openrewrite/rewrite-testing-frameworks/issues/373.