Skip to content

Commit 87c6fc5

Browse files
committed
chore: rewrite tests to use selfie where possible
1 parent 333af93 commit 87c6fc5

File tree

8 files changed

+115
-16
lines changed

8 files changed

+115
-16
lines changed

app/src/test/java/com/diffplug/spotless/cli/SpotlessCLIModeTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void applyModeChangesFilesAndExitsWithCode0() throws IOException {
3434
.withStep(GoogleJavaFormat.class)
3535
.run();
3636

37-
assertFile("Java.java").sameAsResource("java/googlejavaformat/JavaCodeFormatted.test");
37+
selfie().expectResource("Java.java").toMatchDisk();
3838
assertThat(result.exitCode()).isEqualTo(0);
3939
}
4040

@@ -48,7 +48,7 @@ void checkModeLeavesFilesUnchangedAndExitsWithCode1() throws IOException {
4848
.withStep(GoogleJavaFormat.class)
4949
.runAndFail();
5050

51-
assertFile("Java.java").sameAsResource("java/googlejavaformat/JavaCodeUnformatted.test");
51+
selfie().expectResource("Java.java").toMatchDisk();
5252
assertThat(result.exitCode()).isEqualTo(1);
5353
}
5454
}

app/src/test/java/com/diffplug/spotless/cli/steps/GoogleJavaFormatNativeProcessTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,4 @@
1818
import com.diffplug.spotless.tag.CliNativeTest;
1919

2020
@CliNativeTest
21-
public class GoogleJavaFormatNativeProcessTest extends GoogleJavaFormatTest {
22-
23-
// TODO include the correct google-java-format class to be available in native
24-
}
21+
public class GoogleJavaFormatNativeProcessTest extends GoogleJavaFormatTest {}

app/src/test/java/com/diffplug/spotless/cli/steps/GoogleJavaFormatTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ void formattingWithGoogleJavaFormatWorks() throws IOException {
3333
.withStep(GoogleJavaFormat.class)
3434
.run();
3535

36-
assertFile("Java.java").sameAsResource("java/googlejavaformat/JavaCodeFormatted.test");
36+
selfie().expectResource("Java.java").toMatchDisk();
3737
}
3838
}

app/src/test/java/com/diffplug/spotless/cli/steps/LicenseHeaderTest.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ void assertHeaderIsApplied() {
4747
.withOption("--header", "/* License */")
4848
.run();
4949

50-
assertFile("TestFile.java").hasContent("/* License */\npublic class TestFile {}");
50+
selfie().expectResource("TestFile.java").toBe("""
51+
/* License */
52+
public class TestFile {}""");
5153
}
5254

5355
@Test
@@ -61,7 +63,9 @@ void assertHeaderFileIsApplied() {
6163
.withOption("--header-file", "header.txt")
6264
.run();
6365

64-
assertFile("TestFile.java").hasContent("/* License */\npublic class TestFile {}");
66+
selfie().expectResource("TestFile.java").toBe("""
67+
/* License */
68+
public class TestFile {}""");
6569
}
6670

6771
@Test
@@ -75,7 +79,10 @@ void assertDelimiterIsApplied() {
7579
.withOption("--delimiter", "\\/\\* keep me")
7680
.run();
7781

78-
assertFile("TestFile.java").hasContent("/* License */\n/* keep me */\npublic class TestFile {}");
82+
selfie().expectResource("TestFile.java").toBe("""
83+
/* License */
84+
/* keep me */
85+
public class TestFile {}""");
7986
}
8087

8188
@Test
@@ -120,7 +127,11 @@ void assertSkipLinesMatchingIsApplied() {
120127
.withOption("--skip-lines-matching", ".*skip me.*")
121128
.run();
122129

123-
assertFile("TestFile.java").hasContent("/* skip me */\n/* License */\npublic class TestFile {}");
130+
selfie().expectResource("TestFile.java").toBe("""
131+
/* skip me */
132+
/* License */
133+
public class TestFile {}
134+
""");
124135
}
125136

126137
@Test
@@ -134,7 +145,9 @@ void assertPreserveModeIsApplied() {
134145
.withOption("--year-mode", LicenseHeaderStep.YearMode.PRESERVE.toString())
135146
.run();
136147

137-
assertFile("TestFile.java").hasContent("/* License (c) 2022 */\npublic class TestFile {}");
148+
selfie().expectResource("TestFile.java").toBe("""
149+
/* License (c) 2022 */
150+
public class TestFile {}""");
138151
}
139152

140153
@Test
@@ -148,7 +161,9 @@ void assertContentPatternIsAppliedIfMatching() {
148161
.withOption("--content-pattern", ".*TestFile.*")
149162
.run();
150163

151-
assertFile("TestFile.java").hasContent("/* License */\npublic class TestFile {}");
164+
selfie().expectResource("TestFile.java").toBe("""
165+
/* License */
166+
public class TestFile {}""");
152167
}
153168

154169
@Test
@@ -162,6 +177,6 @@ void assertContentPatternIsNotAppliedIfNotMatching() {
162177
.withOption("--content-pattern", ".*NonExistent.*")
163178
.run();
164179

165-
assertFile("TestFile.java").hasContent("public class TestFile {}");
180+
selfie().expectResource("TestFile.java").toBe("public class TestFile {}");
166181
}
167182
}

app/src/test/java/com/diffplug/spotless/cli/steps/PrettierTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void itRunsPrettierForTsFilesWithOptions() throws IOException {
3737
.withOption("--prettier-config-option", "parser=typescript")
3838
.run();
3939

40-
assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean");
40+
selfie().expectResource("test.ts").toMatchDisk();
4141
}
4242

4343
@Test
@@ -51,6 +51,6 @@ void itRunsPrettierForTsFilesWithOptionFile() throws Exception {
5151
.withOption("--prettier-config-path", ".prettierrc.yml")
5252
.run();
5353

54-
assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean");
54+
selfie().expectResource("test.ts").toMatchDisk();
5555
}
5656
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
╔═ applyModeChangesFilesAndExitsWithCode0 ═╗
2+
import mylib.UsedA;
3+
import mylib.UsedB;
4+
5+
public class Java {
6+
/** Some javadoc. */
7+
public static void main(String[] args) {
8+
System.out.println(
9+
"A very very very very very very very very very very very very very very very very very very very very very long string that goes beyond the 100-character line length.");
10+
UsedB.someMethod();
11+
UsedA.someMethod();
12+
}
13+
}
14+
15+
╔═ checkModeLeavesFilesUnchangedAndExitsWithCode1 ═╗
16+
17+
import mylib.Unused;
18+
import mylib.UsedB;
19+
import mylib.UsedA;
20+
21+
public class Java {
22+
/**
23+
* Some javadoc.
24+
*/
25+
public static void main(String[] args) {
26+
System.out.println("A very very very very very very very very very very very very very very very very very very very very very long string that goes beyond the 100-character line length.");
27+
UsedB.someMethod();
28+
UsedA.someMethod();
29+
}
30+
}
31+
╔═ [end of file] ═╗
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
╔═ formattingWithGoogleJavaFormatWorks ═╗
2+
import mylib.UsedA;
3+
import mylib.UsedB;
4+
5+
public class Java {
6+
/** Some javadoc. */
7+
public static void main(String[] args) {
8+
System.out.println(
9+
"A very very very very very very very very very very very very very very very very very very very very very long string that goes beyond the 100-character line length.");
10+
UsedB.someMethod();
11+
UsedA.someMethod();
12+
}
13+
}
14+
15+
╔═ [end of file] ═╗
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
╔═ itRunsPrettierForTsFilesWithOptionFile ═╗
2+
export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary
3+
extends AbstractController
4+
implements
5+
DisposeAware,
6+
CallbackAware
7+
{
8+
public myValue: string[];
9+
10+
constructor(
11+
private myService: Service,
12+
name: string,
13+
private field: any
14+
) {
15+
super(name);
16+
}
17+
18+
//...
19+
}
20+
21+
╔═ itRunsPrettierForTsFilesWithOptions ═╗
22+
export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary
23+
extends AbstractController
24+
implements
25+
DisposeAware,
26+
CallbackAware
27+
{
28+
public myValue: string[];
29+
30+
constructor(
31+
private myService: Service,
32+
name: string,
33+
private field: any
34+
) {
35+
super(name);
36+
}
37+
38+
//...
39+
}
40+
41+
╔═ [end of file] ═╗

0 commit comments

Comments
 (0)