-
Notifications
You must be signed in to change notification settings - Fork 103
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
What version of OpenRewrite are you using?
I am using latest version
How are you running OpenRewrite?
Running unit test in rewrite-testing-frameworks
What is the smallest, simplest way to reproduce the problem?
@Override
public void defaults(RecipeSpec spec) {
spec
.parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(),
"junit-jupiter-api-5", "junit-jupiter-params-5"))
.parser(KotlinParser.builder().classpathFromResources(new InMemoryExecutionContext(),
"junit-jupiter-api-5", "junit-jupiter-params-5"))
.recipe(new TestMethodsShouldBeVoid());
}
@Test
void testFactoryMustReturnAValueInKotlin() {
rewriteRun(
//language=kotlin
kotlin(
"""
import org.junit.jupiter.api.DynamicTest
import org.junit.jupiter.api.TestFactory
class Doer {
@TestFactory
fun createSomeTests() : List<DynamicTest> {return listOf<DynamicTest>()}
}
"""
)
);
}
@Test
void testFactoryMustReturnAValueInJava() {
rewriteRun(
//language=java
java(
"""
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import java.util.List;
import java.util.ArrayList;
class Doer {
@TestFactory
List<DynamicTest> createSomeTests() {
return new ArrayList<DynamicTest>();
}
}
"""
)
);
}
What did you expect to see?
I would expect to see no change because functions annotated with TestFactory must return a value.
What did you see instead?
In case of Kotlin test, an exception was thrown (see below) and in case of Java test:
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import java.util.List;
import java.util.ArrayList;
class Doer {
@TestFactory
void createSomeTests() {
new ArrayList<DynamicTest>();
}
}
What is the full stack trace of any errors you encountered?
Caused by: java.lang.ClassCastException: class org.openrewrite.java.tree.J$MethodInvocation cannot be cast to class org.openrewrite.java.tree.J$Return (org.openrewrite.java.tree.J$MethodInvocation and org.openrewrite.java.tree.J$Return are in unnamed module of loader 'app')
at org.openrewrite.kotlin.KotlinVisitor.visitReturn(KotlinVisitor.java:234)
at org.openrewrite.kotlin.tree.K$Return.acceptKotlin(K.java:1589)
at org.openrewrite.kotlin.tree.K.accept(K.java:57)
at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:242)
... 71 more
Are you interested in contributing a fix to OpenRewrite?
Yes, I will send a PR later.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Type
Projects
Status
Done