|
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;
|
| 25 | +import org.gradle.testkit.runner.GradleRunner; |
24 | 26 | import org.gradle.testkit.runner.TaskOutcome;
|
25 | 27 | import org.junit.jupiter.api.Test;
|
26 | 28 | import org.junit.jupiter.api.extension.ExtendWith;
|
@@ -50,6 +52,45 @@ public void checkOk() throws IOException {
|
50 | 52 | assertThat(formattedContent).contains("class Simple {").contains(" public static void main");
|
51 | 53 | }
|
52 | 54 |
|
| 55 | + @Test |
| 56 | + public void checkUpToDate() throws IOException { |
| 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 | + } |
| 65 | + |
| 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 | + } |
| 79 | + |
| 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); |
| 92 | + } |
| 93 | + |
53 | 94 | @Test
|
54 | 95 | public void checkSpacesOk() throws IOException {
|
55 | 96 | BuildResult result = this.gradleBuild.source("src/test/resources/format-spaces").build("format");
|
|
0 commit comments