21
21
22
22
public class JsonExtensionTest extends GradleIntegrationHarness {
23
23
@ Test
24
- public void defaultFormatting () throws IOException {
24
+ public void defaultFormattingWithCustomTarget () throws IOException {
25
25
setFile ("build.gradle" ).toLines (
26
- "buildscript { repositories { mavenCentral() } }" ,
27
- "plugins {" ,
28
- " id 'java'" ,
29
- " id 'com.diffplug.spotless'" ,
30
- "}" ,
31
- "spotless {" ,
32
- " json {" +
33
- " target 'examples/**/*.json'" +
34
- " simple()" +
35
- "}" ,
36
- "}" );
26
+ "buildscript { repositories { mavenCentral() } }" ,
27
+ "plugins {" ,
28
+ " id 'com.diffplug.spotless'" ,
29
+ "}" ,
30
+ "spotless {" ,
31
+ " json {" ,
32
+ " simple()" ,
33
+ " target 'examples/**/*.json'" +
34
+ " }" ,
35
+ "}" );
37
36
setFile ("src/main/resources/example.json" ).toResource ("json/nestedObjectBefore.json" );
38
37
setFile ("examples/main/resources/example.json" ).toResource ("json/nestedObjectBefore.json" );
39
38
gradleRunner ().withArguments ("spotlessApply" ).build ();
@@ -44,21 +43,38 @@ public void defaultFormatting() throws IOException {
44
43
@ Test
45
44
public void formattingWithCustomNumberOfSpaces () throws IOException {
46
45
setFile ("build.gradle" ).toLines (
47
- "buildscript { repositories { mavenCentral() } }" ,
48
- "plugins {" ,
49
- " id 'java'" ,
50
- " id 'com.diffplug.spotless'" ,
51
- "}" ,
52
- "spotless {" ,
53
- " json {" +
54
- " target '**/*.json'" +
55
- " simple {" +
56
- " indentWithSpaces(6)" +
57
- " }" ,
58
- "}" ,
59
- "}" );
46
+ "buildscript { repositories { mavenCentral() } }" ,
47
+ "plugins {" ,
48
+ " id 'com.diffplug.spotless'" ,
49
+ "}" ,
50
+ "spotless {" ,
51
+ " json {" +
52
+ " simple().indentWithSpaces(6)" +
53
+ " target '**/*.json'" +
54
+ " }" ,
55
+ "}" );
60
56
setFile ("src/main/resources/example.json" ).toResource ("json/singletonArrayBefore.json" );
61
57
gradleRunner ().withArguments ("spotlessApply" ).build ();
62
58
assertFile ("src/main/resources/example.json" ).sameAsResource ("json/singletonArrayAfter6Spaces.json" );
63
59
}
60
+
61
+ @ Test
62
+ public void whenTargetIsFirst () throws IOException {
63
+ setFile ("build.gradle" ).toLines (
64
+ "buildscript { repositories { mavenCentral() } }" ,
65
+ "plugins {" ,
66
+ " id 'com.diffplug.spotless'" ,
67
+ "}" ,
68
+ "spotless {" ,
69
+ " json {" ,
70
+ " target 'examples/**/*.json'" +
71
+ " simple()" ,
72
+ " }" ,
73
+ "}" );
74
+ setFile ("src/main/resources/example.json" ).toResource ("json/nestedObjectBefore.json" );
75
+ setFile ("examples/main/resources/example.json" ).toResource ("json/nestedObjectBefore.json" );
76
+ gradleRunner ().withArguments ("spotlessApply" ).build ();
77
+ assertFile ("src/main/resources/example.json" ).sameAsResource ("json/nestedObjectBefore.json" );
78
+ assertFile ("examples/main/resources/example.json" ).sameAsResource ("json/nestedObjectAfter.json" );
79
+ }
64
80
}
0 commit comments