|
16 | 16 |
|
17 | 17 | package org.springframework.boot.build.architecture;
|
18 | 18 |
|
| 19 | +import java.io.FileNotFoundException; |
19 | 20 | import java.io.IOException;
|
| 21 | +import java.nio.charset.StandardCharsets; |
20 | 22 | import java.nio.file.Files;
|
21 | 23 | import java.nio.file.Path;
|
22 | 24 | import java.util.function.Consumer;
|
@@ -160,6 +162,17 @@ void whenClassCallsStringToUpperCaseWithLocaleShouldNotFail() throws IOException
|
160 | 162 | runGradleWithCompiledClasses("string/toUpperCaseWithLocale", shouldHaveEmptyFailureReport());
|
161 | 163 | }
|
162 | 164 |
|
| 165 | + @Test |
| 166 | + void whenBeanMethodExposePrivateTypeeShouldNotFailAndWriteReport() throws IOException { |
| 167 | + runGradleWithCompiledClasses("beans/privatebean", shouldHaveFailureReportWithMessage( |
| 168 | + "@Bean methods must not return types declared with the private modifier, as such types are incompatible with Spring AOT processing")); |
| 169 | + } |
| 170 | + |
| 171 | + @Test |
| 172 | + void whenBeanMethodExposeNonPrivateTypeeShouldNotFail() throws IOException { |
| 173 | + runGradleWithCompiledClasses("beans/regular", shouldHaveEmptyFailureReport()); |
| 174 | + } |
| 175 | + |
163 | 176 | @Test
|
164 | 177 | void whenBeanPostProcessorBeanMethodIsNotStaticWithExternalClass() throws IOException {
|
165 | 178 | Files.writeString(this.buildFile, """
|
@@ -196,17 +209,22 @@ IntegrationMBeanExporter integrationMBeanExporter() {
|
196 | 209 |
|
197 | 210 | private Consumer<GradleRunner> shouldHaveEmptyFailureReport() {
|
198 | 211 | return (gradleRunner) -> {
|
199 |
| - assertThat(gradleRunner.build().getOutput()).contains("BUILD SUCCESSFUL") |
200 |
| - .contains("Task :checkArchitectureMain"); |
201 |
| - assertThat(failureReport()).isEmptyFile(); |
| 212 | + try { |
| 213 | + assertThat(gradleRunner.build().getOutput()).contains("BUILD SUCCESSFUL") |
| 214 | + .contains("Task :checkArchitectureMain"); |
| 215 | + assertThat(failureReport()).isEmpty(); |
| 216 | + } |
| 217 | + catch (Exception ex) { |
| 218 | + throw new AssertionError("Expected build to succeed but it failed\n" + failureReport(), ex); |
| 219 | + } |
202 | 220 | };
|
203 | 221 | }
|
204 | 222 |
|
205 | 223 | private Consumer<GradleRunner> shouldHaveFailureReportWithMessage(String message) {
|
206 | 224 | return (gradleRunner) -> {
|
207 | 225 | assertThat(gradleRunner.buildAndFail().getOutput()).contains("BUILD FAILED")
|
208 | 226 | .contains("Task :checkArchitectureMain FAILED");
|
209 |
| - assertThat(failureReport()).content().contains(message); |
| 227 | + assertThat(failureReport()).contains(message); |
210 | 228 | };
|
211 | 229 | }
|
212 | 230 |
|
@@ -235,8 +253,17 @@ private void runGradle(Consumer<GradleRunner> callback) {
|
235 | 253 | .withPluginClasspath());
|
236 | 254 | }
|
237 | 255 |
|
238 |
| - private Path failureReport() { |
239 |
| - return this.projectDir.resolve("build/checkArchitectureMain/failure-report.txt"); |
| 256 | + private String failureReport() { |
| 257 | + try { |
| 258 | + Path failureReport = this.projectDir.resolve("build/checkArchitectureMain/failure-report.txt"); |
| 259 | + return Files.readString(failureReport, StandardCharsets.UTF_8); |
| 260 | + } |
| 261 | + catch (FileNotFoundException ex) { |
| 262 | + return "Failure report does not exist"; |
| 263 | + } |
| 264 | + catch (IOException ex) { |
| 265 | + return "Failure report could not be read: " + ex.getMessage(); |
| 266 | + } |
240 | 267 | }
|
241 | 268 |
|
242 | 269 | }
|
0 commit comments