From f1f780a2a33e71ba9fdf3dba7115f1453640e1ea Mon Sep 17 00:00:00 2001 From: Marvin Froeder Date: Mon, 8 Jul 2024 13:27:40 -0300 Subject: [PATCH 1/6] Added ChainedAssertions for Iterator hasNext Signed-off-by: Marvin Froeder --- .../resources/META-INF/rewrite/assertj.yml | 11 +++++ .../MigrateChainedAssertToAssertJTest.java | 41 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/main/resources/META-INF/rewrite/assertj.yml b/src/main/resources/META-INF/rewrite/assertj.yml index 2695a5dd0..f7ed519c6 100644 --- a/src/main/resources/META-INF/rewrite/assertj.yml +++ b/src/main/resources/META-INF/rewrite/assertj.yml @@ -25,6 +25,7 @@ recipeList: - org.openrewrite.java.testing.hamcrest.MigrateHamcrestToAssertJ - org.openrewrite.java.testing.assertj.JUnitToAssertj - org.openrewrite.java.testing.assertj.StaticImports + - org.openrewrite.java.testing.assertj.IsEqualToBoolean - org.openrewrite.java.testing.assertj.SimplifyChainedAssertJAssertions - org.openrewrite.java.testing.assertj.IsEqualToEmptyString @@ -337,6 +338,16 @@ recipeList: assertToReplace: isSameAs dedicatedAssertion: containsSame requiredType: java.util.Optional + - org.openrewrite.java.testing.assertj.SimplifyChainedAssertJAssertion: + chainedAssertion: hasNext + assertToReplace: isTrue + dedicatedAssertion: hasNext + requiredType: java.util.Iterator + - org.openrewrite.java.testing.assertj.SimplifyChainedAssertJAssertion: + chainedAssertion: hasNext + assertToReplace: isFalse + dedicatedAssertion: isExhausted + requiredType: java.util.Iterator --- type: specs.openrewrite.org/v1beta/recipe diff --git a/src/test/java/org/openrewrite/java/testing/assertj/MigrateChainedAssertToAssertJTest.java b/src/test/java/org/openrewrite/java/testing/assertj/MigrateChainedAssertToAssertJTest.java index 0f54f4f47..f97aec77c 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/MigrateChainedAssertToAssertJTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/MigrateChainedAssertToAssertJTest.java @@ -414,4 +414,45 @@ void test() { rewriteRun(java(before, after)); } } + + + @Nested + class Iteratorz { + private static Stream collectionReplacements() { + return Stream.of( + Arguments.arguments("hasNext", "isTrue", "hasNext"), + Arguments.arguments("hasNext", "isFalse", "isExhausted") + ); + } + + @ParameterizedTest + @MethodSource("collectionReplacements") + void collectionReplacements(String chainedAssertion, String assertToReplace, String dedicatedAssertion) { + //language=java + String template = """ + import java.util.Iterator; + + import static org.assertj.core.api.Assertions.assertThat; + + class A { + void test(Iterator iterator, Iterator otherIterator) { + String something = ""; + %s + } + } + """; + String assertBefore = "assertThat(iterator.%s()).%s();"; + String assertAfter = "assertThat(iterator).%s();"; + + String formattedAssertBefore = assertBefore.formatted(chainedAssertion, assertToReplace); + + String before = String.format(template, formattedAssertBefore); + String after = String.format(template, assertAfter.formatted(dedicatedAssertion)); + + rewriteRun( + java(before, after) + ); + } + + } } From e8adb61d4a3027b20868467eea50844ac6da4e87 Mon Sep 17 00:00:00 2001 From: Marvin Froeder Date: Mon, 8 Jul 2024 13:28:10 -0300 Subject: [PATCH 2/6] Create dedicated test for IsEqualToEmptyString --- .../assertj/IsEqualToEmptyStringTest.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/test/java/org/openrewrite/java/testing/assertj/IsEqualToEmptyStringTest.java diff --git a/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToEmptyStringTest.java b/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToEmptyStringTest.java new file mode 100644 index 000000000..d239df9e4 --- /dev/null +++ b/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToEmptyStringTest.java @@ -0,0 +1,56 @@ +/* + * Copyright 2024 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.java.testing.assertj; + +import static org.openrewrite.java.Assertions.java; + +import org.junit.jupiter.api.Test; +import org.openrewrite.InMemoryExecutionContext; +import org.openrewrite.java.JavaParser; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +class IsEqualToEmptyStringTest implements RewriteTest { + + @Override + public void defaults(RecipeSpec spec) { + spec + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3.24")) + .recipe(new IsEqualToEmptyString()); + } + + @Test + void convertsIsEqualToEmptyString() { + rewriteRun( + // language=java + java(""" + import static org.assertj.core.api.Assertions.assertThat; + class Test { + void test() { + assertThat("test").isEqualTo(""); + } + } + """, """ + import static org.assertj.core.api.Assertions.assertThat; + class Test { + void test() { + assertThat("test").isEmpty(); + } + } + """)); + } + +} From 1957fc846041c065f304fbcbd11be841ca147b0b Mon Sep 17 00:00:00 2001 From: Marvin Froeder Date: Mon, 8 Jul 2024 13:28:27 -0300 Subject: [PATCH 3/6] AssertJ has a more idiomatic way of asserting that a boolean is true. This recipe will find instances of: -`assertThat(boolean).isEqualTo(true)` and replace them with `isTrue()`. -`assertThat(boolean).isEqualTo(false)` and replace them with `isFalse()`. Signed-off-by: Marvin Froeder --- .../testing/assertj/IsEqualToBoolean.java | 74 ++++++++++++++++++ .../testing/assertj/IsEqualToBooleanTest.java | 77 +++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 src/main/java/org/openrewrite/java/testing/assertj/IsEqualToBoolean.java create mode 100644 src/test/java/org/openrewrite/java/testing/assertj/IsEqualToBooleanTest.java diff --git a/src/main/java/org/openrewrite/java/testing/assertj/IsEqualToBoolean.java b/src/main/java/org/openrewrite/java/testing/assertj/IsEqualToBoolean.java new file mode 100644 index 000000000..4a907911a --- /dev/null +++ b/src/main/java/org/openrewrite/java/testing/assertj/IsEqualToBoolean.java @@ -0,0 +1,74 @@ +/* + * Copyright 2024 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.java.testing.assertj; + +import org.openrewrite.ExecutionContext; +import org.openrewrite.Preconditions; +import org.openrewrite.Recipe; +import org.openrewrite.TreeVisitor; +import org.openrewrite.java.JavaIsoVisitor; +import org.openrewrite.java.MethodMatcher; +import org.openrewrite.java.search.UsesMethod; +import org.openrewrite.java.tree.J; +import org.openrewrite.java.tree.J.MethodInvocation; +import org.openrewrite.java.tree.JavaType.Method; + +import java.util.Collections; + +/** + * AssertJ has a more idiomatic way of asserting that a boolean is true. This + * recipe will find instances of: + * + * -`assertThat(boolean).isEqualTo(true)` and replace them with `isTrue()`. + * -`assertThat(boolean).isEqualTo(false)` and replace them with `isFalse()`. + */ +public class IsEqualToBoolean extends Recipe { + + private static final MethodMatcher IS_EQUAL_TO = new MethodMatcher( + "org.assertj.core.api.AbstractBooleanAssert isEqualTo(boolean)"); + + @Override + public String getDisplayName() { + return "Convert `assertThat(String).isEqualTo(true)` to `isTrue()` and `isEqualTo(false)` to `isFalse()`"; + } + + @Override + public String getDescription() { + return "Adopt idiomatic AssertJ assertion for true booleans."; + } + + @Override + public TreeVisitor getVisitor() { + return Preconditions.check(new UsesMethod<>(IS_EQUAL_TO), new JavaIsoVisitor() { + @Override + public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { + MethodInvocation mi = super.visitMethodInvocation(method, ctx); + if (IS_EQUAL_TO.matches(mi)) { + String methodName; + if (J.Literal.isLiteralValue(mi.getArguments().get(0), true)) { + methodName = "isTrue"; + } else { + methodName = "isFalse"; + } + Method isBooleanMethod = mi.getMethodType().withName(methodName); + return mi.withName(mi.getName().withSimpleName(methodName).withType(isBooleanMethod)) + .withMethodType(isBooleanMethod).withArguments(Collections.emptyList()); + } + return mi; + } + }); + } +} diff --git a/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToBooleanTest.java b/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToBooleanTest.java new file mode 100644 index 000000000..a7bc8e65c --- /dev/null +++ b/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToBooleanTest.java @@ -0,0 +1,77 @@ +/* + * Copyright 2024 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.java.testing.assertj; + +import static org.openrewrite.java.Assertions.java; + +import org.junit.jupiter.api.Test; +import org.openrewrite.InMemoryExecutionContext; +import org.openrewrite.java.JavaParser; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +class IsEqualToBooleanTest implements RewriteTest { + + @Override + public void defaults(RecipeSpec spec) { + spec + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3.24")) + .recipe(new IsEqualToBoolean()); + } + + @Test + void convertsIsEqualToTrue() { + rewriteRun( + // language=java + java(""" + import static org.assertj.core.api.Assertions.assertThat; + class Test { + void test() { + assertThat(true).isEqualTo(true); + } + } + """, """ + import static org.assertj.core.api.Assertions.assertThat; + class Test { + void test() { + assertThat(true).isTrue(); + } + } + """)); + } + + @Test + void convertsIsEqualToFalse() { + rewriteRun( + // language=java + java(""" + import static org.assertj.core.api.Assertions.assertThat; + class Test { + void test() { + assertThat(false).isEqualTo(false); + } + } + """, """ + import static org.assertj.core.api.Assertions.assertThat; + class Test { + void test() { + assertThat(false).isFalse(); + } + } + """)); + } + +} From e6c03a10d6cc48bbdfbbf65fc8f277b08403735a Mon Sep 17 00:00:00 2001 From: Marvin Date: Mon, 8 Jul 2024 13:49:30 -0300 Subject: [PATCH 4/6] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../java/testing/assertj/IsEqualToBooleanTest.java | 10 +++++++--- .../java/testing/assertj/IsEqualToEmptyStringTest.java | 7 +++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToBooleanTest.java b/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToBooleanTest.java index a7bc8e65c..149f040f9 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToBooleanTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToBooleanTest.java @@ -15,6 +15,7 @@ */ package org.openrewrite.java.testing.assertj; +import org.openrewrite.DocumentExample; import static org.openrewrite.java.Assertions.java; import org.junit.jupiter.api.Test; @@ -31,8 +32,10 @@ public void defaults(RecipeSpec spec) { .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3.24")) .recipe(new IsEqualToBoolean()); } - - @Test + + @DocumentExample + java( + """ void convertsIsEqualToTrue() { rewriteRun( // language=java @@ -57,7 +60,8 @@ void test() { void convertsIsEqualToFalse() { rewriteRun( // language=java - java(""" + java( + """ import static org.assertj.core.api.Assertions.assertThat; class Test { void test() { diff --git a/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToEmptyStringTest.java b/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToEmptyStringTest.java index d239df9e4..9bc1fc2ad 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToEmptyStringTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToEmptyStringTest.java @@ -15,6 +15,7 @@ */ package org.openrewrite.java.testing.assertj; +import org.openrewrite.DocumentExample; import static org.openrewrite.java.Assertions.java; import org.junit.jupiter.api.Test; @@ -31,8 +32,10 @@ public void defaults(RecipeSpec spec) { .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3.24")) .recipe(new IsEqualToEmptyString()); } - - @Test + + @DocumentExample + java( + """ void convertsIsEqualToEmptyString() { rewriteRun( // language=java From 20074900443f8526d1c113326a36774fb5267631 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Mon, 8 Jul 2024 19:11:05 +0200 Subject: [PATCH 5/6] Apply formatter --- .../testing/assertj/IsEqualToBoolean.java | 2 +- .../testing/assertj/IsEqualToBooleanTest.java | 87 ++++++++++--------- .../assertj/IsEqualToEmptyStringTest.java | 47 +++++----- .../MigrateChainedAssertToAssertJTest.java | 66 +++++++------- 4 files changed, 104 insertions(+), 98 deletions(-) diff --git a/src/main/java/org/openrewrite/java/testing/assertj/IsEqualToBoolean.java b/src/main/java/org/openrewrite/java/testing/assertj/IsEqualToBoolean.java index 4a907911a..e0a9bcc7e 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/IsEqualToBoolean.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/IsEqualToBoolean.java @@ -31,7 +31,7 @@ /** * AssertJ has a more idiomatic way of asserting that a boolean is true. This * recipe will find instances of: - * + *

* -`assertThat(boolean).isEqualTo(true)` and replace them with `isTrue()`. * -`assertThat(boolean).isEqualTo(false)` and replace them with `isFalse()`. */ diff --git a/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToBooleanTest.java b/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToBooleanTest.java index 149f040f9..c208d7a79 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToBooleanTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToBooleanTest.java @@ -15,67 +15,72 @@ */ package org.openrewrite.java.testing.assertj; -import org.openrewrite.DocumentExample; -import static org.openrewrite.java.Assertions.java; - import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.java.JavaParser; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; +import static org.openrewrite.java.Assertions.java; + class IsEqualToBooleanTest implements RewriteTest { - + @Override public void defaults(RecipeSpec spec) { spec - .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3.24")) - .recipe(new IsEqualToBoolean()); + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3.24")) + .recipe(new IsEqualToBoolean()); } @DocumentExample - java( - """ void convertsIsEqualToTrue() { rewriteRun( - // language=java - java(""" - import static org.assertj.core.api.Assertions.assertThat; - class Test { - void test() { - assertThat(true).isEqualTo(true); - } - } - """, """ - import static org.assertj.core.api.Assertions.assertThat; - class Test { - void test() { - assertThat(true).isTrue(); - } - } - """)); + // language=java + java( + """ + import static org.assertj.core.api.Assertions.assertThat; + class Test { + void test() { + assertThat(true).isEqualTo(true); + } + } + """, + """ + import static org.assertj.core.api.Assertions.assertThat; + class Test { + void test() { + assertThat(true).isTrue(); + } + } + """ + ) + ); } @Test void convertsIsEqualToFalse() { rewriteRun( - // language=java - java( - """ - import static org.assertj.core.api.Assertions.assertThat; - class Test { - void test() { - assertThat(false).isEqualTo(false); - } - } - """, """ - import static org.assertj.core.api.Assertions.assertThat; - class Test { - void test() { - assertThat(false).isFalse(); - } - } - """)); + // language=java + java( + """ + import static org.assertj.core.api.Assertions.assertThat; + class Test { + void test() { + assertThat(false).isEqualTo(false); + } + } + """, + """ + import static org.assertj.core.api.Assertions.assertThat; + class Test { + void test() { + assertThat(false).isFalse(); + } + } + """ + ) + ); } } diff --git a/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToEmptyStringTest.java b/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToEmptyStringTest.java index 9bc1fc2ad..8ba2477e6 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToEmptyStringTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToEmptyStringTest.java @@ -16,44 +16,45 @@ package org.openrewrite.java.testing.assertj; import org.openrewrite.DocumentExample; -import static org.openrewrite.java.Assertions.java; - -import org.junit.jupiter.api.Test; import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.java.JavaParser; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; +import static org.openrewrite.java.Assertions.java; + class IsEqualToEmptyStringTest implements RewriteTest { - + @Override public void defaults(RecipeSpec spec) { spec - .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3.24")) + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3.24")) .recipe(new IsEqualToEmptyString()); } @DocumentExample - java( - """ void convertsIsEqualToEmptyString() { rewriteRun( - // language=java - java(""" - import static org.assertj.core.api.Assertions.assertThat; - class Test { - void test() { - assertThat("test").isEqualTo(""); - } - } - """, """ - import static org.assertj.core.api.Assertions.assertThat; - class Test { - void test() { - assertThat("test").isEmpty(); - } - } - """)); + // language=java + java( + """ + import static org.assertj.core.api.Assertions.assertThat; + class Test { + void test() { + assertThat("test").isEqualTo(""); + } + } + """, + """ + import static org.assertj.core.api.Assertions.assertThat; + class Test { + void test() { + assertThat("test").isEmpty(); + } + } + """ + ) + ); } } diff --git a/src/test/java/org/openrewrite/java/testing/assertj/MigrateChainedAssertToAssertJTest.java b/src/test/java/org/openrewrite/java/testing/assertj/MigrateChainedAssertToAssertJTest.java index f97aec77c..62c146fa8 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/MigrateChainedAssertToAssertJTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/MigrateChainedAssertToAssertJTest.java @@ -56,31 +56,33 @@ void stringIsEmptyExample() { rewriteRun( //language=java java( - """ - import org.junit.jupiter.api.Test; - - import static org.assertj.core.api.Assertions.assertThat; - - class MyTest { - @Test - void testMethod() { - String s = "hello world"; - assertThat(s.isEmpty()).isTrue(); - } - } - """, """ - import org.junit.jupiter.api.Test; - - import static org.assertj.core.api.Assertions.assertThat; - - class MyTest { - @Test - void testMethod() { - String s = "hello world"; - assertThat(s).isEmpty(); - } - } - """) + """ + import org.junit.jupiter.api.Test; + + import static org.assertj.core.api.Assertions.assertThat; + + class MyTest { + @Test + void testMethod() { + String s = "hello world"; + assertThat(s.isEmpty()).isTrue(); + } + } + """, + """ + import org.junit.jupiter.api.Test; + + import static org.assertj.core.api.Assertions.assertThat; + + class MyTest { + @Test + void testMethod() { + String s = "hello world"; + assertThat(s).isEmpty(); + } + } + """ + ) ); } @@ -343,9 +345,9 @@ void mapHasSameSizeAs() { """ import org.junit.jupiter.api.Test; import java.util.Map; - + import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { @Test void testMethod() { @@ -358,9 +360,9 @@ void testMethod() { """ import org.junit.jupiter.api.Test; import java.util.Map; - + import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { @Test void testMethod() { @@ -414,7 +416,6 @@ void test() { rewriteRun(java(before, after)); } } - @Nested class Iteratorz { @@ -431,9 +432,9 @@ void collectionReplacements(String chainedAssertion, String assertToReplace, Str //language=java String template = """ import java.util.Iterator; - + import static org.assertj.core.api.Assertions.assertThat; - + class A { void test(Iterator iterator, Iterator otherIterator) { String something = ""; @@ -453,6 +454,5 @@ void test(Iterator iterator, Iterator otherIterator) { java(before, after) ); } - } } From 3936cfd46891da416e0b3447a0a1c9fb18558c3b Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Mon, 8 Jul 2024 20:08:33 +0200 Subject: [PATCH 6/6] Add missing `@Test` annotations --- .../testing/assertj/IsEqualToBooleanTest.java | 2 +- .../assertj/IsEqualToEmptyStringTest.java | 3 +- .../MigrateChainedAssertToAssertJTest.java | 42 +++++++++---------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToBooleanTest.java b/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToBooleanTest.java index c208d7a79..8202f1ff0 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToBooleanTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToBooleanTest.java @@ -34,6 +34,7 @@ public void defaults(RecipeSpec spec) { } @DocumentExample + @Test void convertsIsEqualToTrue() { rewriteRun( // language=java @@ -82,5 +83,4 @@ void test() { ) ); } - } diff --git a/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToEmptyStringTest.java b/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToEmptyStringTest.java index 8ba2477e6..61a41413e 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToEmptyStringTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/IsEqualToEmptyStringTest.java @@ -15,6 +15,7 @@ */ package org.openrewrite.java.testing.assertj; +import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.java.JavaParser; @@ -33,6 +34,7 @@ public void defaults(RecipeSpec spec) { } @DocumentExample + @Test void convertsIsEqualToEmptyString() { rewriteRun( // language=java @@ -56,5 +58,4 @@ void test() { ) ); } - } diff --git a/src/test/java/org/openrewrite/java/testing/assertj/MigrateChainedAssertToAssertJTest.java b/src/test/java/org/openrewrite/java/testing/assertj/MigrateChainedAssertToAssertJTest.java index 62c146fa8..99bb27790 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/MigrateChainedAssertToAssertJTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/MigrateChainedAssertToAssertJTest.java @@ -58,9 +58,9 @@ void stringIsEmptyExample() { java( """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { @Test void testMethod() { @@ -71,9 +71,9 @@ void testMethod() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { @Test void testMethod() { @@ -107,9 +107,9 @@ void stringReplacements(String chainedAssertion, String assertToReplace, String //language=java String template = """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { @Test void test() { @@ -163,9 +163,9 @@ void fileReplacements(String chainedAssertion, String assertToReplace, String de String template = """ import org.junit.jupiter.api.Test; import java.io.File; - + import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { @Test void test() { @@ -212,9 +212,9 @@ void pathReplacements(String chainedAssertion, String assertToReplace, String de import org.junit.jupiter.api.Test; import java.nio.file.Path; import java.nio.file.Paths; - + import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { @Test void test() { @@ -260,9 +260,9 @@ void collectionReplacements(String chainedAssertion, String assertToReplace, Str //language=java String template = """ import java.util.Collection; - + import static org.assertj.core.api.Assertions.assertThat; - + class A { void test(Collection collection, Collection otherCollection) { String something = ""; @@ -305,9 +305,9 @@ void mapReplacements(String chainedAssertion, String assertToReplace, String ded import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.Map; - + import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { @Test void test() { @@ -345,9 +345,9 @@ void mapHasSameSizeAs() { """ import org.junit.jupiter.api.Test; import java.util.Map; - + import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { @Test void testMethod() { @@ -360,9 +360,9 @@ void testMethod() { """ import org.junit.jupiter.api.Test; import java.util.Map; - + import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { @Test void testMethod() { @@ -394,9 +394,9 @@ void optionalReplacements(String chainedAssertion, String assertToReplace, Strin String template = """ import org.junit.jupiter.api.Test; import java.util.Optional; - + import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { @Test void test() { @@ -418,7 +418,7 @@ void test() { } @Nested - class Iteratorz { + class Iterators { private static Stream collectionReplacements() { return Stream.of( Arguments.arguments("hasNext", "isTrue", "hasNext"),