Skip to content

Commit

Permalink
Fix Assertions#kotlin(before, after)
Browse files Browse the repository at this point in the history
fixes #30
  • Loading branch information
traceyyoshima committed Mar 6, 2023
1 parent b5da895 commit a283ec4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/openrewrite/kotlin/Assertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<SourceSpec<K.CompilationUnit>> spec) {
SourceSpec<K.CompilationUnit> kotlin = new SourceSpec<>(K.CompilationUnit.class, null, KotlinParser.builder(), before, null);
SourceSpec<K.CompilationUnit> kotlin = new SourceSpec<>(K.CompilationUnit.class, null, KotlinParser.builder(), before, s -> after);
spec.accept(kotlin);
return kotlin;
}
Expand Down
46 changes: 46 additions & 0 deletions src/test/java/org/openrewrite/kotlin/AssertionsTest.java
Original file line number Diff line number Diff line change
@@ -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
}
"""
)
);
}
}

0 comments on commit a283ec4

Please sign in to comment.