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
@@ -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 @@ -49,7 +49,7 @@ void noConfigOnHelp() throws IOException {
"tasks.named('check').configure {",
" dependsOn(canary)",
"}");
setFile("src/main/java/test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test");
setFile(TEST_PATH).toResource("java/googlejavaformat/JavaCodeUnformatted.test");

String help = gradleRunner().withArguments("help").build().getOutput();
Assertions.assertThat(help).doesNotContain("Canary was configured");
Expand Down
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 @@ -53,13 +53,13 @@ private void testIncludeExcludeOption(boolean excludeJava) throws IOException {

String withoutHeader = getTestResource("groovy/licenseheader/JavaCodeWithoutHeader.test");

setFile("src/main/java/test.java").toContent(withoutHeader);
setFile(TEST_PATH).toContent(withoutHeader);
setFile("src/main/groovy/test.java").toContent(withoutHeader);
setFile("src/main/groovy/test.groovy").toContent(withoutHeader);

gradleRunner().withArguments("spotlessApply").build();

assertFile("src/main/java/test.java").hasContent(withoutHeader);
assertFile(TEST_PATH).hasContent(withoutHeader);
assertFile("src/main/groovy/test.groovy").hasContent(HEADER + "\n" + withoutHeader);
if (excludeJava) {
assertFile("src/main/groovy/test.java").hasContent(withoutHeader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ void integration() throws IOException {
" googleJavaFormat()",
" }",
"}");
setFile("src/main/java/test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test");
setFile(TEST_PATH).toResource("java/googlejavaformat/JavaCodeUnformatted.test");
setFile("src/main/groovy/test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test");
setFile("src/main/groovy/test.groovy").toResource("java/googlejavaformat/JavaCodeUnformatted.test");

gradleRunner().withArguments("spotlessApply").build();

assertFile("src/main/java/test.java").sameAsResource("java/googlejavaformat/JavaCodeFormatted.test");
assertFile(TEST_PATH).sameAsResource("java/googlejavaformat/JavaCodeFormatted.test");
assertFile("src/main/groovy/test.java").sameAsResource("java/googlejavaformat/JavaCodeFormatted.test");
assertFile("src/main/groovy/test.groovy").sameAsResource("java/googlejavaformat/JavaCodeUnformatted.test");
}
Expand Down Expand Up @@ -76,9 +76,9 @@ void removeUnusedImportsWithCleanthat() throws IOException {
" java { removeUnusedImports('cleanthat-javaparser-unnecessaryimport') }",
"}");

setFile("src/main/java/test.java").toResource("java/removeunusedimports/Jdk17TextBlockUnformatted.test");
setFile(TEST_PATH).toResource("java/removeunusedimports/Jdk17TextBlockUnformatted.test");
gradleRunner().withArguments("spotlessApply").build();
assertFile("src/main/java/test.java").sameAsResource("java/removeunusedimports/Jdk17TextBlockFormatted.test");
assertFile(TEST_PATH).sameAsResource("java/removeunusedimports/Jdk17TextBlockFormatted.test");
}

@Test
Expand Down Expand Up @@ -122,9 +122,9 @@ void fenceWithTargetExcludeNoMatch() throws Exception {
" }",
"}");

setFile("src/main/java/test.java").toResource("java/targetExclude/TargetExcludeNoMatchUnformatted.test");
setFile(TEST_PATH).toResource("java/targetExclude/TargetExcludeNoMatchUnformatted.test");
gradleRunner().withArguments("spotlessApply").build();
assertFile("src/main/java/test.java").sameAsResource("java/targetExclude/TargetExcludeNoMatchFormatted.test");
assertFile(TEST_PATH).sameAsResource("java/targetExclude/TargetExcludeNoMatchFormatted.test");
}

/**
Expand All @@ -148,8 +148,8 @@ void fenceWithTargetExcludeMatch() throws Exception {
" }",
"}");

setFile("src/main/java/test.java").toResource("java/targetExclude/TargetExcludeMatch.test");
setFile(TEST_PATH).toResource("java/targetExclude/TargetExcludeMatch.test");
gradleRunner().withArguments("spotlessApply").build();
assertFile("src/main/java/test.java").sameAsResource("java/targetExclude/TargetExcludeMatch.test");
assertFile(TEST_PATH).sameAsResource("java/targetExclude/TargetExcludeMatch.test");
}
}
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(TEST_PATH).toContent(unformattedContent);
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).hasContent(unformattedContent.replace(" ", " "));
assertFile(TEST_PATH).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 @@ -34,8 +34,8 @@ private void runTest() throws Exception {
String notFormatted = "<a><b> c</b></a>";
String formatted = "<a>\n\t<b> c</b>\n</a>";
//writePomWithFormatSteps includes java. WTP does not care about file extensions.
setFile("src/main/java/test.java").toContent(notFormatted);
setFile(TEST_PATH).toContent(notFormatted);
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile("src/main/java/test.java").hasContent(formatted);
assertFile(TEST_PATH).hasContent(formatted);
}
}
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 @@ -39,8 +39,8 @@ void fromContentWithSelfclosingTag() throws Exception {
private void runTest() throws Exception {
String noTrailingNewline = "public class Java {}";
String hasTrailingNewline = noTrailingNewline + "\n";
setFile("src/main/java/test.java").toContent(noTrailingNewline);
setFile(TEST_PATH).toContent(noTrailingNewline);
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile("src/main/java/test.java").hasContent(hasTrailingNewline);
assertFile(TEST_PATH).hasContent(hasTrailingNewline);
}
}
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(TEST_PATH).toResource(source);
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).sameAsResource(target);
assertFile(TEST_PATH).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(TEST_PATH).toContent(sourceContent);
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).hasContent(targetContent);
assertFile(TEST_PATH).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 @@ -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(TEST_PATH).toResource("license/MissingLicense.test");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).sameAsResource("license/HasLicense.test");
assertFile(TEST_PATH).sameAsResource("license/HasLicense.test");
}

private void testUnsupportedFile(String file) throws Exception {
Expand Down
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(TEST_PATH).toContent(sourceContent);
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).hasContent(targetContent);
assertFile(TEST_PATH).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(TEST_PATH).toContent(sourceContent);
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).hasContent(targetContent);
assertFile(TEST_PATH).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(TEST_PATH).toContent(sourceContent);
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).hasContent(targetContent);
assertFile(TEST_PATH).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(TEST_PATH).toContent(sourceContent);
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).hasContent(targetContent);
assertFile(TEST_PATH).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(TEST_PATH).toContent(sourceContent);
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).hasContent(targetContent);
assertFile(TEST_PATH).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 @@ -37,9 +37,8 @@ void testEclipse() throws Exception {
void doesNotFormatJavaFiles() throws Exception {
writePomWithGrEclipse();

String javaPath = "src/main/java/test.java";
String testJavaPath = "src/test/java/test.java";
setFile(javaPath).toResource("java/googlejavaformat/JavaCodeUnformatted.test");
setFile(TEST_PATH).toResource("java/googlejavaformat/JavaCodeUnformatted.test");
setFile(testJavaPath).toResource("java/googlejavaformat/JavaCodeUnformatted.test");

String groovyPath = "src/main/groovy/test.groovy";
Expand All @@ -49,7 +48,7 @@ void doesNotFormatJavaFiles() throws Exception {

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

assertFile(javaPath).sameAsResource("java/googlejavaformat/JavaCodeUnformatted.test");
assertFile(TEST_PATH).sameAsResource("java/googlejavaformat/JavaCodeUnformatted.test");
assertFile(testJavaPath).sameAsResource("java/googlejavaformat/JavaCodeUnformatted.test");

assertFile(groovyPath).sameAsResource("groovy/greclipse/format/formatted.test");
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,8 @@ 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);
// .withRemoteDebug(21654)
setFile(TEST_PATH).toResource("java/cleanthat/" + dirtyPath);
Assertions.assertThat(mavenRunner().withArguments("spotless:apply").runNoError().stdOutUtf8()).doesNotContain("[ERROR]");
assertFile(path).sameAsResource("java/cleanthat/" + cleanPath);
assertFile(TEST_PATH).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,8 @@ 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");
setFile(TEST_PATH).toResource("java/eclipse/JavaCodeUnformatted.test");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).sameAsResource("java/eclipse/JavaCodeFormatted.test");
assertFile(TEST_PATH).sameAsResource("java/eclipse/JavaCodeFormatted.test");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 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 All @@ -25,19 +25,17 @@ class FormatAnnotationsStepTest extends MavenIntegrationHarness {
void testFormatAnnotations() throws Exception {
writePomWithJavaSteps("<formatAnnotations/>");

String path = "src/main/java/test.java";
setFile(path).toResource("java/formatannotations/FormatAnnotationsTestInput.test");
setFile(TEST_PATH).toResource("java/formatannotations/FormatAnnotationsTestInput.test");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).sameAsResource("java/formatannotations/FormatAnnotationsTestOutput.test");
assertFile(TEST_PATH).sameAsResource("java/formatannotations/FormatAnnotationsTestOutput.test");
}

@Test
void testFormatAnnotationsAccessModifiers() throws Exception {
writePomWithJavaSteps("<formatAnnotations/>");

String path = "src/main/java/test.java";
setFile(path).toResource("java/formatannotations/FormatAnnotationsAccessModifiersInput.test");
setFile(TEST_PATH).toResource("java/formatannotations/FormatAnnotationsAccessModifiersInput.test");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).sameAsResource("java/formatannotations/FormatAnnotationsAccessModifiersOutput.test");
assertFile(TEST_PATH).sameAsResource("java/formatannotations/FormatAnnotationsAccessModifiersOutput.test");
}
}
Loading
Loading