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

Assertj removes asLocale #496

Open
timo-abele opened this issue Mar 13, 2024 · 1 comment
Open

Assertj removes asLocale #496

timo-abele opened this issue Mar 13, 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 multi module project.

    <profile>
        <id>openrewrite</id>
        <build>
            <plugins>
                <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>
                        <failOnDryRunResults>true</failOnDryRunResults>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.openrewrite.recipe</groupId>
                            <artifactId>rewrite-testing-frameworks</artifactId>
                            <version>2.4.1</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    </profile>

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

No guarantee on completeness of imports 😄

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

import java.util.HashSet;
import java.util.Locale;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertTrue;

class A {
    class MyLang { MyLang(String l){} Locale asLocale(){return null;}}

    @Test
    void regressionAsLocaleShouldStay() {
        MyLang underTest = new MyLang("he");

        Set<Locale> localeSet = new HashSet<>();

        assertTrue(localeSet.contains(underTest.asLocale()));
    }
}

What did you expect to see?

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

import java.util.HashSet;
import java.util.Locale;
import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;

class A {
    class MyLang { MyLang(String l){} Locale asLocale(){return null;}}

    @Test
    void regressionAsLocaleShouldStay() {
        MyLang underTest = new MyLang("he");

        Set<Locale> localeSet = new HashSet<>();

        assertThat(localeSet).contains(underTest.asLocale());
    }
}

What did you see instead?

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

import java.util.HashSet;
import java.util.Locale;
import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;

class A {
    class MyLang { MyLang(String l){} Locale asLocale(){return null;}}

    @Test
    void regressionAsLocaleShouldStay() {
        MyLang underTest = new MyLang("he");

        Set<Locale> localeSet = new HashSet<>();

        assertThat(localeSet).contains(underTest);
    }
}

Comment

In a nutshell: the asLocale call on my custom class is erroneously dropped.
I suppose the asLocale can be skipped for some jdk class but that the recipe does not check for this type

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

That's quite unexpected, thanks for the clear report! Definitely something to fix.

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
Status: Backlog
Development

No branches or pull requests

2 participants