Skip to content

Commit

Permalink
Document each of the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Feb 6, 2024
1 parent c6a7dfa commit 8a0f3d2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/test/java/com/yourorg/NoGuavaListsNewArrayListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@

import static org.openrewrite.java.Assertions.java;

/**
* This is a test for the NoGuavaListsNewArrayList recipe, as an example of how to write a test for an imperative recipe.
*/
class NoGuavaListsNewArrayListTest implements RewriteTest {

// Note, you can define defaults for the RecipeSpec and these defaults will be used for all tests.
// In this case, the recipe and the parser are common. See below, on how the defaults can be overridden
// per test.
@Override
public void defaults(RecipeSpec spec) {
// Note how we directly instantiate the recipe class here
spec.recipe(new NoGuavaListsNewArrayList())
.parser(JavaParser.fromJavaVersion()
.logCompilationWarningsAndErrors(true)
Expand Down
12 changes: 11 additions & 1 deletion src/test/java/com/yourorg/SimplifyTernaryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,26 @@

import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import static org.openrewrite.java.Assertions.java;

/**
* This is a test for the SimplifyTernary recipe, as an example of how to write a test for a Refaster style recipe.
*/
class SimplifyTernaryTest implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
// Note that we instantiate a generated class here, with `Recipes` appended to the Refaster class name
spec.recipe(new SimplifyTernaryRecipes());
}

@DocumentExample
@Test
void simplified() {
rewriteRun(
spec -> spec.recipe(new SimplifyTernaryRecipes()),
//language=java
java(
"""
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/yourorg/UseOpenRewriteNullableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ void replacesNullableAnnotation() {
java(
"""
import org.jetbrains.annotations.Nullable;
class A {
@Nullable
String s;
}
""",
"""
import org.openrewrite.internal.lang.Nullable;
class A {
@Nullable
String s;
Expand Down

0 comments on commit 8a0f3d2

Please sign in to comment.