diff --git a/src/main/java/org/openrewrite/kotlin/Assertions.java b/src/main/java/org/openrewrite/kotlin/Assertions.java index 0bf48c38a..a17954680 100644 --- a/src/main/java/org/openrewrite/kotlin/Assertions.java +++ b/src/main/java/org/openrewrite/kotlin/Assertions.java @@ -46,7 +46,7 @@ public static SourceSpecs kotlin(@Language("kotlin") @Nullable String before, @L public static SourceSpecs kotlin(@Language("kotlin") @Nullable String before, @Language("kotlin") String after, Consumer> spec) { - SourceSpec kotlin = new SourceSpec<>(K.CompilationUnit.class, null, KotlinParser.builder(), before, null); + SourceSpec kotlin = new SourceSpec<>(K.CompilationUnit.class, null, KotlinParser.builder(), before, s -> after); spec.accept(kotlin); return kotlin; } diff --git a/src/test/java/org/openrewrite/kotlin/AssertionsTest.java b/src/test/java/org/openrewrite/kotlin/AssertionsTest.java new file mode 100644 index 000000000..9624b776b --- /dev/null +++ b/src/test/java/org/openrewrite/kotlin/AssertionsTest.java @@ -0,0 +1,46 @@ +package org.openrewrite.kotlin; + +import org.junit.jupiter.api.Test; +import org.openrewrite.ExecutionContext; +import org.openrewrite.Issue; +import org.openrewrite.java.tree.J; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.kotlin.Assertions.kotlin; +import static org.openrewrite.test.RewriteTest.toRecipe; + +// This class may be removed after recipes with Assertions are added. +public class AssertionsTest implements RewriteTest { + @Override + public void defaults(RecipeSpec spec) { + spec.recipe(toRecipe(() -> new KotlinIsoVisitor<>() { + @Override + public J visitVariable(J.VariableDeclarations.NamedVariable variable, ExecutionContext executionContext) { + if ("a".equals(variable.getSimpleName())) { + return variable.withName(variable.getName().withSimpleName("b")); + } + return variable; + } + })); + } + + @Issue("https://github.com/openrewrite/rewrite-kotlin/issues/30") + @Test + void isChanged() { + rewriteRun( + kotlin( + """ + class A { + val a = 1 + } + """, + """ + class A { + val b = 1 + } + """ + ) + ); + } +}