Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ void testWithCustomMaxWidthDefaultStyleKtfmt() throws IOException {
}

private void checkKtlintOfficialStyle() throws IOException {
String path = "src/main/kotlin/Main.kt";
setFile(path).toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty");
testPath = "src/main/kotlin/Main.kt";
setFile(testPath).toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty");
gradleRunner().withArguments("spotlessApply").build();
assertFile(path).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean");
assertFile(testPath).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 DiffPlug
* Copyright 2016-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,10 +38,9 @@ void testSingleDependencyIncludingTransitives() throws Exception {
}

private void assertResolveDependenciesWorks() throws Exception {
String path = "src/main/java/test.java";
String unformattedContent = "package a;";
setFile(path).toContent(unformattedContent);
setFile(testPath).toContent(unformattedContent);
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).hasContent(unformattedContent.replace(" ", " "));
assertFile(testPath).hasContent(unformattedContent.replace(" ", " "));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,9 +46,9 @@ void applyUsingDefaultVersionSelfclosing() throws Exception {
}

private void runTest() throws Exception {
String path = "src/main/antlr4/Hello.g4";
setFile(path).toResource("antlr4/Hello.unformatted.g4");
testPath = "src/main/antlr4/Hello.g4";
setFile(testPath).toResource("antlr4/Hello.unformatted.g4");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).sameAsResource("antlr4/Hello.formatted.g4");
assertFile(testPath).sameAsResource("antlr4/Hello.formatted.g4");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,9 +48,8 @@ private void runToSpacesTest() throws Exception {
}

private void runTest(String source, String target) throws Exception {
String path = "src/main/java/test.java";
setFile(path).toResource(source);
setFile(testPath).toResource(source);
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).sameAsResource(target);
assertFile(testPath).sameAsResource(target);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 DiffPlug
* Copyright 2021-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -51,9 +51,8 @@ public void groovyFromJarState() throws Exception {
}

private void runTest(String sourceContent, String targetContent) throws Exception {
String path = "src/main/java/test.java";
setFile(path).toContent(sourceContent);
setFile(testPath).toContent(sourceContent);
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).hasContent(targetContent);
assertFile(testPath).hasContent(targetContent);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,11 +44,11 @@ void fromContentCpp() throws Exception {
" </content>",
"</licenseHeader>");

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

@Test
Expand All @@ -61,10 +61,10 @@ void fromContentGroovy() throws Exception {
" </content>",
"</licenseHeader>");

String path = "src/main/groovy/test.groovy";
setFile(path).toResource("license/MissingLicense.test");
testPath = "src/main/groovy/test.groovy";
setFile(testPath).toResource("license/MissingLicense.test");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).sameAsResource("license/HasLicense.test");
assertFile(testPath).sameAsResource("license/HasLicense.test");
}

@Test
Expand Down Expand Up @@ -123,12 +123,12 @@ void fromContentKotlin() throws Exception {
" </content>",
"</licenseHeader>");

String path = "src/main/kotlin/test.kt";
testPath = "src/main/kotlin/test.kt";
String noLicenseHeader = getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test");

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

@Test
Expand All @@ -142,10 +142,9 @@ void unsupportedModuleInfo() throws Exception {
}

private void runTest() throws Exception {
String path = "src/main/java/test.java";
setFile(path).toResource("license/MissingLicense.test");
setFile(testPath).toResource("license/MissingLicense.test");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).sameAsResource("license/HasLicense.test");
assertFile(testPath).sameAsResource("license/HasLicense.test");
}

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

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

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

// file should remain the same
assertFile(path).sameAsResource("license/" + file + ".test");
assertFile(testPath).sameAsResource("license/" + file + ".test");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,10 +44,9 @@ private void runToUnixTest() throws Exception {
}

private void runTest(String sourceContent, String targetContent) throws Exception {
String path = "src/main/java/test.java";
setFile(path).toContent(sourceContent);
setFile(testPath).toContent(sourceContent);
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).hasContent(targetContent);
assertFile(testPath).hasContent(targetContent);
}

private String getClassWithLineEndings(String lineEnding) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 DiffPlug
* Copyright 2021-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,9 +41,8 @@ public void fromStdInToStdOut() throws Exception {
}

private void runTest(String sourceContent, String targetContent) throws Exception {
String path = "src/main/java/test.java";
setFile(path).toContent(sourceContent);
setFile(testPath).toContent(sourceContent);
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).hasContent(targetContent);
assertFile(testPath).hasContent(targetContent);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,9 +34,8 @@ void fromContent() throws Exception {
}

private void runTest(String sourceContent, String targetContent) throws Exception {
String path = "src/main/java/test.java";
setFile(path).toContent(sourceContent);
setFile(testPath).toContent(sourceContent);
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).hasContent(targetContent);
assertFile(testPath).hasContent(targetContent);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,9 +33,8 @@ void fromContent() throws Exception {
}

private void runTest(String sourceContent, String targetContent) throws Exception {
String path = "src/main/java/test.java";
setFile(path).toContent(sourceContent);
setFile(testPath).toContent(sourceContent);
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).hasContent(targetContent);
assertFile(testPath).hasContent(targetContent);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,10 +32,9 @@ void fromContentToTabs() throws Exception {
}

private void runTest(String sourceContent, String targetContent) throws Exception {
String path = "src/main/java/test.java";
setFile(path).toContent(sourceContent);
setFile(testPath).toContent(sourceContent);
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).hasContent(targetContent);
assertFile(testPath).hasContent(targetContent);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 DiffPlug
* Copyright 2020-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,10 +27,10 @@ class GrEclipseTest extends MavenIntegrationHarness {
void testEclipse() throws Exception {
writePomWithGrEclipse();

String path = "src/main/groovy/test.groovy";
setFile(path).toResource("groovy/greclipse/format/unformatted.test");
testPath = "src/main/groovy/test.groovy";
setFile(testPath).toResource("groovy/greclipse/format/unformatted.test");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).sameAsResource("groovy/greclipse/format/formatted.test");
assertFile(testPath).sameAsResource("groovy/greclipse/format/formatted.test");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2021 DiffPlug
* Copyright 2020-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,9 +50,9 @@ private void runTest() throws Exception {
}

private void runTest(String expectedResource) throws Exception {
String path = "src/main/groovy/test.groovy";
setFile(path).toResource("java/importsorter/GroovyCodeUnsortedMisplacedImports.test");
testPath = "src/main/groovy/test.groovy";
setFile(testPath).toResource("java/importsorter/GroovyCodeUnsortedMisplacedImports.test");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).sameAsResource(expectedResource);
assertFile(testPath).sameAsResource(expectedResource);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 DiffPlug
* Copyright 2023-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,16 +37,16 @@ void testNotRemoveSemicolonsString() throws Exception {
void testRemoveSemicolons() throws Exception {
writePomWithGroovySteps("<removeSemicolons/>");

String path = "src/main/groovy/test.groovy";
setFile(path).toResource("groovy/removeSemicolons/GroovyCodeWithSemicolons.test");
testPath = "src/main/groovy/test.groovy";
setFile(testPath).toResource("groovy/removeSemicolons/GroovyCodeWithSemicolons.test");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).sameAsResource("groovy/removeSemicolons/GroovyCodeWithSemicolonsFormatted.test");
assertFile(testPath).sameAsResource("groovy/removeSemicolons/GroovyCodeWithSemicolonsFormatted.test");
}

private void runTest(String sourceContent, String targetContent) throws Exception {
String path = "src/main/groovy/test.groovy";
setFile(path).toContent(sourceContent);
testPath = "src/main/groovy/test.groovy";
setFile(testPath).toContent(sourceContent);
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).hasContent(targetContent);
assertFile(testPath).hasContent(targetContent);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 DiffPlug
* Copyright 2021-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -246,8 +246,8 @@ private List<File> writeUnformattedFiles(int count) throws IOException {
private List<File> writeFiles(String resource, String suffix, int count) throws IOException {
List<File> result = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
String path = "src/main/java/test_" + suffix + "_" + i + ".java";
File file = setFile(path).toResource(resource);
testPath = "src/main/java/test_" + suffix + "_" + i + ".java";
File file = setFile(testPath).toResource(resource);
result.add(file);
}
return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 DiffPlug
* Copyright 2022-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -101,10 +101,9 @@ void testIncludeOnlyLiteralsFirstInComparisons() throws Exception {
}

private void runTest(String dirtyPath, String cleanPath) throws Exception {
String path = "src/main/java/test.java";
setFile(path).toResource("java/cleanthat/" + dirtyPath);
setFile(testPath).toResource("java/cleanthat/" + dirtyPath);
// .withRemoteDebug(21654)
Assertions.assertThat(mavenRunner().withArguments("spotless:apply").runNoError().stdOutUtf8()).doesNotContain("[ERROR]");
assertFile(path).sameAsResource("java/cleanthat/" + cleanPath);
assertFile(testPath).sameAsResource("java/cleanthat/" + cleanPath);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,9 +29,9 @@ void testEclipse() throws Exception {
"</eclipse>");
setFile("formatter.xml").toResource("java/eclipse/formatter.xml");

String path = "src/main/java/test.java";
setFile(path).toResource("java/eclipse/JavaCodeUnformatted.test");
testPath = "src/main/java/test.java";
setFile(testPath).toResource("java/eclipse/JavaCodeUnformatted.test");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).sameAsResource("java/eclipse/JavaCodeFormatted.test");
assertFile(testPath).sameAsResource("java/eclipse/JavaCodeFormatted.test");
}
}
Loading
Loading