generated from moderneinc/rewrite-recipe-starter
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Assertions#kotlin(before, after)
fixes #30
- Loading branch information
1 parent
b5da895
commit a283ec4
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
""" | ||
) | ||
); | ||
} | ||
} |