Skip to content

Commit 9c0fab9

Browse files
author
Vincent Potucek
committed
[openrewrite] exclude testlib/src/main/resources
1 parent cd4ec59 commit 9c0fab9

22 files changed

+126
-100
lines changed

gradle/rewrite.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ rewrite {
1414
'**package-info.java',
1515
'**plugin-maven/build.gradle',
1616
'**settings.gradle',
17-
'**special-tests.gradle'
17+
'**special-tests.gradle',
18+
'**testlib/src/main/resources**'
1819
)
1920
exportDatatables = true
2021
failOnDryRunResults = true

lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokensParser.java

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,31 +71,35 @@ private static boolean isDigit(final char argChar) {
7171
}
7272

7373
private static boolean isSymbol(final char argChar) {
74-
// double quote
75-
// question mark
76-
// percent
77-
// ampersand
78-
// quote
79-
// left paren
80-
// right paren
81-
// vertical bar
82-
// asterisk
83-
// plus sign
84-
// comma
85-
// minus sign
86-
// period
87-
// solidus
88-
// colon
89-
// semicolon
90-
// less than operator
91-
// equals operator
92-
// greater than operator
93-
// greater than operator
94-
// greater than operator
95-
// apos
96-
// bracket open
97-
// bracket close
98-
return switch(argChar){case'"','?','%','&','\'','(',')','|','*','+',',','-','.','/',':',';','<','=','>','!','~','`','[',']'->true;default->false;};
74+
switch (argChar) {
75+
case '"': // double quote
76+
case '?': // question mark
77+
case '%': // percent
78+
case '&': // ampersand
79+
case '\'': // quote
80+
case '(': // left paren
81+
case ')': // right paren
82+
case '|': // vertical bar
83+
case '*': // asterisk
84+
case '+': // plus sign
85+
case ',': // comma
86+
case '-': // minus sign
87+
case '.': // period
88+
case '/': // solidus
89+
case ':': // colon
90+
case ';': // semicolon
91+
case '<': // less than operator
92+
case '=': // equals operator
93+
case '>': // greater than operator
94+
case '!': // greater than operator
95+
case '~': // greater than operator
96+
case '`': // apos
97+
case '[': // bracket open
98+
case ']': // bracket close
99+
return true;
100+
default:
101+
return false;
102+
}
99103
}
100104

101105
private FormatterToken nextToken() {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2025 DiffPlug
2+
* Copyright 2016 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.
@@ -27,7 +27,7 @@
2727
* just copy-paste these methods where you need
2828
* them.
2929
*/
30-
public final class ReflectionUtil {
30+
public class ReflectionUtil {
3131
public static void dumpAllInfo(String name, Object obj) {
3232
System.out.println(name + " of type " + obj.getClass());
3333
for (Method method : obj.getClass().getMethods()) {
@@ -50,6 +50,4 @@ public static void dumpMethod(Method method) {
5050
}
5151
System.out.println(")");
5252
}
53-
54-
private ReflectionUtil() {}
5553
}

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

Lines changed: 8 additions & 4 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 final class ReadAsserter {
181+
public static 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 final class WriteAsserter {
226+
public static class WriteAsserter {
227227
private File file;
228228

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

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

247249
public File toResource(String path) {
248-
ThrowingEx.run(() -> Files.write(file.toPath(), getTestResource(path).getBytes(StandardCharsets.UTF_8)));
250+
ThrowingEx.run(() -> {
251+
Files.write(file.toPath(), getTestResource(path).getBytes(StandardCharsets.UTF_8));
252+
});
249253
return file;
250254
}
251255

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-2025 DiffPlug
2+
* Copyright 2016-2024 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.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.*;
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 final class StepHarness extends StepHarnessBase {
28+
public 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.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.*;
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 final class StepHarnessWithFile extends StepHarnessBase {
29+
public 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: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import com.diffplug.common.collect.ImmutableSet;
4343
import com.diffplug.common.io.Files;
4444

45-
public final class TestProvisioner {
45+
public class TestProvisioner {
4646
public static Project gradleProject(File dir) {
4747
File userHome = new File(StandardSystemProperty.USER_HOME.value());
4848
return ProjectBuilder.builder()
@@ -143,7 +143,9 @@ public static Provisioner mavenCentral() {
143143
return mavenCentral.get();
144144
}
145145

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

148150
/** Creates a Provisioner for the local maven repo for development purpose. */
149151
public static Provisioner mavenLocal() {
@@ -157,7 +159,9 @@ public static Provisioner snapshots() {
157159
return snapshots.get();
158160
}
159161

160-
private static final Supplier<Provisioner> snapshots = () -> createWithRepositories(repo -> repo.maven(setup -> setup.setUrl("https://oss.sonatype.org/content/repositories/snapshots")));
161-
162-
private TestProvisioner() {}
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+
});
163167
}

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

Lines changed: 43 additions & 25 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,7 +51,9 @@ void supportAdd() {
5151
@ParameterizedTest(name = "{index} {1}")
5252
@MethodSource
5353
void supportAddFailsFor(Consumer<Jvm.Support<String>> configuration, String nameNotUsed) {
54-
assertThrows(IllegalArgumentException.class, () -> configuration.accept(testSupport));
54+
assertThrows(IllegalArgumentException.class, () -> {
55+
configuration.accept(testSupport);
56+
});
5557
}
5658

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

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

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

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

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

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

110-
proposal = assertThrows(Exception.class, () -> testSupport.suggestLaterVersionOnError(fmtVersion, unused -> {
111-
throw testException;
112-
}).apply("")).getMessage();
120+
proposal = assertThrows(Exception.class, () -> {
121+
testSupport.suggestLaterVersionOnError(fmtVersion, unused -> {
122+
throw testException;
123+
}).apply("");
124+
}).getMessage();
113125
assertThat(proposal).contains("%s %s requires JVM %d+".formatted(TEST_NAME, fmtVersion, higherJvmVersion + 1));
114126
}
115127
}
@@ -123,12 +135,14 @@ void supportProposesFormatterUpgrade() {
123135
for (String fmtVersion : Arrays.asList("0", "1", "1.9", "1.9-SNAPSHOT")) {
124136
testSupport.assertFormatterSupported(fmtVersion);
125137

126-
String proposal = assertThrows(Exception.class, () -> testSupport.suggestLaterVersionOnError(fmtVersion, unused -> {
127-
throw new Exception("Some test exception");
128-
}).apply("")).getMessage();
129-
assertThat(proposal.replace("\r", "")).isEqualTo("My Test Formatter " + fmtVersion + " is currently being used, but outdated.\n"
130-
+ "My Test Formatter 2 is the recommended version, which may have fixed this problem.\n"
131-
+ "My Test Formatter 2 requires JVM " + requiredJvm + "+.");
138+
String proposal = assertThrows(Exception.class, () -> {
139+
testSupport.suggestLaterVersionOnError(fmtVersion, unused -> {
140+
throw new Exception("Some test exception");
141+
}).apply("");
142+
}).getMessage();
143+
assertThat(proposal.replace("\r", "")).isEqualTo("My Test Formatter " + fmtVersion + " is currently being used, but outdated.\n" +
144+
"My Test Formatter 2 is the recommended version, which may have fixed this problem.\n" +
145+
"My Test Formatter 2 requires JVM " + requiredJvm + "+.");
132146
}
133147
}
134148

@@ -139,9 +153,11 @@ void supportProposesJvmUpgrade() {
139153
testSupport.add(higherJvm, "2");
140154
testSupport.add(higherJvm + 1, "3");
141155
for (String fmtVersion : Arrays.asList("1", "1.0")) {
142-
String proposal = assertThrows(Exception.class, () -> testSupport.suggestLaterVersionOnError(fmtVersion, unused -> {
143-
throw new Exception("Some test exception");
144-
}).apply("")).getMessage();
156+
String proposal = assertThrows(Exception.class, () -> {
157+
testSupport.suggestLaterVersionOnError(fmtVersion, unused -> {
158+
throw new Exception("Some test exception");
159+
}).apply("");
160+
}).getMessage();
145161
assertThat(proposal).contains(String.format("on JVM %d", Jvm.version()));
146162
assertThat(proposal).contains("limits you to %s %s".formatted(TEST_NAME, "1"));
147163
assertThat(proposal).contains("upgrade your JVM to %d+".formatted(higherJvm));
@@ -156,9 +172,11 @@ void supportAllowsExperimentalVersions() {
156172
testSupport.assertFormatterSupported(fmtVersion);
157173

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2025 DiffPlug
2+
* Copyright 2016-2024 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.
@@ -116,7 +116,7 @@ void diverging() throws IOException {
116116
void cycleOrder() {
117117
BiConsumer<String, String> testCase = (unorderedStr, canonical) -> {
118118
List<String> unordered = Arrays.asList(unorderedStr.split(","));
119-
for (int i = 0; i < unordered.size(); i++) {
119+
for (int i = 0; i < unordered.size(); ++i) {
120120
// try every rotation of the list
121121
Collections.rotate(unordered, 1);
122122
PaddedCell result = CYCLE.create(rootFolder, unordered);

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;
107+
private File buildDir = null;
108108

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

0 commit comments

Comments
 (0)