@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2012 - 2023 the original author or authors .
* Copyright 2012 - 2024 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -19,6 +19,7 @@ package org.springframework.boot.diagnostics.analyzer;
@@ -19,6 +19,7 @@ package org.springframework.boot.diagnostics.analyzer;
import org.junit.jupiter.api.Test ;
import org.springframework.beans.factory.BeanCreationException ;
import org.springframework.beans.factory.NoUniqueBeanDefinitionException ;
import org.springframework.beans.factory.ObjectProvider ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.boot.diagnostics.FailureAnalysis ;
@ -101,6 +102,21 @@ class NoUniqueBeanDefinitionFailureAnalyzerTests {
@@ -101,6 +102,21 @@ class NoUniqueBeanDefinitionFailureAnalyzerTests {
assertFoundBeans ( failureAnalysis ) ;
}
@Test
void failureAnalysisWithoutInjectionPoints ( ) {
this . context . registerBean ( "beanOne" , TestBean . class ) ;
this . context . register ( DuplicateBeansProducer . class ) ;
this . context . refresh ( ) ;
FailureAnalysis failureAnalysis = analyzeFailure ( new NoUniqueBeanDefinitionException ( TestBean . class , 3 ,
"no TestBeanProvider specified and expected single matching TestBean but found 3: beanOne,beanTwo,xmlBean" ) ) ;
assertThat ( failureAnalysis . getDescription ( ) )
. startsWith ( "A component required a single bean, but 3 were found:" ) ;
assertThat ( failureAnalysis . getDescription ( ) ) . contains ( "beanOne: defined in unknown location" ) ;
assertThat ( failureAnalysis . getDescription ( ) )
. contains ( "beanTwo: defined by method 'beanTwo' in " + DuplicateBeansProducer . class . getName ( ) ) ;
assertThat ( failureAnalysis . getDescription ( ) ) . contains ( "xmlBean: a programmatically registered singleton" ) ;
}
private BeanCreationException createFailure ( Class < ? > consumer ) {
this . context . registerBean ( "beanOne" , TestBean . class ) ;
this . context . register ( DuplicateBeansProducer . class , consumer ) ;
@ -114,7 +130,7 @@ class NoUniqueBeanDefinitionFailureAnalyzerTests {
@@ -114,7 +130,7 @@ class NoUniqueBeanDefinitionFailureAnalyzerTests {
return null ;
}
private FailureAnalysis analyzeFailure ( BeanCreation Exception failure ) {
private FailureAnalysis analyzeFailure ( Exception failure ) {
return this . analyzer . analyze ( failure ) ;
}