openrewrite / rewrite-testing-frameworks

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

isGreaterThanOrEqualTo for java.util.Date by HamcrestMatcherToAssertJ should result isAfterOrEqualTo #526

Open ssheikin opened 2 weeks ago

ssheikin commented 2 weeks ago

What version of OpenRewrite are you using?

I am using

How are you running OpenRewrite?

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

            <plugin>
                <groupId>org.openrewrite.maven</groupId>
                <artifactId>rewrite-maven-plugin</artifactId>
                <version>5.32.0</version>
                <configuration>
                    <activeRecipes>
                        <recipe>org.openrewrite.java.testing.hamcrest.MigrateHamcrestToAssertJ</recipe>
                    </activeRecipes>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.openrewrite.recipe</groupId>
                        <artifactId>rewrite-testing-frameworks</artifactId>
                        <version>2.10.1</version>
                    </dependency>
                </dependencies>
            </plugin>

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

java.sql.Timestamp actualDate;
assertThat(actualDate, greaterThanOrEqualTo(expectedDate));

What did you expect to see?

assertThat(actualDate).isAfterOrEqualTo(expectedDate);

What did you see instead?

assertThat(actualDate).isGreaterThanOrEqualTo(expectedDate);

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

[ERROR] cannot find symbol
[ERROR]   symbol:   method isGreaterThanOrEqualTo(java.sql.Timestamp)
[ERROR]   location: class org.assertj.core.api.AbstractDateAssert<capture#1 of ?>

Are you interested in contributing a fix to OpenRewrite?

timtebeek commented 2 weeks ago

Thanks for the report! Looks like we should be able to fix this quite easily by adding an additional step with an argumentType: java.util.Date that converts to isAfterOrEqualTo instead, and runs before the generalized case https://github.com/openrewrite/rewrite-testing-frameworks/blob/65711d5ea8c296929e6f409c1650f64253558365/src/main/resources/META-INF/rewrite/hamcrest.yml#L70-L72

Just a couple lines of Yaml for a contribution if you're up for it; test optional as we're just reusing existing components. Is that something you'd like to contribute?

ssheikin commented 1 week ago

Sure! I'll try to take a look on my free evening.

timtebeek commented 1 week ago

Awesome, thanks a lot!