diff --git a/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaImmutableListOf.java b/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaImmutableListOf.java index 261f5067d8..5574f818c4 100644 --- a/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaImmutableListOf.java +++ b/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaImmutableListOf.java @@ -15,11 +15,11 @@ */ package org.openrewrite.java.migrate.guava; +import org.openrewrite.Applicability; import org.openrewrite.ExecutionContext; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; import org.openrewrite.internal.lang.Nullable; -import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaTemplate; import org.openrewrite.java.JavaVisitor; import org.openrewrite.java.MethodMatcher; @@ -57,15 +57,9 @@ public Duration getEstimatedEffortPerOccurrence() { } @Override - protected JavaVisitor getSingleSourceApplicableTest() { - return new JavaIsoVisitor() { - @Override - public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionContext executionContext) { - doAfterVisit(new UsesJavaVersion<>(9)); - doAfterVisit(new UsesType<>("com.google.common.collect.ImmutableList")); - return cu; - } - }; + protected TreeVisitor getSingleSourceApplicableTest() { + return Applicability.and(new UsesJavaVersion<>(9), + new UsesType<>("com.google.common.collect.ImmutableList")); } // Code is shared between `NoGuavaImmutableMapOf`, `NoGuavaImmutableListOf`, and `NoGuavaImmutableSetOf`. diff --git a/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaImmutableMapOf.java b/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaImmutableMapOf.java index af8a29fa64..5b0cdf170a 100644 --- a/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaImmutableMapOf.java +++ b/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaImmutableMapOf.java @@ -15,11 +15,11 @@ */ package org.openrewrite.java.migrate.guava; +import org.openrewrite.Applicability; import org.openrewrite.ExecutionContext; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; import org.openrewrite.internal.lang.Nullable; -import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaTemplate; import org.openrewrite.java.JavaVisitor; import org.openrewrite.java.MethodMatcher; @@ -57,15 +57,9 @@ public Duration getEstimatedEffortPerOccurrence() { } @Override - protected JavaVisitor getSingleSourceApplicableTest() { - return new JavaIsoVisitor() { - @Override - public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionContext executionContext) { - doAfterVisit(new UsesJavaVersion<>(9)); - doAfterVisit(new UsesType<>("com.google.common.collect.ImmutableMap")); - return cu; - } - }; + protected TreeVisitor getSingleSourceApplicableTest() { + return Applicability.and(new UsesJavaVersion<>(9), + new UsesType<>("com.google.common.collect.ImmutableMap")); } // Code is shared between `NoGuavaImmutableMapOf`, `NoGuavaImmutableListOf`, and `NoGuavaImmutableSetOf`. diff --git a/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaImmutableSetOf.java b/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaImmutableSetOf.java index 26aaae2734..5f2e57a1ba 100644 --- a/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaImmutableSetOf.java +++ b/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaImmutableSetOf.java @@ -15,11 +15,11 @@ */ package org.openrewrite.java.migrate.guava; +import org.openrewrite.Applicability; import org.openrewrite.ExecutionContext; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; import org.openrewrite.internal.lang.Nullable; -import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaTemplate; import org.openrewrite.java.JavaVisitor; import org.openrewrite.java.MethodMatcher; @@ -60,15 +60,9 @@ public Duration getEstimatedEffortPerOccurrence() { } @Override - protected JavaVisitor getSingleSourceApplicableTest() { - return new JavaIsoVisitor() { - @Override - public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionContext executionContext) { - doAfterVisit(new UsesJavaVersion<>(9)); - doAfterVisit(new UsesType<>("com.google.common.collect.ImmutableSet")); - return cu; - } - }; + protected TreeVisitor getSingleSourceApplicableTest() { + return Applicability.and(new UsesJavaVersion<>(9), + new UsesType<>("com.google.common.collect.ImmutableSet")); } // Code is shared between `NoGuavaImmutableMapOf`, `NoGuavaImmutableListOf`, and `NoGuavaImmutableSetOf`. diff --git a/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonList.java b/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonList.java index fb70a73acc..f1c0edefbc 100644 --- a/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonList.java +++ b/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonList.java @@ -15,9 +15,10 @@ */ package org.openrewrite.java.migrate.util; +import org.openrewrite.Applicability; import org.openrewrite.ExecutionContext; import org.openrewrite.Recipe; -import org.openrewrite.java.JavaIsoVisitor; +import org.openrewrite.TreeVisitor; import org.openrewrite.java.JavaTemplate; import org.openrewrite.java.JavaVisitor; import org.openrewrite.java.MethodMatcher; @@ -46,15 +47,9 @@ public String getDescription() { } @Override - protected JavaVisitor getSingleSourceApplicableTest() { - return new JavaIsoVisitor() { - @Override - public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionContext executionContext) { - doAfterVisit(new UsesJavaVersion<>(9)); - doAfterVisit(new UsesMethod<>(SINGLETON_LIST)); - return cu; - } - }; + protected TreeVisitor getSingleSourceApplicableTest() { + return Applicability.and(new UsesJavaVersion<>(9), + new UsesMethod<>(SINGLETON_LIST)); } @Override diff --git a/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonMap.java b/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonMap.java index 3e35cc025a..49626932f6 100644 --- a/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonMap.java +++ b/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonMap.java @@ -15,9 +15,10 @@ */ package org.openrewrite.java.migrate.util; +import org.openrewrite.Applicability; import org.openrewrite.ExecutionContext; import org.openrewrite.Recipe; -import org.openrewrite.java.JavaIsoVisitor; +import org.openrewrite.TreeVisitor; import org.openrewrite.java.JavaTemplate; import org.openrewrite.java.JavaVisitor; import org.openrewrite.java.MethodMatcher; @@ -49,15 +50,9 @@ public String getDescription() { } @Override - protected JavaVisitor getSingleSourceApplicableTest() { - return new JavaIsoVisitor() { - @Override - public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionContext executionContext) { - doAfterVisit(new UsesJavaVersion<>(9)); - doAfterVisit(new UsesMethod<>(SINGLETON_MAP)); - return cu; - } - }; + protected TreeVisitor getSingleSourceApplicableTest() { + return Applicability.and(new UsesJavaVersion<>(9), + new UsesMethod<>(SINGLETON_MAP)); } @Override diff --git a/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonSet.java b/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonSet.java index 8c0d35db34..e9cb50bbbc 100644 --- a/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonSet.java +++ b/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonSet.java @@ -15,9 +15,10 @@ */ package org.openrewrite.java.migrate.util; +import org.openrewrite.Applicability; import org.openrewrite.ExecutionContext; import org.openrewrite.Recipe; -import org.openrewrite.java.JavaIsoVisitor; +import org.openrewrite.TreeVisitor; import org.openrewrite.java.JavaTemplate; import org.openrewrite.java.JavaVisitor; import org.openrewrite.java.MethodMatcher; @@ -46,15 +47,9 @@ public String getDescription() { } @Override - protected JavaVisitor getSingleSourceApplicableTest() { - return new JavaIsoVisitor() { - @Override - public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionContext executionContext) { - doAfterVisit(new UsesJavaVersion<>(9)); - doAfterVisit(new UsesMethod<>(SINGLETON_SET)); - return cu; - } - }; + protected TreeVisitor getSingleSourceApplicableTest() { + return Applicability.and(new UsesJavaVersion<>(9), + new UsesMethod<>(SINGLETON_SET)); } @Override diff --git a/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsUnmodifiableList.java b/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsUnmodifiableList.java index ce4eb9ca27..48bfd9fd6c 100644 --- a/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsUnmodifiableList.java +++ b/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsUnmodifiableList.java @@ -15,9 +15,10 @@ */ package org.openrewrite.java.migrate.util; +import org.openrewrite.Applicability; import org.openrewrite.ExecutionContext; import org.openrewrite.Recipe; -import org.openrewrite.java.JavaIsoVisitor; +import org.openrewrite.TreeVisitor; import org.openrewrite.java.JavaTemplate; import org.openrewrite.java.JavaVisitor; import org.openrewrite.java.MethodMatcher; @@ -50,15 +51,9 @@ public String getDescription() { } @Override - protected JavaVisitor getSingleSourceApplicableTest() { - return new JavaIsoVisitor() { - @Override - public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionContext executionContext) { - doAfterVisit(new UsesJavaVersion<>(9)); - doAfterVisit(new UsesMethod<>(UNMODIFIABLE_LIST)); - return cu; - } - }; + protected TreeVisitor getSingleSourceApplicableTest() { + return Applicability.and(new UsesJavaVersion<>(9), + new UsesMethod<>(UNMODIFIABLE_LIST)); } @Override diff --git a/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsUnmodifiableSet.java b/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsUnmodifiableSet.java index 564b649c45..cbb92a5a15 100644 --- a/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsUnmodifiableSet.java +++ b/src/main/java/org/openrewrite/java/migrate/util/MigrateCollectionsUnmodifiableSet.java @@ -15,9 +15,10 @@ */ package org.openrewrite.java.migrate.util; +import org.openrewrite.Applicability; import org.openrewrite.ExecutionContext; import org.openrewrite.Recipe; -import org.openrewrite.java.JavaIsoVisitor; +import org.openrewrite.TreeVisitor; import org.openrewrite.java.JavaTemplate; import org.openrewrite.java.JavaVisitor; import org.openrewrite.java.MethodMatcher; @@ -50,15 +51,9 @@ public String getDescription() { } @Override - protected JavaVisitor getSingleSourceApplicableTest() { - return new JavaIsoVisitor() { - @Override - public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionContext executionContext) { - doAfterVisit(new UsesJavaVersion<>(9)); - doAfterVisit(new UsesMethod<>(UNMODIFIABLE_SET)); - return cu; - } - }; + protected TreeVisitor getSingleSourceApplicableTest() { + return Applicability.and(new UsesJavaVersion<>(9), + new UsesMethod<>(UNMODIFIABLE_SET)); } @Override diff --git a/src/main/java/org/openrewrite/java/migrate/util/UseEnumSetOf.java b/src/main/java/org/openrewrite/java/migrate/util/UseEnumSetOf.java index 5f2e406a65..4b399d0d26 100644 --- a/src/main/java/org/openrewrite/java/migrate/util/UseEnumSetOf.java +++ b/src/main/java/org/openrewrite/java/migrate/util/UseEnumSetOf.java @@ -15,14 +15,10 @@ */ package org.openrewrite.java.migrate.util; -import org.openrewrite.Cursor; -import org.openrewrite.ExecutionContext; -import org.openrewrite.Recipe; -import org.openrewrite.TreeVisitor; +import org.openrewrite.*; import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaTemplate; -import org.openrewrite.java.JavaVisitor; import org.openrewrite.java.MethodMatcher; import org.openrewrite.java.search.UsesJavaVersion; import org.openrewrite.java.search.UsesMethod; @@ -54,15 +50,9 @@ public Duration getEstimatedEffortPerOccurrence() { } @Override - protected JavaVisitor getSingleSourceApplicableTest() { - return new JavaIsoVisitor() { - @Override - public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionContext executionContext) { - doAfterVisit(new UsesJavaVersion<>(9)); - doAfterVisit(new UsesMethod<>(SET_OF)); - return cu; - } - }; + protected TreeVisitor getSingleSourceApplicableTest() { + return Applicability.and(new UsesJavaVersion<>(9), + new UsesMethod<>(SET_OF)); } @Override diff --git a/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonListTest.kt b/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonListTest.kt index c4fb3ab15e..5e758e4883 100644 --- a/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonListTest.kt +++ b/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonListTest.kt @@ -17,36 +17,41 @@ package org.openrewrite.java.migrate.util import org.junit.jupiter.api.Test import org.openrewrite.Issue -import org.openrewrite.Recipe -import org.openrewrite.java.JavaRecipeTest +import org.openrewrite.java.Assertions.java +import org.openrewrite.java.Assertions.version +import org.openrewrite.test.RecipeSpec +import org.openrewrite.test.RewriteTest -class MigrateCollectionsSingletonListTest : JavaRecipeTest { - override val recipe: Recipe - get() = MigrateCollectionsSingletonList() +class MigrateCollectionsSingletonListTest : RewriteTest { + override fun defaults(spec: RecipeSpec) { + spec.recipe(MigrateCollectionsSingletonList()) + } @Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/72") @Test - fun singletonList() = assertChanged( - before = """ + fun singletonList() = rewriteRun( + version( + java(""" import java.util.*; class Test { List list = Collections.singletonList("ABC"); } """, - after = """ + """ import java.util.List; class Test { List list = List.of("ABC"); } - """ + """), 9) ) @Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/72") @Test - fun singletonListCustomType() = assertChanged( - before = """ + fun singletonListCustomType() = rewriteRun( + version( + java(""" import java.util.*; import java.time.LocalDate; @@ -54,14 +59,14 @@ class MigrateCollectionsSingletonListTest : JavaRecipeTest { List list = Collections.singletonList(LocalDate.now()); } """, - after = """ + """ import java.util.List; import java.time.LocalDate; class Test { List list = List.of(LocalDate.now()); } - """ + """), 9) ) } diff --git a/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonMapTest.kt b/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonMapTest.kt index caed5068f9..2026ed8cc4 100644 --- a/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonMapTest.kt +++ b/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonMapTest.kt @@ -17,36 +17,41 @@ package org.openrewrite.java.migrate.util import org.junit.jupiter.api.Test import org.openrewrite.Issue -import org.openrewrite.Recipe -import org.openrewrite.java.JavaRecipeTest +import org.openrewrite.java.Assertions.java +import org.openrewrite.java.Assertions.version +import org.openrewrite.test.RecipeSpec +import org.openrewrite.test.RewriteTest -class MigrateCollectionsSingletonMapTest : JavaRecipeTest { - override val recipe: Recipe - get() = MigrateCollectionsSingletonMap() +class MigrateCollectionsSingletonMapTest : RewriteTest { + override fun defaults(spec: RecipeSpec) { + spec.recipe(MigrateCollectionsSingletonMap()) + } @Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/72") @Test - fun singletonMap() = assertChanged( - before = """ + fun singletonMap() = rewriteRun( + version( + java(""" import java.util.*; class Test { Map set = Collections.singletonMap("hello", "world"); } """, - after = """ + """ import java.util.Map; class Test { Map set = Map.of("hello", "world"); } - """ + """), 9) ) @Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/72") @Test - fun singletonMapCustomType() = assertChanged( - before = """ + fun singletonMapCustomType() = rewriteRun( + version( + java(""" import java.util.*; import java.time.LocalDate; @@ -54,14 +59,14 @@ class MigrateCollectionsSingletonMapTest : JavaRecipeTest { Map map = Collections.singletonMap("date", LocalDate.now()); } """, - after = """ + """ import java.util.Map; import java.time.LocalDate; class Test { Map map = Map.of("date", LocalDate.now()); } - """ + """),9) ) } diff --git a/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonSetTest.kt b/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonSetTest.kt index a5f9b62d3c..80bab2bf57 100644 --- a/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonSetTest.kt +++ b/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsSingletonSetTest.kt @@ -17,36 +17,41 @@ package org.openrewrite.java.migrate.util import org.junit.jupiter.api.Test import org.openrewrite.Issue -import org.openrewrite.Recipe -import org.openrewrite.java.JavaRecipeTest +import org.openrewrite.java.Assertions.java +import org.openrewrite.java.Assertions.version +import org.openrewrite.test.RecipeSpec +import org.openrewrite.test.RewriteTest -class MigrateCollectionsSingletonSetTest : JavaRecipeTest { - override val recipe: Recipe - get() = MigrateCollectionsSingletonSet() +class MigrateCollectionsSingletonSetTest : RewriteTest { + override fun defaults(spec: RecipeSpec) { + spec.recipe(MigrateCollectionsSingletonSet()) + } @Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/72") @Test - fun singleTonSet() = assertChanged( - before = """ + fun singleTonSet() = rewriteRun( + version( + java(""" import java.util.*; class Test { Set set = Collections.singleton("Hello"); } """, - after = """ + """ import java.util.Set; class Test { Set set = Set.of("Hello"); } - """ + """), 9) ) @Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/72") @Test - fun singletonSetCustomType() = assertChanged( - before = """ + fun singletonSetCustomType() = rewriteRun( + version( + java(""" import java.util.*; import java.time.LocalDate; @@ -54,14 +59,14 @@ class MigrateCollectionsSingletonSetTest : JavaRecipeTest { Set set = Collections.singleton(LocalDate.now()); } """, - after = """ + """ import java.util.Set; import java.time.LocalDate; class Test { Set set = Set.of(LocalDate.now()); } - """ + """), 9) ) } diff --git a/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsUnmodifiableListTest.kt b/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsUnmodifiableListTest.kt index c7bc903c56..4afec0b158 100644 --- a/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsUnmodifiableListTest.kt +++ b/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsUnmodifiableListTest.kt @@ -17,36 +17,42 @@ package org.openrewrite.java.migrate.util import org.junit.jupiter.api.Test import org.openrewrite.Issue -import org.openrewrite.Recipe -import org.openrewrite.java.JavaRecipeTest +import org.openrewrite.java.Assertions.java +import org.openrewrite.java.Assertions.version +import org.openrewrite.test.RecipeSpec +import org.openrewrite.test.RewriteTest -class MigrateCollectionsUnmodifiableListTest : JavaRecipeTest { - override val recipe: Recipe - get() = MigrateCollectionsUnmodifiableList() +@Suppress("Java9CollectionFactory") +class MigrateCollectionsUnmodifiableListTest : RewriteTest { + override fun defaults(spec: RecipeSpec) { + spec.recipe(MigrateCollectionsUnmodifiableList()) + } @Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/67") @Test - fun unmodifiableList() = assertChanged( - before = """ + fun unmodifiableList() = rewriteRun( + version( + java(""" import java.util.*; class Test { List l = Collections.unmodifiableList(Arrays.asList(1, 2, 3)); } """, - after = """ + """ import java.util.List; class Test { List l = List.of(1, 2, 3); } - """ + """), 9) ) @Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/67") @Test - fun unmodifiableListTyped() = assertChanged( - before = """ + fun unmodifiableListTyped() = rewriteRun( + version( + java(""" import java.util.*; import java.time.LocalDate; @@ -54,13 +60,13 @@ class MigrateCollectionsUnmodifiableListTest : JavaRecipeTest { List s = Collections.unmodifiableList(Arrays.asList(LocalDate.of(2010,1,1),LocalDate.now())); } """, - after = """ + """ import java.util.List; import java.time.LocalDate; class Test { List s = List.of(LocalDate.of(2010, 1, 1), LocalDate.now()); } - """ + """), 9) ) } diff --git a/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsUnmodifiableSetTest.kt b/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsUnmodifiableSetTest.kt index c2d08c78d8..6089bc8224 100644 --- a/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsUnmodifiableSetTest.kt +++ b/src/test/kotlin/org/openrewrite/java/migrate/util/MigrateCollectionsUnmodifiableSetTest.kt @@ -17,36 +17,43 @@ package org.openrewrite.java.migrate.util import org.junit.jupiter.api.Test import org.openrewrite.Issue -import org.openrewrite.Recipe -import org.openrewrite.java.JavaRecipeTest +import org.openrewrite.java.Assertions.java +import org.openrewrite.java.Assertions.version +import org.openrewrite.test.RecipeSpec +import org.openrewrite.test.RewriteTest -class MigrateCollectionsUnmodifiableSetTest : JavaRecipeTest { - override val recipe: Recipe - get() = MigrateCollectionsUnmodifiableSet() +@Suppress("Java9CollectionFactory") +class MigrateCollectionsUnmodifiableSetTest : RewriteTest { + + override fun defaults(spec: RecipeSpec) { + spec.recipe(MigrateCollectionsUnmodifiableSet()) + } @Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/67") @Test - fun unmodifiableSet() = assertChanged( - before = """ + fun unmodifiableSet() = rewriteRun( + version( + java(""" import java.util.*; class Test { Set s = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(1, 2, 3))); } """, - after = """ + """ import java.util.Set; class Test { Set s = Set.of(1, 2, 3); } - """ + """), 9) ) @Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/67") @Test - fun unmodifiableSetTyped() = assertChanged( - before = """ + fun unmodifiableSetTyped() = rewriteRun( + version( + java(""" import java.util.*; import java.time.LocalDate; @@ -54,13 +61,13 @@ class MigrateCollectionsUnmodifiableSetTest : JavaRecipeTest { Set s = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(LocalDate.of(2010,1,1),LocalDate.now()))); } """, - after = """ + """ import java.util.Set; import java.time.LocalDate; class Test { Set s = Set.of(LocalDate.of(2010, 1, 1), LocalDate.now()); } - """ + """), 9) ) } diff --git a/src/test/kotlin/org/openrewrite/java/migrate/util/UseEnumSetOfTest.kt b/src/test/kotlin/org/openrewrite/java/migrate/util/UseEnumSetOfTest.kt index f73943009c..f08b300bbb 100644 --- a/src/test/kotlin/org/openrewrite/java/migrate/util/UseEnumSetOfTest.kt +++ b/src/test/kotlin/org/openrewrite/java/migrate/util/UseEnumSetOfTest.kt @@ -16,16 +16,22 @@ package org.openrewrite.java.migrate.util import org.junit.jupiter.api.Test -import org.openrewrite.Recipe -import org.openrewrite.java.JavaRecipeTest +import org.openrewrite.java.Assertions.java +import org.openrewrite.java.Assertions.version +import org.openrewrite.test.RecipeSpec +import org.openrewrite.test.RewriteTest -class UseEnumSetOfTest : JavaRecipeTest { - override val recipe: Recipe - get() = UseEnumSetOf() +@Suppress("UnusedAssignment") +class UseEnumSetOfTest : RewriteTest { + + override fun defaults(spec: RecipeSpec) { + spec.recipe(UseEnumSetOf()) + } @Test - fun changeDeclaration() = assertChanged( - before = """ + fun changeDeclaration() = rewriteRun( + version( + java(""" import java.util.Set; class Test { @@ -37,7 +43,7 @@ class UseEnumSetOfTest : JavaRecipeTest { } } """.trimIndent(), - after = """ + """ import java.util.EnumSet; import java.util.Set; @@ -49,12 +55,13 @@ class UseEnumSetOfTest : JavaRecipeTest { Set warm = EnumSet.of(Color.RED); } } - """.trimIndent() + """.trimIndent()), 9) ) @Test - fun changeAssignment() = assertChanged( - before = """ + fun changeAssignment() = rewriteRun( + version( + java(""" import java.util.Set; class Test { @@ -67,7 +74,7 @@ class UseEnumSetOfTest : JavaRecipeTest { } } """.trimIndent(), - after = """ + """ import java.util.EnumSet; import java.util.Set; @@ -80,6 +87,6 @@ class UseEnumSetOfTest : JavaRecipeTest { warm = EnumSet.of(Color.RED); } } - """.trimIndent() + """.trimIndent()), 9) ) }