Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.openrewrite.java.testing.junit5.JUnit5BestPractices should fix a null as actual and flip the parameters #492

Closed
timo-abele opened this issue Mar 7, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@timo-abele
Copy link
Contributor

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a single module project.

            <plugin>
                <groupId>org.openrewrite.maven</groupId>
                <artifactId>rewrite-maven-plugin</artifactId>
                <version>5.23.1</version>
                <configuration>
                    <activeRecipes>
                        <recipe>org.openrewrite.java.testing.assertj.Assertj</recipe>
                    </activeRecipes>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.openrewrite.recipe</groupId>
                        <artifactId>rewrite-testing-frameworks</artifactId>
                        <version>2.4.1</version>
                    </dependency>
                </dependencies>
            </plugin>

What is the smallest, simplest way to reproduce the problem?

class A {
    class B {};

    @Test
    public void FlippedParams(){
        B myVariable = new B();

        assertNotEquals(myVariable, null);
    }
}

Or even ``

What did you expect to see?

class A {
    class B {};

    @Test
    public void FlippedParams(){
        B myVariable = new B();

        assertThat(myVariable).isNotEqualTo(null);
    }
}

Or maybe through a dedicated pre-clean recipe that flips them:
assertNotEquals(null, myVariable);
This would cover more cases

What did you see instead?

class A {
    class B {};

    @Test
    public void FlippedParams(){
        B myVariable = new B();

        assertThat(null).isNotEqualTo(myVariable);
    }
}

What is the full stack trace of any errors you encountered?

Ambiguous method call. Both
assertThat
(Predicate<Object>)
in Assertions and
assertThat
(IntPredicate)
in Assertions match

Comments

This is intentionally filed as a bug report and not a feature request because it breaks the build.
So this has to be fixed. I see no reason for any user to push an Assertion on null to main.

Are you interested in contributing a fix to OpenRewrite?

@timo-abele timo-abele added the bug Something isn't working label Mar 7, 2024
@timtebeek
Copy link
Contributor

Thanks for the suggestion @timo-abele ; I think that's suitably covered in 964e677 now by reusing a recipe we already had to flip misplaced assertions first before migrating to AssertJ. Hope you agree!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

2 participants