NotConstructorBoundInjectionFailureAnalyzerTests Class — spring-boot Architecture
Architecture documentation for the NotConstructorBoundInjectionFailureAnalyzerTests class in NotConstructorBoundInjectionFailureAnalyzerTests.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot/src/test/java/org/springframework/boot/context/properties/NotConstructorBoundInjectionFailureAnalyzerTests.java lines 38–129
class NotConstructorBoundInjectionFailureAnalyzerTests {
private final NotConstructorBoundInjectionFailureAnalyzer analyzer = new NotConstructorBoundInjectionFailureAnalyzer();
@Test
void failureAnalysisForConfigurationPropertiesThatShouldHaveBeenConstructorBound() {
FailureAnalysis analysis = analyzeFailure(
createFailure(ShouldHaveUsedConstructorBindingPropertiesConfiguration.class));
assertThat(analysis).isNotNull();
assertThat(analysis.getDescription()).isEqualTo(ConstructorBoundProperties.class.getSimpleName()
+ " is annotated with @" + ConstructorBinding.class.getSimpleName()
+ " but it is defined as a regular bean which caused dependency injection to fail.");
assertThat(analysis.getAction())
.isEqualTo("Update your configuration so that " + ConstructorBoundProperties.class.getSimpleName()
+ " is defined via @" + ConfigurationPropertiesScan.class.getSimpleName() + " or @"
+ EnableConfigurationProperties.class.getSimpleName() + ".");
}
@Test
void failureAnalysisForNonConstructorBoundProperties() {
FailureAnalysis analysis = analyzeFailure(createFailure(JavaBeanBoundPropertiesConfiguration.class));
assertThat(analysis).isNull();
}
private @Nullable FatalBeanException createFailure(Class<?> config) {
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
context.register(config);
context.refresh();
return null;
}
catch (FatalBeanException ex) {
return ex;
}
}
private @Nullable FailureAnalysis analyzeFailure(@Nullable Exception failure) {
assertThat(failure).isNotNull();
FailureAnalysis analysis = this.analyzer.analyze(failure);
if (analysis != null) {
new LoggingFailureAnalysisReporter().report(analysis);
}
return analysis;
}
@ConfigurationProperties("test")
static class ConstructorBoundProperties {
private final String name;
ConstructorBoundProperties(String name) {
this.name = name;
}
String getName() {
return this.name;
}
}
@Configuration(proxyBeanMethods = false)
@Import(ConstructorBoundProperties.class)
static class ShouldHaveUsedConstructorBindingPropertiesConfiguration {
}
@ConfigurationProperties("test")
static class JavaBeanBoundProperties {
private @Nullable String name;
@Autowired
JavaBeanBoundProperties(String dependency) {
}
@Nullable String getName() {
return this.name;
}
void setName(@Nullable String name) {
this.name = name;
}
}
@Configuration(proxyBeanMethods = false)
@Import(JavaBeanBoundProperties.class)
static class JavaBeanBoundPropertiesConfiguration {
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free