Skip to content

Commit f9674f6

Browse files
committed
Update the StringFormatted single source applicability test to use Applicability#and, also update the StringFormattedTest to use the new Assertions#version(SourceSpecs, int).
1 parent 77f5e85 commit f9674f6

File tree

2 files changed

+16
-27
lines changed

2 files changed

+16
-27
lines changed

src/main/java/org/openrewrite/java/migrate/lang/StringFormatted.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.openrewrite.java.migrate.lang;
1717

18+
import org.openrewrite.Applicability;
1819
import org.openrewrite.ExecutionContext;
1920
import org.openrewrite.Recipe;
2021
import org.openrewrite.TreeVisitor;
@@ -24,7 +25,6 @@
2425
import org.openrewrite.java.search.UsesMethod;
2526
import org.openrewrite.java.tree.Expression;
2627
import org.openrewrite.java.tree.J;
27-
import org.openrewrite.java.tree.JavaSourceFile;
2828

2929
import java.time.Duration;
3030
import java.util.Collections;
@@ -46,16 +46,7 @@ public String getDescription() {
4646

4747
@Override
4848
protected TreeVisitor<?, ExecutionContext> getSingleSourceApplicableTest() {
49-
return new JavaIsoVisitor<ExecutionContext>() {
50-
@Override
51-
public JavaSourceFile visitJavaSourceFile(JavaSourceFile cu, ExecutionContext executionContext) {
52-
JavaSourceFile sf = (JavaSourceFile) new UsesJavaVersion<ExecutionContext>(17).visit(cu, executionContext);
53-
if (sf != cu) {
54-
doAfterVisit(new UsesMethod<>(STRING_FORMAT));
55-
}
56-
return cu;
57-
}
58-
};
49+
return Applicability.and(new UsesJavaVersion<>(17),new UsesMethod<>(STRING_FORMAT));
5950
}
6051

6152
@Override

src/test/kotlin/org/openrewrite/java/migrate/lang/StringFormattedTest.kt

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import org.openrewrite.java.Assertions.*
2121
import org.openrewrite.java.JavaParser
2222
import org.openrewrite.test.RecipeSpec
2323
import org.openrewrite.test.RewriteTest
24-
import org.openrewrite.test.SourceSpec
2524
import org.openrewrite.test.TypeValidation
2625

2726
@Suppress("RedundantStringFormatCall")
@@ -45,7 +44,7 @@ class StringFormattedTest : RewriteTest {
4544
class A {
4645
String str = "foo".formatted();
4746
}
48-
""") as SourceSpec<*>,
47+
"""),
4948
17)
5049
)
5150

@@ -62,7 +61,7 @@ class StringFormattedTest : RewriteTest {
6261
class A {
6362
String str = "foo %s".formatted("a");
6463
}
65-
""") as SourceSpec<*>, 17
64+
"""), 17
6665
)
6766
)
6867

@@ -79,7 +78,7 @@ class StringFormattedTest : RewriteTest {
7978
class A {
8079
String str = "foo %s %d".formatted("a", 1);
8180
}
82-
""") as SourceSpec<*>, 17
81+
"""), 17
8382
)
8483
)
8584

@@ -96,7 +95,7 @@ class StringFormattedTest : RewriteTest {
9695
class A {
9796
String str = "foo %s %d %f".formatted("a", 1, 2.0);
9897
}
99-
""") as SourceSpec<*>, 17
98+
"""), 17
10099
)
101100
)
102101

@@ -113,7 +112,7 @@ class StringFormattedTest : RewriteTest {
113112
class A {
114113
String str = ("foo " + "%s").formatted("a");
115114
}
116-
""") as SourceSpec<*>, 17
115+
"""), 17
117116
)
118117
)
119118

@@ -130,7 +129,7 @@ class StringFormattedTest : RewriteTest {
130129
class A {
131130
String str = "foo %s".formatted("a" + "b");
132131
}
133-
""") as SourceSpec<*>, 17
132+
"""), 17
134133
)
135134
)
136135

@@ -153,7 +152,7 @@ class StringFormattedTest : RewriteTest {
153152
return "foo %s";
154153
}
155154
}
156-
""") as SourceSpec<*>, 17
155+
"""), 17
157156
)
158157
)
159158

@@ -176,7 +175,7 @@ class StringFormattedTest : RewriteTest {
176175
String str = fmt.formatted("a");
177176
}
178177
}
179-
""") as SourceSpec<*>, 17
178+
"""), 17
180179
)
181180
)
182181

@@ -195,7 +194,7 @@ class StringFormattedTest : RewriteTest {
195194
static final String fmt = "foo %s";
196195
String str = fmt.formatted("a");
197196
}
198-
""") as SourceSpec<*>, 17
197+
"""), 17
199198
)
200199
)
201200

@@ -213,7 +212,7 @@ class StringFormattedTest : RewriteTest {
213212
class A {
214213
String str = "foo %s".formatted("a");
215214
}
216-
""") as SourceSpec<*>, 17
215+
"""), 17
217216
)
218217
)
219218

@@ -226,7 +225,7 @@ class StringFormattedTest : RewriteTest {
226225
class A {
227226
String str = String.format(Locale.US, "foo %s", "a");
228227
}
229-
""") as SourceSpec<*>, 17
228+
"""), 17
230229
)
231230
)
232231

@@ -243,7 +242,7 @@ class StringFormattedTest : RewriteTest {
243242
class A {
244243
String str = "foo %s %s".formatted("a", "b");
245244
}
246-
""") as SourceSpec<*>, 17
245+
"""), 17
247246
)
248247
)
249248

@@ -264,8 +263,7 @@ class StringFormattedTest : RewriteTest {
264263
"a",
265264
"b");
266265
}
267-
""") as SourceSpec<*>, 17
268-
)
266+
"""), 17)
269267
)
270268

271269
@Test
@@ -287,7 +285,7 @@ class StringFormattedTest : RewriteTest {
287285
// B
288286
"b");
289287
}
290-
""") as SourceSpec<*>, 17
288+
"""), 17
291289
)
292290
)
293291

0 commit comments

Comments
 (0)