Skip to content

Commit 1e9438e

Browse files
author
Vincent Potucek
committed
use default field for default test path
1 parent 9bc702f commit 1e9438e

31 files changed

+156
-167
lines changed

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ void testWithCustomMaxWidthDefaultStyleKtfmt() throws IOException {
231231
}
232232

233233
private void checkKtlintOfficialStyle() throws IOException {
234-
String path = "src/main/kotlin/Main.kt";
235-
setFile(path).toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty");
234+
testPath = "src/main/kotlin/Main.kt";
235+
setFile(testPath).toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty");
236236
gradleRunner().withArguments("spotlessApply").build();
237-
assertFile(path).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean");
237+
assertFile(testPath).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean");
238238
}
239239
}

plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 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.
@@ -38,10 +38,9 @@ void testSingleDependencyIncludingTransitives() throws Exception {
3838
}
3939

4040
private void assertResolveDependenciesWorks() throws Exception {
41-
String path = "src/main/java/test.java";
4241
String unformattedContent = "package a;";
43-
setFile(path).toContent(unformattedContent);
42+
setFile(testPath).toContent(unformattedContent);
4443
mavenRunner().withArguments("spotless:apply").runNoError();
45-
assertFile(path).hasContent(unformattedContent.replace(" ", " "));
44+
assertFile(testPath).hasContent(unformattedContent.replace(" ", " "));
4645
}
4746
}

plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 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.
@@ -46,9 +46,9 @@ void applyUsingDefaultVersionSelfclosing() throws Exception {
4646
}
4747

4848
private void runTest() throws Exception {
49-
String path = "src/main/antlr4/Hello.g4";
50-
setFile(path).toResource("antlr4/Hello.unformatted.g4");
49+
testPath = "src/main/antlr4/Hello.g4";
50+
setFile(testPath).toResource("antlr4/Hello.unformatted.g4");
5151
mavenRunner().withArguments("spotless:apply").runNoError();
52-
assertFile(path).sameAsResource("antlr4/Hello.formatted.g4");
52+
assertFile(testPath).sameAsResource("antlr4/Hello.formatted.g4");
5353
}
5454
}

plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/IndentTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 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.
@@ -48,9 +48,8 @@ private void runToSpacesTest() throws Exception {
4848
}
4949

5050
private void runTest(String source, String target) throws Exception {
51-
String path = "src/main/java/test.java";
52-
setFile(path).toResource(source);
51+
setFile(testPath).toResource(source);
5352
mavenRunner().withArguments("spotless:apply").runNoError();
54-
assertFile(path).sameAsResource(target);
53+
assertFile(testPath).sameAsResource(target);
5554
}
5655
}

plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/Jsr223Test.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 DiffPlug
2+
* Copyright 2021-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.
@@ -51,9 +51,8 @@ public void groovyFromJarState() throws Exception {
5151
}
5252

5353
private void runTest(String sourceContent, String targetContent) throws Exception {
54-
String path = "src/main/java/test.java";
55-
setFile(path).toContent(sourceContent);
54+
setFile(testPath).toContent(sourceContent);
5655
mavenRunner().withArguments("spotless:apply").runNoError();
57-
assertFile(path).hasContent(targetContent);
56+
assertFile(testPath).hasContent(targetContent);
5857
}
5958
}

plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 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.
@@ -44,11 +44,11 @@ void fromContentCpp() throws Exception {
4444
" </content>",
4545
"</licenseHeader>");
4646

47-
String path = "src/test/cpp/file.c++";
47+
testPath = "src/test/cpp/file.c++";
4848
String cppContent = "#include <whatsoever.h>";
49-
setFile(path).toContent(cppContent);
49+
setFile(testPath).toContent(cppContent);
5050
mavenRunner().withArguments("spotless:apply").runNoError();
51-
assertFile(path).hasContent(cppLicense + '\n' + cppContent);
51+
assertFile(testPath).hasContent(cppLicense + '\n' + cppContent);
5252
}
5353

5454
@Test
@@ -61,10 +61,10 @@ void fromContentGroovy() throws Exception {
6161
" </content>",
6262
"</licenseHeader>");
6363

64-
String path = "src/main/groovy/test.groovy";
65-
setFile(path).toResource("license/MissingLicense.test");
64+
testPath = "src/main/groovy/test.groovy";
65+
setFile(testPath).toResource("license/MissingLicense.test");
6666
mavenRunner().withArguments("spotless:apply").runNoError();
67-
assertFile(path).sameAsResource("license/HasLicense.test");
67+
assertFile(testPath).sameAsResource("license/HasLicense.test");
6868
}
6969

7070
@Test
@@ -123,12 +123,12 @@ void fromContentKotlin() throws Exception {
123123
" </content>",
124124
"</licenseHeader>");
125125

126-
String path = "src/main/kotlin/test.kt";
126+
testPath = "src/main/kotlin/test.kt";
127127
String noLicenseHeader = getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test");
128128

129-
setFile(path).toContent(noLicenseHeader);
129+
setFile(testPath).toContent(noLicenseHeader);
130130
mavenRunner().withArguments("spotless:apply").runNoError();
131-
assertFile(path).hasContent(KOTLIN_LICENSE_HEADER + '\n' + noLicenseHeader);
131+
assertFile(testPath).hasContent(KOTLIN_LICENSE_HEADER + '\n' + noLicenseHeader);
132132
}
133133

134134
@Test
@@ -142,10 +142,9 @@ void unsupportedModuleInfo() throws Exception {
142142
}
143143

144144
private void runTest() throws Exception {
145-
String path = "src/main/java/test.java";
146-
setFile(path).toResource("license/MissingLicense.test");
145+
setFile(testPath).toResource("license/MissingLicense.test");
147146
mavenRunner().withArguments("spotless:apply").runNoError();
148-
assertFile(path).sameAsResource("license/HasLicense.test");
147+
assertFile(testPath).sameAsResource("license/HasLicense.test");
149148
}
150149

151150
private void testUnsupportedFile(String file) throws Exception {
@@ -156,12 +155,12 @@ private void testUnsupportedFile(String file) throws Exception {
156155
" </content>",
157156
"</licenseHeader>");
158157

159-
String path = "src/main/java/com/diffplug/spotless/" + file;
160-
setFile(path).toResource("license/" + file + ".test");
158+
testPath = "src/main/java/com/diffplug/spotless/" + file;
159+
setFile(testPath).toResource("license/" + file + ".test");
161160

162161
mavenRunner().withArguments("spotless:apply").runNoError();
163162

164163
// file should remain the same
165-
assertFile(path).sameAsResource("license/" + file + ".test");
164+
assertFile(testPath).sameAsResource("license/" + file + ".test");
166165
}
167166
}

plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LineEndingsTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 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.
@@ -44,10 +44,9 @@ private void runToUnixTest() throws Exception {
4444
}
4545

4646
private void runTest(String sourceContent, String targetContent) throws Exception {
47-
String path = "src/main/java/test.java";
48-
setFile(path).toContent(sourceContent);
47+
setFile(testPath).toContent(sourceContent);
4948
mavenRunner().withArguments("spotless:apply").runNoError();
50-
assertFile(path).hasContent(targetContent);
49+
assertFile(testPath).hasContent(targetContent);
5150
}
5251

5352
private String getClassWithLineEndings(String lineEnding) {

plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/NativeCmdTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 DiffPlug
2+
* Copyright 2021-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.
@@ -41,9 +41,8 @@ public void fromStdInToStdOut() throws Exception {
4141
}
4242

4343
private void runTest(String sourceContent, String targetContent) throws Exception {
44-
String path = "src/main/java/test.java";
45-
setFile(path).toContent(sourceContent);
44+
setFile(testPath).toContent(sourceContent);
4645
mavenRunner().withArguments("spotless:apply").runNoError();
47-
assertFile(path).hasContent(targetContent);
46+
assertFile(testPath).hasContent(targetContent);
4847
}
4948
}

plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/ReplaceRegexTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 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.
@@ -34,9 +34,8 @@ void fromContent() throws Exception {
3434
}
3535

3636
private void runTest(String sourceContent, String targetContent) throws Exception {
37-
String path = "src/main/java/test.java";
38-
setFile(path).toContent(sourceContent);
37+
setFile(testPath).toContent(sourceContent);
3938
mavenRunner().withArguments("spotless:apply").runNoError();
40-
assertFile(path).hasContent(targetContent);
39+
assertFile(testPath).hasContent(targetContent);
4140
}
4241
}

plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/ReplaceTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 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.
@@ -33,9 +33,8 @@ void fromContent() throws Exception {
3333
}
3434

3535
private void runTest(String sourceContent, String targetContent) throws Exception {
36-
String path = "src/main/java/test.java";
37-
setFile(path).toContent(sourceContent);
36+
setFile(testPath).toContent(sourceContent);
3837
mavenRunner().withArguments("spotless:apply").runNoError();
39-
assertFile(path).hasContent(targetContent);
38+
assertFile(testPath).hasContent(targetContent);
4039
}
4140
}

0 commit comments

Comments
 (0)