From 1e9438e0850f2bc2da4ff7c6e5b1ef14b67be961 Mon Sep 17 00:00:00 2001 From: Vincent Potucek Date: Wed, 23 Jul 2025 16:24:01 +0200 Subject: [PATCH] use default field for default test path --- .../gradle/spotless/KotlinExtensionTest.java | 6 ++-- .../spotless/maven/MavenProvisionerTest.java | 7 ++--- .../maven/antlr4/Antlr4FormatterTest.java | 8 ++--- .../spotless/maven/generic/IndentTest.java | 7 ++--- .../spotless/maven/generic/Jsr223Test.java | 7 ++--- .../maven/generic/LicenseHeaderTest.java | 31 +++++++++---------- .../maven/generic/LineEndingsTest.java | 7 ++--- .../spotless/maven/generic/NativeCmdTest.java | 7 ++--- .../maven/generic/ReplaceRegexTest.java | 7 ++--- .../spotless/maven/generic/ReplaceTest.java | 7 ++--- .../generic/TrimTrailingWhitespaceTest.java | 7 ++--- .../spotless/maven/groovy/GrEclipseTest.java | 8 ++--- .../maven/groovy/ImportOrderTest.java | 8 ++--- .../maven/groovy/RemoveSemicolonsTest.java | 14 ++++----- .../incremental/UpToDateCheckingTest.java | 6 ++-- .../java/CleanthatJavaRefactorerTest.java | 7 ++--- .../maven/java/EclipseFormatStepTest.java | 8 ++--- .../maven/java/FormatAnnotationsStepTest.java | 14 ++++----- .../maven/java/GoogleJavaFormatTest.java | 7 ++--- .../spotless/maven/java/ImportOrderTest.java | 7 ++--- .../maven/java/PalantirJavaFormatTest.java | 7 ++--- .../java/RemoveUnusedImportsStepTest.java | 6 ++-- .../java/RemoveWildcardImportsStepTest.java | 5 ++- .../spotless/maven/kotlin/DiktatTest.java | 20 ++++++------ .../spotless/maven/kotlin/KtlintTest.java | 18 +++++------ .../npm/NpmStepsWithNpmInstallCacheTest.java | 29 +++++++++-------- ...namicallyInstalledNpmInstallationTest.java | 8 ++--- .../prettier/PrettierFormatStepTest.java | 24 +++++++------- .../spotless/maven/scala/ScalafmtTest.java | 8 ++--- .../typescript/TypescriptFormatStepTest.java | 12 +++---- .../diffplug/spotless/ResourceHarness.java | 6 ++++ 31 files changed, 156 insertions(+), 167 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index 2132ac11e4..2bfe20847d 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -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"); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java index e1214a0d59..1eb529ace0 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java @@ -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. @@ -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(" ", " ")); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java index 4f1b1c2353..67135d9ccb 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/antlr4/Antlr4FormatterTest.java @@ -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. @@ -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"); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/IndentTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/IndentTest.java index b7558cf763..6f1954ea7f 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/IndentTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/IndentTest.java @@ -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. @@ -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); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/Jsr223Test.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/Jsr223Test.java index eb1b3b0575..ae97d1c8ef 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/Jsr223Test.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/Jsr223Test.java @@ -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. @@ -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); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java index 92d74bc659..1b32252a6b 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java @@ -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. @@ -44,11 +44,11 @@ void fromContentCpp() throws Exception { " ", ""); - String path = "src/test/cpp/file.c++"; + testPath = "src/test/cpp/file.c++"; String cppContent = "#include "; - 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 @@ -61,10 +61,10 @@ void fromContentGroovy() throws Exception { " ", ""); - 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 @@ -123,12 +123,12 @@ void fromContentKotlin() throws Exception { " ", ""); - 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 @@ -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 { @@ -156,12 +155,12 @@ private void testUnsupportedFile(String file) throws Exception { " ", ""); - 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"); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LineEndingsTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LineEndingsTest.java index 1c99234fcc..35d14aa941 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LineEndingsTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LineEndingsTest.java @@ -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. @@ -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) { diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/NativeCmdTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/NativeCmdTest.java index fe1fdd3c6e..15272a170c 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/NativeCmdTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/NativeCmdTest.java @@ -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. @@ -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); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/ReplaceRegexTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/ReplaceRegexTest.java index e3ce08b359..245dd004c7 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/ReplaceRegexTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/ReplaceRegexTest.java @@ -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. @@ -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); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/ReplaceTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/ReplaceTest.java index 466124222d..83db1e135f 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/ReplaceTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/ReplaceTest.java @@ -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. @@ -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); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/TrimTrailingWhitespaceTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/TrimTrailingWhitespaceTest.java index 8cb99f5c45..44d8ce7e49 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/TrimTrailingWhitespaceTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/TrimTrailingWhitespaceTest.java @@ -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. @@ -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); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/GrEclipseTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/GrEclipseTest.java index 34d95dc7d2..4a858e6d2e 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/GrEclipseTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/GrEclipseTest.java @@ -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. @@ -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 diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/ImportOrderTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/ImportOrderTest.java index 5cdca40d4c..bbe6e183c5 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/ImportOrderTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/ImportOrderTest.java @@ -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. @@ -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); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/RemoveSemicolonsTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/RemoveSemicolonsTest.java index fc78c87a27..5df01f4e9c 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/RemoveSemicolonsTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/RemoveSemicolonsTest.java @@ -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. @@ -37,16 +37,16 @@ void testNotRemoveSemicolonsString() throws Exception { void testRemoveSemicolons() throws Exception { writePomWithGroovySteps(""); - 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); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java index cfc17594ca..9a2227f3fb 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java @@ -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. @@ -246,8 +246,8 @@ private List writeUnformattedFiles(int count) throws IOException { private List writeFiles(String resource, String suffix, int count) throws IOException { List 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; diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java index 5f6bc2750d..bc1a9960c2 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java @@ -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. @@ -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); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/EclipseFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/EclipseFormatStepTest.java index 792a2a1382..3799a3eca5 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/EclipseFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/EclipseFormatStepTest.java @@ -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. @@ -29,9 +29,9 @@ void testEclipse() throws Exception { ""); 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"); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/FormatAnnotationsStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/FormatAnnotationsStepTest.java index 972a4b4f7f..a03213376b 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/FormatAnnotationsStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/FormatAnnotationsStepTest.java @@ -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. @@ -25,19 +25,19 @@ class FormatAnnotationsStepTest extends MavenIntegrationHarness { void testFormatAnnotations() throws Exception { writePomWithJavaSteps(""); - String path = "src/main/java/test.java"; - setFile(path).toResource("java/formatannotations/FormatAnnotationsTestInput.test"); + testPath = "src/main/java/test.java"; + setFile(testPath).toResource("java/formatannotations/FormatAnnotationsTestInput.test"); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile(path).sameAsResource("java/formatannotations/FormatAnnotationsTestOutput.test"); + assertFile(testPath).sameAsResource("java/formatannotations/FormatAnnotationsTestOutput.test"); } @Test void testFormatAnnotationsAccessModifiers() throws Exception { writePomWithJavaSteps(""); - String path = "src/main/java/test.java"; - setFile(path).toResource("java/formatannotations/FormatAnnotationsAccessModifiersInput.test"); + testPath = "src/main/java/test.java"; + setFile(testPath).toResource("java/formatannotations/FormatAnnotationsAccessModifiersInput.test"); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile(path).sameAsResource("java/formatannotations/FormatAnnotationsAccessModifiersOutput.test"); + assertFile(testPath).sameAsResource("java/formatannotations/FormatAnnotationsAccessModifiersOutput.test"); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java index 52e89e58db..858690ddb9 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java @@ -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. @@ -80,9 +80,8 @@ private void runTest(String targetResource) throws Exception { } private void runTest(String targetResource, String sourceResource) throws Exception { - String path = "src/main/java/test.java"; - setFile(path).toResource(sourceResource); + setFile(testPath).toResource(sourceResource); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile(path).sameAsResource(targetResource); + assertFile(testPath).sameAsResource(targetResource); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/ImportOrderTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/ImportOrderTest.java index 2eef48083e..323674e079 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/ImportOrderTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/ImportOrderTest.java @@ -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. @@ -59,9 +59,8 @@ private void runTest() throws Exception { } private void runTest(String expectedResource) throws Exception { - String path = "src/main/java/test.java"; - setFile(path).toResource("java/importsorter/JavaCodeUnsortedImports.test"); + setFile(testPath).toResource("java/importsorter/JavaCodeUnsortedImports.test"); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile(path).sameAsResource(expectedResource); + assertFile(testPath).sameAsResource(expectedResource); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java index eee4fab8c5..7be8c1229b 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2024 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. @@ -52,9 +52,8 @@ void formatJavaDoc() throws Exception { } private void runTest(String targetResource, String sourceResource) throws Exception { - String path = "src/main/java/test.java"; - setFile(path).toResource(sourceResource); + setFile(testPath).toResource(sourceResource); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile(path).sameAsResource(targetResource); + assertFile(testPath).sameAsResource(targetResource); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveUnusedImportsStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveUnusedImportsStepTest.java index 3689fa8f98..60f580e610 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveUnusedImportsStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveUnusedImportsStepTest.java @@ -25,9 +25,9 @@ class RemoveUnusedImportsStepTest extends MavenIntegrationHarness { void testRemoveUnusedInports() throws Exception { writePomWithJavaSteps(""); - String path = "src/main/java/test.java"; - setFile(path).toResource("java/removeunusedimports/JavaCodeWithPackageUnformatted.test"); + testPath = "src/main/java/test.java"; + setFile(testPath).toResource("java/removeunusedimports/JavaCodeWithPackageUnformatted.test"); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile(path).sameAsResource("java/removeunusedimports/JavaCodeWithPackageFormatted.test"); + assertFile(testPath).sameAsResource("java/removeunusedimports/JavaCodeWithPackageFormatted.test"); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java index 4d4ade94d0..069d7ab7da 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java @@ -25,9 +25,8 @@ class RemoveWildcardImportsStepTest extends MavenIntegrationHarness { void testRemoveWildcardImports() throws Exception { writePomWithJavaSteps(""); - String path = "src/main/java/test.java"; - setFile(path).toResource("java/removewildcardimports/JavaCodeWildcardsUnformatted.test"); + setFile(testPath).toResource("java/removewildcardimports/JavaCodeWildcardsUnformatted.test"); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile(path).sameAsResource("java/removewildcardimports/JavaCodeWildcardsFormatted.test"); + assertFile(testPath).sameAsResource("java/removewildcardimports/JavaCodeWildcardsFormatted.test"); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/DiktatTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/DiktatTest.java index dc6e59fef0..cd69a77951 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/DiktatTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/DiktatTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 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. @@ -28,10 +28,10 @@ void testDiktat() throws Exception { writePomWithKotlinSteps(""); - String path = "src/main/kotlin/Main.kt"; - setFile(path).toResource("kotlin/diktat/main.dirty"); + testPath = "src/main/kotlin/Main.kt"; + setFile(testPath).toResource("kotlin/diktat/main.dirty"); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile(path).sameAsResource("kotlin/diktat/main.clean"); + assertFile(testPath).sameAsResource("kotlin/diktat/main.clean"); } @@ -43,10 +43,10 @@ void testDiktatWithVersion() throws Exception { " 1.2.1", ""); - String path = "src/main/kotlin/Main.kt"; - setFile(path).toResource("kotlin/diktat/main.dirty"); + testPath = "src/main/kotlin/Main.kt"; + setFile(testPath).toResource("kotlin/diktat/main.dirty"); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile(path).sameAsResource("kotlin/diktat/main.clean"); + assertFile(testPath).sameAsResource("kotlin/diktat/main.clean"); } @Test @@ -60,10 +60,10 @@ void testDiktatConfig() throws Exception { " " + conf.getAbsolutePath() + "", ""); - String path = "src/main/kotlin/Main.kt"; - setFile(path).toResource("kotlin/diktat/main.dirty"); + testPath = "src/main/kotlin/Main.kt"; + setFile(testPath).toResource("kotlin/diktat/main.dirty"); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile(path).sameAsResource("kotlin/diktat/main.clean"); + assertFile(testPath).sameAsResource("kotlin/diktat/main.clean"); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java index 2e4eaee791..27155333da 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java @@ -26,10 +26,10 @@ class KtlintTest extends MavenIntegrationHarness { void testKtlint() throws Exception { writePomWithKotlinSteps(""); - String path = "src/main/kotlin/Main.kt"; - setFile(path).toResource("kotlin/ktlint/basic.dirty"); + testPath = "src/main/kotlin/Main.kt"; + setFile(testPath).toResource("kotlin/ktlint/basic.dirty"); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile(path).sameAsResource("kotlin/ktlint/basic.clean"); + assertFile(testPath).sameAsResource("kotlin/ktlint/basic.clean"); } @Test @@ -41,10 +41,10 @@ void testKtlintEditorConfigOverride() throws Exception { " \n" + ""); - 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"); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile(path).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); + assertFile(testPath).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); } @Test @@ -92,9 +92,9 @@ void testWithCustomRuleSetApply() throws Exception { } private void checkKtlintOfficialStyle() throws Exception { - 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"); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile(path).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean"); + assertFile(testPath).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean"); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmStepsWithNpmInstallCacheTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmStepsWithNpmInstallCacheTest.java index eabdd5c5fc..288f88b292 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmStepsWithNpmInstallCacheTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmStepsWithNpmInstallCacheTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 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. @@ -48,7 +48,7 @@ void prettierTypescriptWithoutCache() throws Exception { " 1.16.4", " .prettierrc.yml", ""); - Result result = run("typescript", suffix); + Result result = run(suffix); Assertions.assertThat(result.stdOutUtf8()).doesNotContain("Caching node_modules for").doesNotContain("Using cached node_modules for"); } @@ -61,7 +61,7 @@ void prettierTypescriptWithDefaultCache() throws Exception { " .prettierrc.yml", " true", ""); - Result result = run("typescript", suffix); + Result result = run(suffix); Assertions.assertThat(result.stdOutUtf8()) .contains("Caching node_modules for") .contains(SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME) @@ -78,7 +78,7 @@ void prettierTypescriptWithDefaultCacheIsReusedOnSecondRun() throws Exception { " .prettierrc.yml", " true", ""); - Result result1 = run("typescript", suffix); + Result result1 = run(suffix); Assertions.assertThat(result1.stdOutUtf8()) .contains("Caching node_modules for") .contains(SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME) @@ -87,7 +87,7 @@ void prettierTypescriptWithDefaultCacheIsReusedOnSecondRun() throws Exception { // recursively delete target folder to simulate a fresh run (except the default cache folder) recursiveDelete(Paths.get(rootFolder().getAbsolutePath(), "target"), SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME); - Result result2 = run("typescript", suffix); + Result result2 = run(suffix); Assertions.assertThat(result2.stdOutUtf8()) .doesNotContain("Caching node_modules for") .contains(SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME) @@ -104,7 +104,7 @@ void prettierTypescriptWithSpecificCache() throws Exception { " .prettierrc.yml", " " + cacheDir.getAbsolutePath() + "", ""); - Result result = run("typescript", suffix); + Result result = run(suffix); Assertions.assertThat(result.stdOutUtf8()) .contains("Caching node_modules for") .contains(Path.of(cacheDir.getAbsolutePath()).toAbsolutePath().toString()) @@ -122,7 +122,7 @@ void prettierTypescriptWithSpecificCacheIsUsedOnSecondRun() throws Exception { " .prettierrc.yml", " " + cacheDir.getAbsolutePath() + "", ""); - Result result1 = run("typescript", suffix); + Result result1 = run(suffix); Assertions.assertThat(result1.stdOutUtf8()) .contains("Caching node_modules for") .contains(Path.of(cacheDir.getAbsolutePath()).toAbsolutePath().toString()) @@ -131,7 +131,7 @@ void prettierTypescriptWithSpecificCacheIsUsedOnSecondRun() throws Exception { // recursively delete target folder to simulate a fresh run recursiveDelete(Paths.get(rootFolder().getAbsolutePath(), "target"), null); - Result result2 = run("typescript", suffix); + Result result2 = run(suffix); Assertions.assertThat(result2.stdOutUtf8()) .doesNotContain("Caching node_modules for") .contains(Path.of(cacheDir.getAbsolutePath()).toAbsolutePath().toString()) @@ -142,19 +142,18 @@ private void recursiveDelete(Path path, String exclusion) throws IOException { Files.walkFileTree(path, new RecursiveDelete(exclusion)); } - private Result run(String kind, String suffix) throws IOException, InterruptedException { - String path = prepareRun(kind, suffix); + private Result run(String suffix) throws IOException, InterruptedException { + prepareRun("typescript", suffix); Result result = mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile(path).sameAsResource("npm/prettier/filetypes/" + kind + "/" + kind + ".clean"); + assertFile(testPath).sameAsResource("npm/prettier/filetypes/" + "typescript" + "/" + "typescript" + ".clean"); return result; } - private String prepareRun(String kind, String suffix) throws IOException { + private void prepareRun(String kind, String suffix) throws IOException { String configPath = ".prettierrc.yml"; setFile(configPath).toResource("npm/prettier/filetypes/" + kind + "/" + ".prettierrc.yml"); - String path = "src/main/" + kind + "/test." + suffix; - setFile(path).toResource("npm/prettier/filetypes/" + kind + "/" + kind + ".dirty"); - return path; + testPath = "src/main/" + kind + "/test." + suffix; + setFile(testPath).toResource("npm/prettier/filetypes/" + kind + "/" + kind + ".dirty"); } private static class RecursiveDelete extends SimpleFileVisitor { diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmTestsWithDynamicallyInstalledNpmInstallationTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmTestsWithDynamicallyInstalledNpmInstallationTest.java index 78830bf09d..8bd7d4b015 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmTestsWithDynamicallyInstalledNpmInstallationTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmTestsWithDynamicallyInstalledNpmInstallationTest.java @@ -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. @@ -38,11 +38,11 @@ void useDownloadedNpmInstallation() throws Exception { String suffix = "ts"; String configPath = ".prettierrc.yml"; setFile(configPath).toResource("npm/prettier/filetypes/" + kind + "/" + ".prettierrc.yml"); - String path = "src/main/" + kind + "/test." + suffix; - setFile(path).toResource("npm/prettier/filetypes/" + kind + "/" + kind + ".dirty"); + testPath = "src/main/" + kind + "/test." + suffix; + setFile(testPath).toResource("npm/prettier/filetypes/" + kind + "/" + kind + ".dirty"); mavenRunner().withArguments(installNpmMavenGoal(), "spotless:apply").runNoError(); - assertFile(path).sameAsResource("npm/prettier/filetypes/" + kind + "/" + kind + ".clean"); + assertFile(testPath).sameAsResource("npm/prettier/filetypes/" + kind + "/" + kind + ".clean"); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java index abba35e72c..44ed60e40b 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java @@ -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. @@ -30,21 +30,19 @@ class PrettierFormatStepTest extends MavenIntegrationHarness { private void run(String kind, String suffix) throws IOException, InterruptedException { - String path = prepareRun(kind, suffix); + prepareRun(kind, suffix); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile(path).sameAsResource("npm/prettier/filetypes/" + kind + "/" + kind + ".clean"); + assertFile(testPath).sameAsResource("npm/prettier/filetypes/" + kind + "/" + kind + ".clean"); } - private String prepareRun(String kind, String suffix) throws IOException { - String configPath = ".prettierrc.yml"; - setFile(configPath).toResource("npm/prettier/filetypes/" + kind + "/" + ".prettierrc.yml"); - String path = "src/main/" + kind + "/test." + suffix; - setFile(path).toResource("npm/prettier/filetypes/" + kind + "/" + kind + ".dirty"); - return path; + private void prepareRun(String kind, String suffix) throws IOException { + setFile(".prettierrc.yml").toResource("npm/prettier/filetypes/" + kind + "/" + ".prettierrc.yml"); + testPath = "src/main/" + kind + "/test." + suffix; + setFile(testPath).toResource("npm/prettier/filetypes/" + kind + "/" + kind + ".dirty"); } - private ProcessRunner.Result runExpectingError(String kind, String suffix) throws IOException, InterruptedException { - String path = prepareRun(kind, suffix); + private ProcessRunner.Result runExpectingError(String suffix) throws IOException, InterruptedException { + prepareRun("typescript", suffix); return mavenRunner().withArguments("spotless:apply").runHasError(); } @@ -258,7 +256,7 @@ void autodetect_npmrc_file() throws Exception { " 1.16.4", " .prettierrc.yml", ""); - ProcessRunner.Result result = runExpectingError("typescript", suffix); + ProcessRunner.Result result = runExpectingError(suffix); assertThat(result.stdOutUtf8()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); } @@ -276,7 +274,7 @@ void select_configured_npmrc_file() throws Exception { " .prettierrc.yml", " ${basedir}/.custom_npmrc", ""); - ProcessRunner.Result result = runExpectingError("typescript", suffix); + ProcessRunner.Result result = runExpectingError(suffix); assertThat(result.stdOutUtf8()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/scala/ScalafmtTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/scala/ScalafmtTest.java index ef36c29d8b..74864db27b 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/scala/ScalafmtTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/scala/ScalafmtTest.java @@ -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. @@ -40,9 +40,9 @@ void testScalafmtWithCustomConfig() throws Exception { } private void runTest(String s) throws Exception { - String path = "src/main/scala/test.scala"; - setFile(path).toResource("scala/scalafmt/basic.dirty"); + testPath = "src/main/scala/test.scala"; + setFile(testPath).toResource("scala/scalafmt/basic.dirty"); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile(path).sameAsResource(s); + assertFile(testPath).sameAsResource(s); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java index afda22e06b..ce37d6c534 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2024 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. @@ -39,9 +39,9 @@ private static String styleGuideDevDependenciesString(String styleGuideName) { } private void runTsfmt(String kind) throws IOException, InterruptedException { - String path = prepareRunTsfmt(kind); + prepareRunTsfmt(kind); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile(path).sameAsResource("npm/tsfmt/" + kind + "/" + kind + ".clean"); + assertFile(testPath).sameAsResource("npm/tsfmt/" + kind + "/" + kind + ".clean"); } private String prepareRunTsfmt(String kind) throws IOException { @@ -113,10 +113,10 @@ void tsconfig() throws Exception { @Test void testTypescript_2_Configs() throws Exception { - String path = "src/main/typescript/test.ts"; + testPath = "src/main/typescript/test.ts"; writePomWithTypescriptSteps( - path, + testPath, "", " ${basedir}/tslint.json", " ${basedir}/tslint.json", @@ -124,7 +124,7 @@ void testTypescript_2_Configs() throws Exception { setFile("vscode.json").toResource("npm/tsfmt/vscode/vscode.json"); setFile("tsfmt.json").toResource("npm/tsfmt/tsfmt/tsfmt.json"); - setFile(path).toResource("npm/tsfmt/tsfmt/tsfmt.dirty"); + setFile(testPath).toResource("npm/tsfmt/tsfmt/tsfmt.dirty"); ProcessRunner.Result result = mavenRunner().withArguments("spotless:apply").runHasError(); assertThat(result.stdOutUtf8()).contains("must specify exactly one configFile or config"); } diff --git a/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java b/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java index caf668ae8d..c8e2726fd8 100644 --- a/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java +++ b/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java @@ -42,6 +42,12 @@ import com.diffplug.common.io.Resources; public class ResourceHarness { + + /** + * default test testPath. + */ + protected String testPath = "src/main/java/test.java"; + /** * On OS X, the temp folder is a symlink, * and some of gradle's stuff breaks symlinks.