From 1e9539e3989dad169115d1152732ac4c3c7e8ffd Mon Sep 17 00:00:00 2001 From: Alexei Bratuhin Date: Sat, 10 Jun 2023 18:57:47 +0200 Subject: [PATCH] #3156 = add/refine tests related to non-public, inner and nested classes --- .../java/LombokUtilityClassTest.java | 118 +++++++++++++++++- 1 file changed, 117 insertions(+), 1 deletion(-) 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