-
Notifications
You must be signed in to change notification settings - Fork 53
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
JUnitFailToAssertJFail doesn't remove existing Junit import #467
Comments
Hi @timo-abele ; I've tried to replicate your case but had to make a few small changes to get the example to compile, after which the test already passed without code changes: @Test
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/467")
void removeImport() {
//language=java
rewriteRun(
java(
"""
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
class A {
@Test
void foo() {
String id = "bar";
fail(id + "not found");
fail("foo");
}
}
""",
"""
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.fail;
class A {
@Test
void foo() {
String id = "bar";
fail("", id + "not found");
fail("foo");
}
}
"""
)
);
} Note how I define Line 29 in 53cfd4c The left over import is already cleaned up on this line, provided there's no left over calls to the old method Line 115 in 4582163
Could you let me know how we can better replicate what might factor into your case? You might have stripped away some crucial information. Is |
I managed to condense the original to something reproducible: import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
import lombok.Getter;
class MyTest {
class DebugEnum {
@Getter
private String key = "9";
}
void myMethod() {
String s = new DebugEnum().getKey();
assertThat(1 + 1).isEqualTo(2);
fail("foo");
}
}
|
Thanks for the reduced sample! I've had another look at this after running into the same yesterday. You'll recall that the recipe clears out the imports through RemoveUnusedImports, which itself has a precondition that there should not be any missing types: This is to prevent the recipe from clearing out lots of necessary imports when for instance Lombok, or mocking is used, as both are a frequent source of missing types as we've also seen here on the generated I hope to remedy that partly with this change pushed yesterday: 0f7fc95 Would you be ok with me closing this issue as there's no action we can take in this particular recipe module that would fix this for all possible cases? |
I'm OK with the issue being closed, I've reported the bug, and leave it to your discretion whether this is appropriately addressed. |
We don't really have a dedicated page on what might cause missing types, or how to explore and resolved such issues unfortunately. Perhaps something for our frequently asked questions. Until then you can explore missing types with this recipe which adds search markers: https://docs.openrewrite.org/recipes/java/search/findmissingtypes I'll close this issue for now as we can't fix it in this repository. Thanks again for reporting your findings! |
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 single module project.
What is the smallest, simplest way to reproduce the problem?
What did you expect to see?
What did you see instead?
What is the full stack trace of any errors you encountered?
In the first case (
fail(id + "not found")
) there are no errors, just an unused import that could be avoided by adding a maybeRemoveImport right after this linerewrite-testing-frameworks/src/main/java/org/openrewrite/java/testing/assertj/JUnitFailToAssertJFail.java
Line 148 in a426e40
In the second case, there is actually an error, namely
Are you interested in contributing a fix to OpenRewrite?
no
The text was updated successfully, but these errors were encountered: