diff --git a/rewrite-java/src/test/java/org/openrewrite/java/LombokUtilityClassTest.java b/rewrite-java/src/test/java/org/openrewrite/java/LombokUtilityClassTest.java index 3a4db21fb70..023eba08bf2 100644 --- a/rewrite-java/src/test/java/org/openrewrite/java/LombokUtilityClassTest.java +++ b/rewrite-java/src/test/java/org/openrewrite/java/LombokUtilityClassTest.java @@ -8,7 +8,7 @@ class LombokUtilityClassTest implements RewriteTest { @Test - void happyPath1() { + void happyPathSimple() { rewriteRun( recipeSpec -> recipeSpec .recipe(new LombokUtilityClass() @@ -141,4 +141,120 @@ public int add(final int x, final int y) { ) ); } + + @Test + void happyPathInner() { + rewriteRun( + recipeSpec -> recipeSpec + .recipe(new LombokUtilityClass()), + java( + """ + public class A { + public int add(final int x, final int y) { + return x + y; + } + private class B { + private static int substract(final int x, final int y) { + return x - y; + } + } + } + """, + """ + import lombok.experimental.UtilityClass; + + public class A { + public int add(final int x, final int y) { + return x + y; + } + + @UtilityClass + private class B { + private int substract(final int x, final int y) { + return x - y; + } + } + } + """ + ) + ); + } + + /** + * Nested ~ inner static + */ + @Test + void happyPathNested() { + rewriteRun( + recipeSpec -> recipeSpec + .recipe(new LombokUtilityClass()), + java( + """ + public class A { + public int add(final int x, final int y) { + return x + y; + } + private static class B { + private static int substract(final int x, final int y) { + return x - y; + } + } + } + """, + """ + import lombok.experimental.UtilityClass; + + public class A { + public int add(final int x, final int y) { + return x + y; + } + + @UtilityClass + private static class B { + private int substract(final int x, final int y) { + return x - y; + } + } + } + """ + ) + ); + } + + @Test + void happyPathNonPublic() { + rewriteRun( + recipeSpec -> recipeSpec + .recipe(new LombokUtilityClass()), + java( + """ + public class A { + public int add(final int x, final int y) { + return x + y; + } + } + class B { + public static int substract(final int x, final int y) { + return x - y; + } + } + """, + """ + import lombok.experimental.UtilityClass; + + public class A { + public int add(final int x, final int y) { + return x + y; + } + } + @UtilityClass + class B { + public int substract(final int x, final int y) { + return x - y; + } + } + """ + ) + ); + } } \ No newline at end of file