Skip to content

Commit b314a01

Browse files
committed
Adapt maven tests to use ProcessRunner.
1 parent 7294dbc commit b314a01

File tree

9 files changed

+35
-35
lines changed

9 files changed

+35
-35
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2022 DiffPlug
2+
* Copyright 2016-2023 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.
@@ -21,6 +21,8 @@
2121

2222
import org.junit.jupiter.api.Test;
2323

24+
import com.diffplug.spotless.ProcessRunner;
25+
2426
class SpotlessCheckMojoTest extends MavenIntegrationHarness {
2527

2628
private static final String UNFORMATTED_FILE = "license/MissingLicense.test";
@@ -72,8 +74,8 @@ private void testSpotlessCheck(String fileName, String command, boolean expectEr
7274
MavenRunner mavenRunner = mavenRunner().withArguments(command);
7375

7476
if (expectError) {
75-
MavenRunner.Result result = mavenRunner.runHasError();
76-
assertThat(result.output()).contains("The following files had format violations");
77+
ProcessRunner.Result result = mavenRunner.runHasError();
78+
assertThat(result.stdOutUtf8()).contains("The following files had format violations");
7779
} else {
7880
mavenRunner.runNoError();
7981
}

plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2022 DiffPlug
2+
* Copyright 2021-2023 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.
@@ -254,15 +254,15 @@ private List<File> writeFiles(String resource, String suffix, int count) throws
254254
}
255255

256256
private String runSpotlessApply() throws Exception {
257-
return mavenRunnerForGoal("apply").runNoError().output();
257+
return mavenRunnerForGoal("apply").runNoError().stdOutUtf8();
258258
}
259259

260260
private String runSpotlessCheck() throws Exception {
261-
return mavenRunnerForGoal("check").runNoError().output();
261+
return mavenRunnerForGoal("check").runNoError().stdOutUtf8();
262262
}
263263

264264
private String runSpotlessCheckOnUnformattedFiles() throws Exception {
265-
return mavenRunnerForGoal("check").runHasError().output();
265+
return mavenRunnerForGoal("check").runHasError().stdOutUtf8();
266266
}
267267

268268
private MavenRunner mavenRunnerForGoal(String goal) throws IOException {

plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import org.junit.jupiter.params.ParameterizedTest;
2121
import org.junit.jupiter.params.provider.ValueSource;
2222

23+
import com.diffplug.spotless.ProcessRunner;
2324
import com.diffplug.spotless.ResourceHarness;
2425
import com.diffplug.spotless.maven.MavenIntegrationHarness;
25-
import com.diffplug.spotless.maven.MavenRunner.Result;
2626
import com.diffplug.spotless.npm.EslintFormatterStep;
2727
import com.diffplug.spotless.npm.EslintStyleGuide;
2828
import com.diffplug.spotless.tag.NpmTest;
@@ -50,8 +50,7 @@ void eslintConfigFile() throws Exception {
5050
setFile(".eslintrc.js").toResource("npm/eslint/javascript/custom_rules/.eslintrc.js");
5151
setFile(TEST_FILE_PATH).toResource("npm/eslint/javascript/custom_rules/javascript-es6.dirty");
5252

53-
Result result = mavenRunner().withArguments("spotless:apply").runNoError();
54-
System.out.println(result.output());
53+
ProcessRunner.Result result = mavenRunner().withArguments("spotless:apply").runNoError();
5554
assertFile(TEST_FILE_PATH).sameAsResource("npm/eslint/javascript/custom_rules/javascript-es6.clean");
5655
}
5756

plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void testFormatJson_WithGson_sortByKeys() throws Exception {
5757

5858
setFile("json_test.json").toResource("json/sortByKeysBefore.json");
5959

60-
String output = mavenRunner().withArguments("spotless:apply").runNoError().output();
60+
String output = mavenRunner().withArguments("spotless:apply").runNoError().stdOutUtf8();
6161
LOGGER.error(output);
6262
System.err.println(output);
6363
assertFile("json_test.json").sameAsResource("json/sortByKeysAfter.json");

plugin-maven/src/test/java/com/diffplug/spotless/maven/markdown/FlexmarkMavenTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 DiffPlug
2+
* Copyright 2021-2023 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.
@@ -26,8 +26,7 @@ public void testFlexmarkWithDefaultConfig() throws Exception {
2626
writePomWithMarkdownSteps("<flexmark />");
2727

2828
setFile("markdown_test.md").toResource("markdown/flexmark/FlexmarkUnformatted.md");
29-
mavenRunner().withArguments("spotless:apply").runNoError().error();
29+
mavenRunner().withArguments("spotless:apply").runNoError();
3030
assertFile("markdown_test.md").sameAsResource("markdown/flexmark/FlexmarkFormatted.md");
3131
}
32-
3332
}

plugin-maven/src/test/java/com/diffplug/spotless/maven/pom/SortPomMavenTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 DiffPlug
2+
* Copyright 2021-2023 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.
@@ -25,7 +25,7 @@ public void testSortPomWithDefaultConfig() throws Exception {
2525
writePomWithPomSteps("<sortPom/>");
2626

2727
setFile("pom_test.xml").toResource("pom/pom_dirty.xml");
28-
mavenRunner().withArguments("spotless:apply").runNoError().error();
28+
mavenRunner().withArguments("spotless:apply").runNoError();
2929
assertFile("pom_test.xml").sameAsResource("pom/pom_clean_default.xml");
3030
}
3131
}

plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
import org.junit.jupiter.api.Test;
2323

24+
import com.diffplug.spotless.ProcessRunner;
2425
import com.diffplug.spotless.maven.MavenIntegrationHarness;
25-
import com.diffplug.spotless.maven.MavenRunner.Result;
2626
import com.diffplug.spotless.maven.generic.Prettier;
2727
import com.diffplug.spotless.tag.NpmTest;
2828

@@ -43,7 +43,7 @@ private String prepareRun(String kind, String suffix) throws IOException {
4343
return path;
4444
}
4545

46-
private Result runExpectingError(String kind, String suffix) throws IOException, InterruptedException {
46+
private ProcessRunner.Result runExpectingError(String kind, String suffix) throws IOException, InterruptedException {
4747
String path = prepareRun(kind, suffix);
4848
return mavenRunner().withArguments("spotless:apply").runHasError();
4949
}
@@ -102,8 +102,8 @@ void unique_dependency_config() throws Exception {
102102
" <devDependencies><prettier>1.16.4</prettier></devDependencies>",
103103
"</prettier>");
104104

105-
Result result = mavenRunner().withArguments("spotless:apply").runHasError();
106-
assertThat(result.output()).contains(Prettier.ERROR_MESSAGE_ONLY_ONE_CONFIG);
105+
ProcessRunner.Result result = mavenRunner().withArguments("spotless:apply").runHasError();
106+
assertThat(result.stdOutUtf8()).contains(Prettier.ERROR_MESSAGE_ONLY_ONE_CONFIG);
107107
}
108108

109109
@Test
@@ -156,8 +156,8 @@ void autodetect_npmrc_file() throws Exception {
156156
" <prettierVersion>1.16.4</prettierVersion>",
157157
" <configFile>.prettierrc.yml</configFile>",
158158
"</prettier>");
159-
Result result = runExpectingError("typescript", suffix);
160-
assertThat(result.output()).containsPattern("Running npm command.*npm install.* failed with exit code: 1");
159+
ProcessRunner.Result result = runExpectingError("typescript", suffix);
160+
assertThat(result.stdOutUtf8()).containsPattern("Running npm command.*npm install.* failed with exit code: 1");
161161
}
162162

163163
@Test
@@ -174,7 +174,7 @@ void select_configured_npmrc_file() throws Exception {
174174
" <configFile>.prettierrc.yml</configFile>",
175175
" <npmrc>${basedir}/.custom_npmrc</npmrc>",
176176
"</prettier>");
177-
Result result = runExpectingError("typescript", suffix);
178-
assertThat(result.output()).containsPattern("Running npm command.*npm install.* failed with exit code: 1");
177+
ProcessRunner.Result result = runExpectingError("typescript", suffix);
178+
assertThat(result.stdOutUtf8()).containsPattern("Running npm command.*npm install.* failed with exit code: 1");
179179
}
180180
}

plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222
import org.junit.jupiter.api.Test;
2323

24+
import com.diffplug.spotless.ProcessRunner;
2425
import com.diffplug.spotless.ResourceHarness;
2526
import com.diffplug.spotless.maven.MavenIntegrationHarness;
26-
import com.diffplug.spotless.maven.MavenRunner.Result;
2727
import com.diffplug.spotless.npm.EslintFormatterStep;
2828
import com.diffplug.spotless.npm.EslintStyleGuide;
2929
import com.diffplug.spotless.tag.NpmTest;
@@ -48,7 +48,7 @@ private String prepareRunTsfmt(String kind) throws IOException {
4848
return TEST_FILE_PATH;
4949
}
5050

51-
private Result runExpectingErrorTsfmt(String kind) throws IOException, InterruptedException {
51+
private ProcessRunner.Result runExpectingErrorTsfmt(String kind) throws IOException, InterruptedException {
5252
prepareRunTsfmt(kind);
5353
return mavenRunner().withArguments("spotless:apply").runHasError();
5454
}
@@ -124,8 +124,8 @@ void testTypescript_2_Configs() throws Exception {
124124
setFile("tsfmt.json").toResource("npm/tsfmt/tsfmt/tsfmt.json");
125125

126126
setFile(path).toResource("npm/tsfmt/tsfmt/tsfmt.dirty");
127-
Result result = mavenRunner().withArguments("spotless:apply").runHasError();
128-
assertThat(result.output()).contains("must specify exactly one configFile or config");
127+
ProcessRunner.Result result = mavenRunner().withArguments("spotless:apply").runHasError();
128+
assertThat(result.stdOutUtf8()).contains("must specify exactly one configFile or config");
129129
}
130130

131131
@Test
@@ -141,8 +141,8 @@ void testNpmrcIsAutoPickedUp() throws Exception {
141141
" <tslintFile>${basedir}/tslint.json</tslintFile>",
142142
"</tsfmt>");
143143
setFile("tslint.json").toResource("npm/tsfmt/tslint/tslint.json");
144-
Result result = runExpectingErrorTsfmt("tslint");
145-
assertThat(result.output()).containsPattern("Running npm command.*npm install.* failed with exit code: 1");
144+
ProcessRunner.Result result = runExpectingErrorTsfmt("tslint");
145+
assertThat(result.stdOutUtf8()).containsPattern("Running npm command.*npm install.* failed with exit code: 1");
146146
}
147147

148148
@Test
@@ -159,8 +159,8 @@ void testNpmrcIsConfigurativelyPickedUp() throws Exception {
159159
" <npmrc>${basedir}/.custom_npmrc</npmrc>",
160160
"</tsfmt>");
161161
setFile("tslint.json").toResource("npm/tsfmt/tslint/tslint.json");
162-
Result result = runExpectingErrorTsfmt("tslint");
163-
assertThat(result.output()).containsPattern("Running npm command.*npm install.* failed with exit code: 1");
162+
ProcessRunner.Result result = runExpectingErrorTsfmt("tslint");
163+
assertThat(result.stdOutUtf8()).containsPattern("Running npm command.*npm install.* failed with exit code: 1");
164164
}
165165

166166
@Test

plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import org.slf4j.Logger;
2222
import org.slf4j.LoggerFactory;
2323

24+
import com.diffplug.spotless.ProcessRunner;
2425
import com.diffplug.spotless.maven.MavenIntegrationHarness;
25-
import com.diffplug.spotless.maven.MavenRunner.Result;
2626

2727
public class YamlTest extends MavenIntegrationHarness {
2828
private static final Logger LOGGER = LoggerFactory.getLogger(YamlTest.class);
@@ -32,9 +32,9 @@ public void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws
3232
writePomWithYamlSteps("<jackson/>");
3333

3434
setFile("yaml_test.yaml").toResource("yaml/separator_comments.yaml");
35-
Result runNoError = mavenRunner().withArguments("spotless:apply").runNoError();
35+
ProcessRunner.Result runNoError = mavenRunner().withArguments("spotless:apply").runNoError();
3636
LOGGER.error("result: {}", runNoError);
37-
assertThat(runNoError.exitValue()).as("Run without error %s", runNoError).isEqualTo(0);
37+
assertThat(runNoError.exitCode()).as("Run without error %s", runNoError).isEqualTo(0);
3838
LOGGER.error("GOGO");
3939
assertFile("yaml_test.yaml").sameAsResource("yaml/separator_comments.clean.yaml");
4040
}

0 commit comments

Comments
 (0)