Skip to content

Commit fa723de

Browse files
author
Vincent Potucek
committed
[openrewrite] apply rewrite
1 parent 1be28fd commit fa723de

14 files changed

+48
-80
lines changed

testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public ReadAsserter assertFile(File file) {
178178
return new ReadAsserter(file);
179179
}
180180

181-
public static class ReadAsserter {
181+
public static final class ReadAsserter {
182182
private final File file;
183183

184184
private ReadAsserter(File file) {
@@ -223,7 +223,7 @@ public WriteAsserter setFile(String path) {
223223
return new WriteAsserter(newFile(path));
224224
}
225225

226-
public static class WriteAsserter {
226+
public static final class WriteAsserter {
227227
private File file;
228228

229229
private WriteAsserter(File file) {
@@ -240,16 +240,12 @@ public File toContent(String content) {
240240
}
241241

242242
public File toContent(String content, Charset charset) {
243-
ThrowingEx.run(() -> {
244-
Files.write(file.toPath(), content.getBytes(charset));
245-
});
243+
ThrowingEx.run(() -> Files.write(file.toPath(), content.getBytes(charset)));
246244
return file;
247245
}
248246

249247
public File toResource(String path) {
250-
ThrowingEx.run(() -> {
251-
Files.write(file.toPath(), getTestResource(path).getBytes(StandardCharsets.UTF_8));
252-
});
248+
ThrowingEx.run(() -> Files.write(file.toPath(), getTestResource(path).getBytes(StandardCharsets.UTF_8)));
253249
return file;
254250
}
255251

testlib/src/main/java/com/diffplug/spotless/StepHarness.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
1515
*/
1616
package com.diffplug.spotless;
1717

18-
import static org.junit.jupiter.api.Assertions.*;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
1919

2020
import java.io.File;
2121
import java.nio.charset.StandardCharsets;
@@ -25,7 +25,7 @@
2525
import com.diffplug.selfie.StringSelfie;
2626

2727
/** An api for testing a {@code FormatterStep} that doesn't depend on the File path. DO NOT ADD FILE SUPPORT TO THIS, use {@link StepHarnessWithFile} if you need that. */
28-
public class StepHarness extends StepHarnessBase {
28+
public final class StepHarness extends StepHarnessBase {
2929
private StepHarness(Formatter formatter, RoundTrip roundTrip) {
3030
super(formatter, roundTrip);
3131
}

testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.diffplug.spotless;
1717

18-
import static org.junit.jupiter.api.Assertions.*;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
1919

2020
import java.io.File;
2121
import java.io.IOException;
@@ -26,7 +26,7 @@
2626
import com.diffplug.selfie.StringSelfie;
2727

2828
/** An api for testing a {@code FormatterStep} that depends on the File path. */
29-
public class StepHarnessWithFile extends StepHarnessBase {
29+
public final class StepHarnessWithFile extends StepHarnessBase {
3030
private final ResourceHarness harness;
3131

3232
private StepHarnessWithFile(ResourceHarness harness, Formatter formatter, RoundTrip roundTrip) {

testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ public static Provisioner mavenCentral() {
143143
return mavenCentral.get();
144144
}
145145

146-
private static final Supplier<Provisioner> mavenCentral = Suppliers.memoize(() -> {
147-
return caching("mavenCentral", () -> createWithRepositories(repo -> repo.mavenCentral()));
148-
});
146+
private static final Supplier<Provisioner> mavenCentral = Suppliers.memoize(() -> caching("mavenCentral", () -> createWithRepositories(repo -> repo.mavenCentral())));
149147

150148
/** Creates a Provisioner for the local maven repo for development purpose. */
151149
public static Provisioner mavenLocal() {
@@ -159,9 +157,5 @@ public static Provisioner snapshots() {
159157
return snapshots.get();
160158
}
161159

162-
private static final Supplier<Provisioner> snapshots = () -> createWithRepositories(repo -> {
163-
repo.maven(setup -> {
164-
setup.setUrl("https://oss.sonatype.org/content/repositories/snapshots");
165-
});
166-
});
160+
private static final Supplier<Provisioner> snapshots = () -> createWithRepositories(repo -> repo.maven(setup -> setup.setUrl("https://oss.sonatype.org/content/repositories/snapshots")));
167161
}

testlib/src/test/java/com/diffplug/spotless/JvmTest.java

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void initialize() {
4242

4343
@Test
4444
void supportAdd() {
45-
Integer differentVersions[] = {0, 1, 2};
45+
Integer[] differentVersions = {0, 1, 2};
4646
Arrays.asList(differentVersions).forEach(v -> testSupport.add(v + Jvm.version(), v.toString()));
4747
Arrays.asList(differentVersions).forEach(v -> assertThat(testSupport.toString()).contains("Version %d".formatted(v)));
4848
assertThat(testSupport.toString()).contains("%s alternatives".formatted(TEST_NAME));
@@ -51,9 +51,7 @@ void supportAdd() {
5151
@ParameterizedTest(name = "{index} {1}")
5252
@MethodSource
5353
void supportAddFailsFor(Consumer<Jvm.Support<String>> configuration, String nameNotUsed) {
54-
assertThrows(IllegalArgumentException.class, () -> {
55-
configuration.accept(testSupport);
56-
});
54+
assertThrows(IllegalArgumentException.class, () -> configuration.accept(testSupport));
5755
}
5856

5957
private static Stream<Arguments> supportAddFailsFor() {
@@ -76,11 +74,9 @@ void supportEmptyConfiguration() {
7674
testSupport.assertFormatterSupported("0.1");
7775

7876
Exception expected = new Exception("Some test exception");
79-
Exception actual = assertThrows(Exception.class, () -> {
80-
testSupport.suggestLaterVersionOnError("0.0", unused -> {
81-
throw expected;
82-
}).apply("");
83-
});
77+
Exception actual = assertThrows(Exception.class, () -> testSupport.suggestLaterVersionOnError("0.0", unused -> {
78+
throw expected;
79+
}).apply(""));
8480
assertEquals(expected, actual);
8581
}
8682

@@ -94,34 +90,26 @@ void supportListsMinimumJvmIfOnlyHigherJvmSupported() {
9490
assertNull(testSupport.getRecommendedFormatterVersion(), "No formatter version is supported");
9591

9692
for (String fmtVersion : Arrays.asList("1.2", "1.2.3", "1.2-SNAPSHOT", "1.2.3-SNAPSHOT")) {
97-
String proposal = assertThrows(Lint.ShortcutException.class, () -> {
98-
testSupport.assertFormatterSupported(fmtVersion);
99-
}).getLints().get(0).getDetail();
93+
String proposal = assertThrows(Lint.ShortcutException.class, () -> testSupport.assertFormatterSupported(fmtVersion)).getLints().get(0).getDetail();
10094
assertThat(proposal).contains(String.format("on JVM %d", Jvm.version()));
10195
assertThat(proposal).contains("%s %s requires JVM %d+".formatted(TEST_NAME, fmtVersion, higherJvmVersion));
10296
assertThat(proposal).contains("try %s alternatives".formatted(TEST_NAME));
10397

104-
proposal = assertThrows(Exception.class, () -> {
105-
testSupport.suggestLaterVersionOnError(fmtVersion, unused -> {
106-
throw testException;
107-
}).apply("");
108-
}).getMessage();
98+
proposal = assertThrows(Exception.class, () -> testSupport.suggestLaterVersionOnError(fmtVersion, unused -> {
99+
throw testException;
100+
}).apply("")).getMessage();
109101
assertThat(proposal).contains(String.format("on JVM %d", Jvm.version()));
110102
assertThat(proposal).contains("%s %s requires JVM %d+".formatted(TEST_NAME, fmtVersion, higherJvmVersion));
111103
assertThat(proposal).contains("try %s alternatives".formatted(TEST_NAME));
112104
}
113105

114106
for (String fmtVersion : Arrays.asList("1.2.4", "2", "1.2.5-SNAPSHOT")) {
115-
String proposal = assertThrows(Lint.ShortcutException.class, () -> {
116-
testSupport.assertFormatterSupported(fmtVersion);
117-
}).getLints().get(0).getDetail();
107+
String proposal = assertThrows(Lint.ShortcutException.class, () -> testSupport.assertFormatterSupported(fmtVersion)).getLints().get(0).getDetail();
118108
assertThat(proposal).contains("%s %s requires JVM %d+".formatted(TEST_NAME, fmtVersion, higherJvmVersion + 1));
119109

120-
proposal = assertThrows(Exception.class, () -> {
121-
testSupport.suggestLaterVersionOnError(fmtVersion, unused -> {
122-
throw testException;
123-
}).apply("");
124-
}).getMessage();
110+
proposal = assertThrows(Exception.class, () -> testSupport.suggestLaterVersionOnError(fmtVersion, unused -> {
111+
throw testException;
112+
}).apply("")).getMessage();
125113
assertThat(proposal).contains("%s %s requires JVM %d+".formatted(TEST_NAME, fmtVersion, higherJvmVersion + 1));
126114
}
127115
}
@@ -135,11 +123,9 @@ void supportProposesFormatterUpgrade() {
135123
for (String fmtVersion : Arrays.asList("0", "1", "1.9", "1.9-SNAPSHOT")) {
136124
testSupport.assertFormatterSupported(fmtVersion);
137125

138-
String proposal = assertThrows(Exception.class, () -> {
139-
testSupport.suggestLaterVersionOnError(fmtVersion, unused -> {
140-
throw new Exception("Some test exception");
141-
}).apply("");
142-
}).getMessage();
126+
String proposal = assertThrows(Exception.class, () -> testSupport.suggestLaterVersionOnError(fmtVersion, unused -> {
127+
throw new Exception("Some test exception");
128+
}).apply("")).getMessage();
143129
assertThat(proposal.replace("\r", "")).isEqualTo("My Test Formatter " + fmtVersion + " is currently being used, but outdated.\n" +
144130
"My Test Formatter 2 is the recommended version, which may have fixed this problem.\n" +
145131
"My Test Formatter 2 requires JVM " + requiredJvm + "+.");
@@ -153,11 +139,9 @@ void supportProposesJvmUpgrade() {
153139
testSupport.add(higherJvm, "2");
154140
testSupport.add(higherJvm + 1, "3");
155141
for (String fmtVersion : Arrays.asList("1", "1.0")) {
156-
String proposal = assertThrows(Exception.class, () -> {
157-
testSupport.suggestLaterVersionOnError(fmtVersion, unused -> {
158-
throw new Exception("Some test exception");
159-
}).apply("");
160-
}).getMessage();
142+
String proposal = assertThrows(Exception.class, () -> testSupport.suggestLaterVersionOnError(fmtVersion, unused -> {
143+
throw new Exception("Some test exception");
144+
}).apply("")).getMessage();
161145
assertThat(proposal).contains(String.format("on JVM %d", Jvm.version()));
162146
assertThat(proposal).contains("limits you to %s %s".formatted(TEST_NAME, "1"));
163147
assertThat(proposal).contains("upgrade your JVM to %d+".formatted(higherJvm));
@@ -172,11 +156,9 @@ void supportAllowsExperimentalVersions() {
172156
testSupport.assertFormatterSupported(fmtVersion);
173157

174158
Exception testException = new Exception("Some test exception");
175-
Exception exception = assertThrows(Exception.class, () -> {
176-
testSupport.suggestLaterVersionOnError(fmtVersion, unused -> {
177-
throw testException;
178-
}).apply("");
179-
});
159+
Exception exception = assertThrows(Exception.class, () -> testSupport.suggestLaterVersionOnError(fmtVersion, unused -> {
160+
throw testException;
161+
}).apply(""));
180162
assertEquals(testException, exception);
181163
}
182164
}

testlib/src/test/java/com/diffplug/spotless/generic/IdeaStepTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void configureFile() throws Exception {
104104
"formatting was applied to clean file");
105105
}
106106

107-
private File buildDir = null;
107+
private File buildDir;
108108

109109
protected File buildDir() {
110110
if (this.buildDir == null) {

testlib/src/test/java/com/diffplug/spotless/gherkin/GherkinUtilsStepTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void canSetIndentationLevelTo0() throws Exception {
9797
@Test
9898
public void equality() {
9999
new SerializableEqualityTester() {
100-
int spaces = 0;
100+
int spaces;
101101

102102
@Override
103103
protected void setupTest(API api) {

testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void equality() throws Exception {
138138
new SerializableEqualityTester() {
139139
String version = "1.10.0";
140140
String style = "";
141-
boolean reflowLongStrings = false;
141+
boolean reflowLongStrings;
142142

143143
@Override
144144
protected void setupTest(API api) {
@@ -170,7 +170,7 @@ void equalityGroupArtifact() throws Exception {
170170
String groupArtifact = GoogleJavaFormatStep.defaultGroupArtifact();
171171
String version = "1.11.0";
172172
String style = "";
173-
boolean reflowLongStrings = false;
173+
boolean reflowLongStrings;
174174

175175
@Override
176176
protected void setupTest(API api) {

testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void equality() {
7272
new SerializableEqualityTester() {
7373
String version = "1.1.0";
7474
String style = "";
75-
boolean formatJavadoc = false;
75+
boolean formatJavadoc;
7676

7777
@Override
7878
protected void setupTest(API api) {

testlib/src/test/java/com/diffplug/spotless/json/JsonFormatterStepCommonTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void canSetIndentationLevelTo0() throws Exception {
7575
@Test
7676
void equality() {
7777
new SerializableEqualityTester() {
78-
int spaces = 0;
78+
int spaces;
7979

8080
@Override
8181
protected void setupTest(API api) {

0 commit comments

Comments
 (0)