What version of OpenRewrite are you using?
I am using
- OpenRewrite v3,30.0
- Maven/Gradle plugin v6.33.0
- rewrite-module v3.30.0
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>6.33.0</version>
<configuration>
<exportDatatables>true</exportDatatables>
<activeRecipes>
<recipe>org.openrewrite.java.testing.junit5.JUnit5BestPractices</recipe>
<recipe>org.openrewrite.java.migrate.UpgradeToJava17</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-testing-frameworks</artifactId>
<version>3.30.0</version>
</dependency>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-migrate-java</artifactId>
<version>3.30.1</version>
</dependency>
</dependencies>
</plugin>
What is the smallest, simplest way to reproduce the problem?
class A {
private A() {}
// Other methods
}
import java.lang.reflect.Constructor;
import org.junit.Assert;
import org.junit.Test;
public class ATest {
@Test(expected = AssertionError.class)
public void testNewInstance() throws Exception {
Constructor<Constants> constructor = Constants.class.getDeclaredConstructor();
Assert.assertFalse(constructor.isAccessible());
constructor.setAccessible(true);
constructor.newInstance((Object[]) null);
}
// Other test methods
}
What did you expect to see?
Test case to be upgraded to Junit 5
What did you see instead?
java.lang.IllegalArgumentException
What is the full stack trace of any errors you encountered?
Error while visiting ATest.java: java.lang.IllegalArgumentException: Expected a template that would generate exactly one statement to replace one statement, but generated 0. Template:
[ERROR] Object x = __P__.<java.lang.Object[]>/*__p2__*/p();
[ERROR] Substitutions:
[ERROR] Substitutions(code=#{} #{} = #{any()};, genericTypes=[], parameters=[Object, x, (Object[]) null], propertyPlaceholderHelper=org.openrewrite.internal.PropertyPlaceholderHelper@6836b2cf, typeVariables=[])
[ERROR] Statement:
[ERROR] constructor.newInstance((Object[]) null)
[ERROR] org.openrewrite.java.internal.template.JavaTemplateJavaExtension$1.maybeReplaceStatement(JavaTemplateJavaExtension.java:481)
[ERROR] org.openrewrite.java.internal.template.JavaTemplateJavaExtension$1.visitMethodInvocation(JavaTemplateJavaExtension.java:438)
[ERROR] org.openrewrite.java.internal.template.JavaTemplateJavaExtension$1.visitMethodInvocation(JavaTemplateJavaExtension.java:60)
[ERROR] org.openrewrite.java.tree.J$MethodInvocation.acceptJava(J.java:4281)
[ERROR] org.openrewrite.java.tree.J.accept(J.java:55)
[ERROR] org.openrewrite.TreeVisitor.visit(TreeVisitor.java:242)
[ERROR] org.openrewrite.TreeVisitor.visit(TreeVisitor.java:154)
[ERROR] org.openrewrite.java.JavaTemplate.doApply(JavaTemplate.java:129)
[ERROR] org.openrewrite.java.JavaTemplate.apply(JavaTemplate.java:109)
[ERROR] org.openrewrite.java.testing.junit5.AssertThrowsOnLastStatement$1.lambda$extractExpressionArguments$3(AssertThrowsOnLastStatement.java:178)
[ERROR] org.openrewrite.internal.ListUtils.map(ListUtils.java:245)
[ERROR] org.openrewrite.internal.ListUtils.map(ListUtils.java:269)
[ERROR] org.openrewrite.java.testing.junit5.AssertThrowsOnLastStatement$1.extractExpressionArguments(AssertThrowsOnLastStatement.java:147)
[ERROR] org.openrewrite.java.testing.junit5.AssertThrowsOnLastStatement$1.lambda$visitMethodDeclaration$1(AssertThrowsOnLastStatement.java:119)
[ERROR] org.openrewrite.internal.ListUtils.flatMap(ListUtils.java:292)
[ERROR] org.openrewrite.java.testing.junit5.AssertThrowsOnLastStatement$1.lambda$visitMethodDeclaration$2(AssertThrowsOnLastStatement.java:112)
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?
Are you interested in contributing a fix to OpenRewrite?