Closed timo-a closed 1 month ago
Thanks for the report @timo-a ; great to see you've helped Jackson adopt JUnit Jupiter, and are coming back here to report issues.
I've briefly tried to replicate the issue, but so far no luck:
@Test
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/618")
void lambdaWithWhileLoop() {
//language=java
rewriteRun(
java(
"""
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
class MyTest {
@Test
public void test() {
assertThrows(IllegalStateException.class, () -> { while (System.out != null) {} });
}
}
"""
)
);
}
Did I miss anything?
I did notice there was a check on the body being null previously that might have erroneously been removed in https://github.com/openrewrite/rewrite-testing-frameworks/commit/8bfd44ab6d44a675dab19d578800956e0eb71be3 Would restoring that help you think? Ideally that change is then matched up with a unit test that requires it, such that it's not dropped again.
@shivanisky might have some additional context here as well
So, it seems that the error occurs in two similarly names test classes, and, convinced that the bug is triggered from within the assertion, I didn't notice that the file I was reducing was no longer causing the error...
Please try
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class MyTest {
@Test
void test() {
assertThrows(IllegalStateException.class, () -> System.out.println("foo"));
}
public interface InnerInterface {
String createParser(String input);
}
}
Thanks a lot; that's all I needed indeed. 🥂
What version of OpenRewrite are you using?
I am using
How are you running OpenRewrite?
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-testing-frameworks:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.testing.junit5.AssertThrowsOnLastStatement
I am using the Maven plugin, and my project is a single module project.
What is the smallest, simplest way to reproduce the problem?
original file
This will result in a NullPointer, see below
What is the full stack trace of any errors you encountered?
Are you interested in contributing a fix to OpenRewrite?
No