Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jamietanna committed May 12, 2021
1 parent 9569417 commit 9dc26a3
Showing 1 changed file with 41 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@

public class JsonExtensionTest extends GradleIntegrationHarness {
@Test
public void defaultFormatting() throws IOException {
public void defaultFormattingWithCustomTarget() throws IOException {
setFile("build.gradle").toLines(
"buildscript { repositories { mavenCentral() } }",
"plugins {",
" id 'java'",
" id 'com.diffplug.spotless'",
"}",
"spotless {",
" json {" +
" target 'examples/**/*.json'" +
" simple()" +
"}",
"}");
"buildscript { repositories { mavenCentral() } }",
"plugins {",
" id 'com.diffplug.spotless'",
"}",
"spotless {",
" json {",
" simple()",
" target 'examples/**/*.json'" +
" }",
"}");
setFile("src/main/resources/example.json").toResource("json/nestedObjectBefore.json");
setFile("examples/main/resources/example.json").toResource("json/nestedObjectBefore.json");
gradleRunner().withArguments("spotlessApply").build();
Expand All @@ -44,21 +43,38 @@ public void defaultFormatting() throws IOException {
@Test
public void formattingWithCustomNumberOfSpaces() throws IOException {
setFile("build.gradle").toLines(
"buildscript { repositories { mavenCentral() } }",
"plugins {",
" id 'java'",
" id 'com.diffplug.spotless'",
"}",
"spotless {",
" json {" +
" target '**/*.json'" +
" simple {" +
" indentWithSpaces(6)" +
" }",
"}",
"}");
"buildscript { repositories { mavenCentral() } }",
"plugins {",
" id 'com.diffplug.spotless'",
"}",
"spotless {",
" json {" +
" simple().indentWithSpaces(6)" +
" target '**/*.json'" +
" }",
"}");
setFile("src/main/resources/example.json").toResource("json/singletonArrayBefore.json");
gradleRunner().withArguments("spotlessApply").build();
assertFile("src/main/resources/example.json").sameAsResource("json/singletonArrayAfter6Spaces.json");
}

@Test
public void whenTargetIsFirst() throws IOException {
setFile("build.gradle").toLines(
"buildscript { repositories { mavenCentral() } }",
"plugins {",
" id 'com.diffplug.spotless'",
"}",
"spotless {",
" json {",
" target 'examples/**/*.json'" +
" simple()",
" }",
"}");
setFile("src/main/resources/example.json").toResource("json/nestedObjectBefore.json");
setFile("examples/main/resources/example.json").toResource("json/nestedObjectBefore.json");
gradleRunner().withArguments("spotlessApply").build();
assertFile("src/main/resources/example.json").sameAsResource("json/nestedObjectBefore.json");
assertFile("examples/main/resources/example.json").sameAsResource("json/nestedObjectAfter.json");
}
}

0 comments on commit 9dc26a3

Please sign in to comment.