|
|
|
@ -56,7 +56,7 @@ class ArchitectureCheckTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void whenPackagesAreTangledTaskFailsAndWritesAReport() throws IOException { |
|
|
|
void whenPackagesAreTangledTaskFailsAndWritesAReport() throws IOException { |
|
|
|
runGradleWithCompiledClasses("tangled", |
|
|
|
runGradleWithCompiledClasses("tangled", |
|
|
|
shouldHaveFailureReportWithMessage("slices matching '(**)' should be free of cycles")); |
|
|
|
shouldHaveFailureReportWithMessages("slices matching '(**)' should be free of cycles")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -67,7 +67,7 @@ class ArchitectureCheckTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void whenBeanPostProcessorBeanMethodIsNotStaticTaskFailsAndWritesAReport() throws IOException { |
|
|
|
void whenBeanPostProcessorBeanMethodIsNotStaticTaskFailsAndWritesAReport() throws IOException { |
|
|
|
runGradleWithCompiledClasses("bpp/nonstatic", |
|
|
|
runGradleWithCompiledClasses("bpp/nonstatic", |
|
|
|
shouldHaveFailureReportWithMessage( |
|
|
|
shouldHaveFailureReportWithMessages( |
|
|
|
"methods that are annotated with @Bean and have raw return type assignable " |
|
|
|
"methods that are annotated with @Bean and have raw return type assignable " |
|
|
|
+ "to org.springframework.beans.factory.config.BeanPostProcessor")); |
|
|
|
+ "to org.springframework.beans.factory.config.BeanPostProcessor")); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -75,7 +75,7 @@ class ArchitectureCheckTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void whenBeanPostProcessorBeanMethodIsStaticAndHasUnsafeParametersTaskFailsAndWritesAReport() throws IOException { |
|
|
|
void whenBeanPostProcessorBeanMethodIsStaticAndHasUnsafeParametersTaskFailsAndWritesAReport() throws IOException { |
|
|
|
runGradleWithCompiledClasses("bpp/unsafeparameters", |
|
|
|
runGradleWithCompiledClasses("bpp/unsafeparameters", |
|
|
|
shouldHaveFailureReportWithMessage( |
|
|
|
shouldHaveFailureReportWithMessages( |
|
|
|
"methods that are annotated with @Bean and have raw return type assignable " |
|
|
|
"methods that are annotated with @Bean and have raw return type assignable " |
|
|
|
+ "to org.springframework.beans.factory.config.BeanPostProcessor")); |
|
|
|
+ "to org.springframework.beans.factory.config.BeanPostProcessor")); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -95,14 +95,14 @@ class ArchitectureCheckTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void whenBeanFactoryPostProcessorBeanMethodIsNotStaticTaskFailsAndWritesAReport() throws IOException { |
|
|
|
void whenBeanFactoryPostProcessorBeanMethodIsNotStaticTaskFailsAndWritesAReport() throws IOException { |
|
|
|
runGradleWithCompiledClasses("bfpp/nonstatic", |
|
|
|
runGradleWithCompiledClasses("bfpp/nonstatic", |
|
|
|
shouldHaveFailureReportWithMessage("methods that are annotated with @Bean and have raw return " |
|
|
|
shouldHaveFailureReportWithMessages("methods that are annotated with @Bean and have raw return " |
|
|
|
+ "type assignable to org.springframework.beans.factory.config.BeanFactoryPostProcessor")); |
|
|
|
+ "type assignable to org.springframework.beans.factory.config.BeanFactoryPostProcessor")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void whenBeanFactoryPostProcessorBeanMethodIsStaticAndHasParametersTaskFailsAndWritesAReport() throws IOException { |
|
|
|
void whenBeanFactoryPostProcessorBeanMethodIsStaticAndHasParametersTaskFailsAndWritesAReport() throws IOException { |
|
|
|
runGradleWithCompiledClasses("bfpp/parameters", |
|
|
|
runGradleWithCompiledClasses("bfpp/parameters", |
|
|
|
shouldHaveFailureReportWithMessage("methods that are annotated with @Bean and have raw return " |
|
|
|
shouldHaveFailureReportWithMessages("methods that are annotated with @Bean and have raw return " |
|
|
|
+ "type assignable to org.springframework.beans.factory.config.BeanFactoryPostProcessor")); |
|
|
|
+ "type assignable to org.springframework.beans.factory.config.BeanFactoryPostProcessor")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -114,7 +114,7 @@ class ArchitectureCheckTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void whenClassLoadsResourceUsingResourceUtilsTaskFailsAndWritesReport() throws IOException { |
|
|
|
void whenClassLoadsResourceUsingResourceUtilsTaskFailsAndWritesReport() throws IOException { |
|
|
|
runGradleWithCompiledClasses("resources/loads", shouldHaveFailureReportWithMessage( |
|
|
|
runGradleWithCompiledClasses("resources/loads", shouldHaveFailureReportWithMessages( |
|
|
|
"no classes should call method where target owner type org.springframework.util.ResourceUtils and target name 'getURL'")); |
|
|
|
"no classes should call method where target owner type org.springframework.util.ResourceUtils and target name 'getURL'")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -130,26 +130,26 @@ class ArchitectureCheckTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void whenClassCallsObjectsRequireNonNullWithMessageTaskFailsAndWritesReport() throws IOException { |
|
|
|
void whenClassCallsObjectsRequireNonNullWithMessageTaskFailsAndWritesReport() throws IOException { |
|
|
|
runGradleWithCompiledClasses("objects/requireNonNullWithString", shouldHaveFailureReportWithMessage( |
|
|
|
runGradleWithCompiledClasses("objects/requireNonNullWithString", shouldHaveFailureReportWithMessages( |
|
|
|
"no classes should call method Objects.requireNonNull(Object, String)")); |
|
|
|
"no classes should call method Objects.requireNonNull(Object, String)")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void whenClassCallsObjectsRequireNonNullWithSupplierTaskFailsAndWritesReport() throws IOException { |
|
|
|
void whenClassCallsObjectsRequireNonNullWithSupplierTaskFailsAndWritesReport() throws IOException { |
|
|
|
runGradleWithCompiledClasses("objects/requireNonNullWithSupplier", shouldHaveFailureReportWithMessage( |
|
|
|
runGradleWithCompiledClasses("objects/requireNonNullWithSupplier", shouldHaveFailureReportWithMessages( |
|
|
|
"no classes should call method Objects.requireNonNull(Object, Supplier)")); |
|
|
|
"no classes should call method Objects.requireNonNull(Object, Supplier)")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void whenClassCallsStringToUpperCaseWithoutLocaleFailsAndWritesReport() throws IOException { |
|
|
|
void whenClassCallsStringToUpperCaseWithoutLocaleFailsAndWritesReport() throws IOException { |
|
|
|
runGradleWithCompiledClasses("string/toUpperCase", |
|
|
|
runGradleWithCompiledClasses("string/toUpperCase", |
|
|
|
shouldHaveFailureReportWithMessage("because String.toUpperCase(Locale.ROOT) should be used instead")); |
|
|
|
shouldHaveFailureReportWithMessages("because String.toUpperCase(Locale.ROOT) should be used instead")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void whenClassCallsStringToLowerCaseWithoutLocaleFailsAndWritesReport() throws IOException { |
|
|
|
void whenClassCallsStringToLowerCaseWithoutLocaleFailsAndWritesReport() throws IOException { |
|
|
|
runGradleWithCompiledClasses("string/toLowerCase", |
|
|
|
runGradleWithCompiledClasses("string/toLowerCase", |
|
|
|
shouldHaveFailureReportWithMessage("because String.toLowerCase(Locale.ROOT) should be used instead")); |
|
|
|
shouldHaveFailureReportWithMessages("because String.toLowerCase(Locale.ROOT) should be used instead")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -164,7 +164,7 @@ class ArchitectureCheckTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void whenBeanMethodExposePrivateTypeShouldFailAndWriteReport() throws IOException { |
|
|
|
void whenBeanMethodExposePrivateTypeShouldFailAndWriteReport() throws IOException { |
|
|
|
runGradleWithCompiledClasses("beans/privatebean", shouldHaveFailureReportWithMessage( |
|
|
|
runGradleWithCompiledClasses("beans/privatebean", shouldHaveFailureReportWithMessages( |
|
|
|
"methods that are annotated with @Bean should not return types declared with the PRIVATE modifier," |
|
|
|
"methods that are annotated with @Bean should not return types declared with the PRIVATE modifier," |
|
|
|
+ " as such types are incompatible with Spring AOT processing", |
|
|
|
+ " as such types are incompatible with Spring AOT processing", |
|
|
|
"Method <org.springframework.boot.build.architecture.beans.privatebean.PrivateBean.myBean()> " |
|
|
|
"Method <org.springframework.boot.build.architecture.beans.privatebean.PrivateBean.myBean()> " |
|
|
|
@ -173,7 +173,7 @@ class ArchitectureCheckTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void whenBeanMethodExposeNonPrivateTypeeShouldNotFail() throws IOException { |
|
|
|
void whenBeanMethodExposeNonPrivateTypeShouldNotFail() throws IOException { |
|
|
|
runGradleWithCompiledClasses("beans/regular", shouldHaveEmptyFailureReport()); |
|
|
|
runGradleWithCompiledClasses("beans/regular", shouldHaveEmptyFailureReport()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -207,7 +207,7 @@ class ArchitectureCheckTests { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
"""); |
|
|
|
"""); |
|
|
|
runGradle(shouldHaveFailureReportWithMessage("methods that are annotated with @Bean and have raw return " |
|
|
|
runGradle(shouldHaveFailureReportWithMessages("methods that are annotated with @Bean and have raw return " |
|
|
|
+ "type assignable to org.springframework.beans.factory.config.BeanPostProcessor ")); |
|
|
|
+ "type assignable to org.springframework.beans.factory.config.BeanPostProcessor ")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -224,7 +224,7 @@ class ArchitectureCheckTests { |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Consumer<GradleRunner> shouldHaveFailureReportWithMessage(String... messages) { |
|
|
|
private Consumer<GradleRunner> shouldHaveFailureReportWithMessages(String... messages) { |
|
|
|
return (gradleRunner) -> { |
|
|
|
return (gradleRunner) -> { |
|
|
|
assertThat(gradleRunner.buildAndFail().getOutput()).contains("BUILD FAILED") |
|
|
|
assertThat(gradleRunner.buildAndFail().getOutput()).contains("BUILD FAILED") |
|
|
|
.contains("Task :checkArchitectureMain FAILED"); |
|
|
|
.contains("Task :checkArchitectureMain FAILED"); |
|
|
|
|