Skip to content

Commit fccdf48

Browse files
committed
chore: add test for mode-switch
1 parent b584dcb commit fccdf48

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2025 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.cli;
17+
18+
import java.io.IOException;
19+
20+
import org.junit.jupiter.api.Test;
21+
22+
import com.diffplug.spotless.cli.steps.GoogleJavaFormat;
23+
24+
import static org.assertj.core.api.Assertions.assertThat;
25+
26+
public class SpotlessCLIModeTest extends CLIIntegrationHarness {
27+
28+
@Test
29+
void applyModeChangesFilesAndExitsWithCode0() throws IOException {
30+
setFile("Java.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test");
31+
32+
SpotlessCLIRunner.Result result = cliRunner()
33+
.withTargets("*.java")
34+
.withStep(GoogleJavaFormat.class)
35+
.run();
36+
37+
assertFile("Java.java").sameAsResource("java/googlejavaformat/JavaCodeFormatted.test");
38+
assertThat(result.exitCode()).isEqualTo(0);
39+
}
40+
41+
@Test
42+
void checkModeLeavesFilesUnchangedAndExitsWithCode1() throws IOException {
43+
setFile("Java.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test");
44+
45+
SpotlessCLIRunner.Result result = cliRunner()
46+
.withTargets("*.java")
47+
.withOption("--mode", "check")
48+
.withStep(GoogleJavaFormat.class)
49+
.runAndFail();
50+
51+
assertFile("Java.java").sameAsResource("java/googlejavaformat/JavaCodeUnformatted.test");
52+
assertThat(result.exitCode()).isEqualTo(1);
53+
}
54+
}

0 commit comments

Comments
 (0)