|
19 | 19 | import java.io.File; |
20 | 20 | import java.io.IOException; |
21 | 21 | import java.nio.file.Files; |
| 22 | +import java.util.Arrays; |
22 | 23 |
|
23 | 24 | import org.gradle.testkit.runner.BuildResult; |
24 | 25 | import org.gradle.testkit.runner.GradleRunner; |
@@ -52,21 +53,42 @@ public void checkOk() throws IOException { |
52 | 53 | } |
53 | 54 |
|
54 | 55 | @Test |
55 | | - public void checkUpTpDate() throws IOException { |
| 56 | + public void checkUpToDate() throws IOException { |
56 | 57 | GradleRunner runner = this.gradleBuild.source("src/test/resources/format").prepareRunner("format"); |
| 58 | + // Format that changes files |
| 59 | + assertThat(runner.build().task(":formatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); |
| 60 | + // Format of already formatted files |
| 61 | + assertThat(runner.build().task(":formatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); |
| 62 | + // Up-to-date |
| 63 | + assertThat(runner.build().task(":formatMain").getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE); |
| 64 | + } |
57 | 65 |
|
58 | | - // 1) Actually format the sources. |
59 | | - BuildResult result1 = runner.build(); |
60 | | - assertThat(result1.task(":formatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); |
61 | | - |
62 | | - // 2) No-op reformat the sources |
63 | | - // Not up-to-date yet because 1) changed the sources. |
64 | | - BuildResult result2 = runner.build(); |
65 | | - assertThat(result2.task(":formatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); |
| 66 | + @Test |
| 67 | + public void notUpToDateWhenJavaBaselineChanges() throws IOException { |
| 68 | + GradleRunner runner = this.gradleBuild.source("src/test/resources/format").prepareRunner("format"); |
| 69 | + // Format that changes files |
| 70 | + assertThat(runner.build().task(":formatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); |
| 71 | + // Format of already formatted files |
| 72 | + assertThat(runner.build().task(":formatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); |
| 73 | + // Up-to-date |
| 74 | + assertThat(runner.build().task(":formatMain").getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE); |
| 75 | + Files.write(new File(this.gradleBuild.getProjectDir(), ".springjavaformatconfig").toPath(), |
| 76 | + Arrays.asList("java-baseline=8")); |
| 77 | + assertThat(runner.build().task(":formatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); |
| 78 | + } |
66 | 79 |
|
67 | | - // 3) Now we should be up-to-date since 2) was effectively a no-op |
68 | | - BuildResult result3 = runner.build(); |
69 | | - assertThat(result3.task(":formatMain").getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE); |
| 80 | + @Test |
| 81 | + public void notUpToDateWhenIndentationStyleChanges() throws IOException { |
| 82 | + GradleRunner runner = this.gradleBuild.source("src/test/resources/format").prepareRunner("format"); |
| 83 | + // Format that changes files |
| 84 | + assertThat(runner.build().task(":formatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); |
| 85 | + // Format of already formatted files |
| 86 | + assertThat(runner.build().task(":formatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); |
| 87 | + // Up-to-date |
| 88 | + assertThat(runner.build().task(":formatMain").getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE); |
| 89 | + Files.write(new File(this.gradleBuild.getProjectDir(), ".springjavaformatconfig").toPath(), |
| 90 | + Arrays.asList("indentation-style=spaces")); |
| 91 | + assertThat(runner.build().task(":formatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); |
70 | 92 | } |
71 | 93 |
|
72 | 94 | @Test |
|
0 commit comments