From 6ed0601cd4d8dd3def67e255d866d0cccf60fab9 Mon Sep 17 00:00:00 2001 From: Greg Dennis Date: Mon, 8 Dec 2025 11:44:10 -0500 Subject: [PATCH 1/4] Add unit test showing bug --- .../KotlinTestMethodShouldBeUnitTest.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/test/java/org/openrewrite/java/testing/cleanup/KotlinTestMethodShouldBeUnitTest.java diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/KotlinTestMethodShouldBeUnitTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/KotlinTestMethodShouldBeUnitTest.java new file mode 100644 index 000000000..644afd707 --- /dev/null +++ b/src/test/java/org/openrewrite/java/testing/cleanup/KotlinTestMethodShouldBeUnitTest.java @@ -0,0 +1,79 @@ +/* + * Copyright 2025 the original author or authors. + *

+ * Licensed under the Moderne Source Available License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://docs.moderne.io/licensing/moderne-source-available-license + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.java.testing.cleanup; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.openrewrite.kotlin.Assertions.kotlin; + +import org.junit.jupiter.api.Test; +import org.openrewrite.ExecutionContext; +import org.openrewrite.InMemoryExecutionContext; +import org.openrewrite.Parser; +import org.openrewrite.SourceFile; +import org.openrewrite.java.tree.J; +import org.openrewrite.kotlin.KotlinIsoVisitor; +import org.openrewrite.kotlin.KotlinParser; +import org.openrewrite.test.RewriteTest; +import org.openrewrite.test.SourceSpec; + +import java.nio.file.Path; +import java.util.Collections; +import java.util.Iterator; + +// +public class KotlinTestMethodShouldBeUnitTest implements RewriteTest { + + @Test + void showNullMethodInvocationType() { + //language=kotlin + SourceSpec source = getOnly( + kotlin( + """ + class ExampleTest { + fun myTest() = run { + return 1 + } + } + """ + )); + Parser parser = KotlinParser.builder().build(); + Path sourcePath = parser.sourcePathFromSourceText(source.getDir(), source.getBefore()); + ExecutionContext ctx = new InMemoryExecutionContext(); + Parser.Input input = Parser.Input.fromString( + sourcePath, source.getBefore(), parser.getCharset(ctx)); + SourceFile sourceFile = getOnly( + parser.parseInputs(Collections.singleton(input), null, ctx).toList()); + new FindMissingTypesVisitor().visit(sourceFile, ctx); + } + + private static class FindMissingTypesVisitor extends KotlinIsoVisitor { + + @Override + public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, + ExecutionContext ctx) { + assertNotNull(method.getMethodType()); + return method; + } + } + + private static T getOnly(Iterable iterable) { + Iterator iter = iterable.iterator(); + T only = iter.next(); + assertFalse(iter.hasNext()); + return only; + } +} From f7b28441522532ce8b70d3fe7608da884f51cb27 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Wed, 10 Dec 2025 09:25:15 +0100 Subject: [PATCH 2/4] Apply formatter --- .../cleanup/KotlinTestMethodShouldBeUnitTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/KotlinTestMethodShouldBeUnitTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/KotlinTestMethodShouldBeUnitTest.java index 644afd707..76249ba01 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/KotlinTestMethodShouldBeUnitTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/KotlinTestMethodShouldBeUnitTest.java @@ -15,10 +15,6 @@ */ package org.openrewrite.java.testing.cleanup; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.openrewrite.kotlin.Assertions.kotlin; - import org.junit.jupiter.api.Test; import org.openrewrite.ExecutionContext; import org.openrewrite.InMemoryExecutionContext; @@ -34,6 +30,10 @@ import java.util.Collections; import java.util.Iterator; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.openrewrite.kotlin.Assertions.kotlin; + // public class KotlinTestMethodShouldBeUnitTest implements RewriteTest { @@ -64,7 +64,7 @@ private static class FindMissingTypesVisitor extends KotlinIsoVisitor Date: Wed, 10 Dec 2025 13:39:34 +0100 Subject: [PATCH 3/4] Use static import --- .../java/testing/cleanup/KotlinTestMethodShouldBeUnitTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/KotlinTestMethodShouldBeUnitTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/KotlinTestMethodShouldBeUnitTest.java index 76249ba01..5cc770e3c 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/KotlinTestMethodShouldBeUnitTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/KotlinTestMethodShouldBeUnitTest.java @@ -30,6 +30,7 @@ import java.util.Collections; import java.util.Iterator; +import static java.util.Collections.singleton; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.openrewrite.kotlin.Assertions.kotlin; @@ -56,7 +57,7 @@ fun myTest() = run { Parser.Input input = Parser.Input.fromString( sourcePath, source.getBefore(), parser.getCharset(ctx)); SourceFile sourceFile = getOnly( - parser.parseInputs(Collections.singleton(input), null, ctx).toList()); + parser.parseInputs(singleton(input), null, ctx).toList()); new FindMissingTypesVisitor().visit(sourceFile, ctx); } From 29144a061f511c2f8c23374e382dcd3c02e9de44 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Mon, 26 Jan 2026 01:19:01 +0100 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../java/testing/cleanup/KotlinTestMethodShouldBeUnitTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/KotlinTestMethodShouldBeUnitTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/KotlinTestMethodShouldBeUnitTest.java index 5cc770e3c..f38dd6936 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/KotlinTestMethodShouldBeUnitTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/KotlinTestMethodShouldBeUnitTest.java @@ -27,7 +27,6 @@ import org.openrewrite.test.SourceSpec; import java.nio.file.Path; -import java.util.Collections; import java.util.Iterator; import static java.util.Collections.singleton; @@ -36,7 +35,7 @@ import static org.openrewrite.kotlin.Assertions.kotlin; // -public class KotlinTestMethodShouldBeUnitTest implements RewriteTest { +class KotlinTestMethodShouldBeUnitTest implements RewriteTest { @Test void showNullMethodInvocationType() {