openrewrite / rewrite-testing-frameworks

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

SImplify negated chained assertions with AssertJ #571

Closed timtebeek closed 2 months ago

timtebeek commented 3 months ago

What problem are you trying to solve?

Right now we already simplify quite a few AssertJ assertions that look at isTrue. https://github.com/openrewrite/rewrite-testing-frameworks/blob/8a037e86a611ec4de6bb34d8816184d4df76f0ed/src/main/resources/META-INF/rewrite/assertj.yml#L86-L100

Some of these also have negated variants that we could quite easily cover as well:

  - org.openrewrite.java.testing.assertj.SimplifyChainedAssertJAssertion:
      chainedAssertion: matches
      assertToReplace: isFalse
      dedicatedAssertion: doesNotMatch
      requiredType: java.lang.String

We should add recipes for negated variants as well, starting with the one above and any similar ones we find.

Tahanima commented 2 months ago

Hi @timtebeek, I would like to add the following recipes:

- org.openrewrite.java.testing.assertj.SimplifyChainedAssertJAssertion:
    chainedAssertion: startsWith
    assertToReplace: isFalse
    dedicatedAssertion: doesNotStartWith
    requiredType: java.lang.String
- org.openrewrite.java.testing.assertj.SimplifyChainedAssertJAssertion:
    chainedAssertion: endsWith
    assertToReplace: isFalse
    dedicatedAssertion: doesNotEndWith
    requiredType: java.lang.String
- org.openrewrite.java.testing.assertj.SimplifyChainedAssertJAssertion:
    chainedAssertion: matches
    assertToReplace: isFalse
    dedicatedAssertion: doesNotMatch
    requiredType: java.lang.String

Should I send a PR?

timtebeek commented 2 months ago

Hi! Yes please! Those are easiest for me to see through

timtebeek commented 2 months ago

With the additions in https://github.com/openrewrite/rewrite-testing-frameworks/pull/594 I think we can close this issue already; we could still identify and add more if needed of course, but there's no need to keep the issue open without a clear example to cover next. Thanks again @Tahanima !