Adapt NoSuchBeanDefinitionFailureAnalyzer to framework change

This commit adapts to a Spring Framework change based on SPR-11419 and
SPR-15338. Rather than throwing an exception when injecting a List or
Map of a candidate bean that is not present, an empty collection/map is
injected.
pull/13870/merge
Stephane Nicoll 6 years ago
parent f3ef7caf09
commit c98bb40136

@ -115,14 +115,6 @@ class NoSuchBeanDefinitionFailureAnalyzer
}
private Class<?> extractBeanType(ResolvableType resolvableType) {
ResolvableType collectionType = resolvableType.asCollection();
if (!collectionType.equals(ResolvableType.NONE)) {
return collectionType.getGeneric(0).getRawClass();
}
ResolvableType mapType = resolvableType.asMap();
if (!mapType.equals(ResolvableType.NONE)) {
return mapType.getGeneric(1).getRawClass();
}
return resolvableType.getRawClass();
}

@ -17,9 +17,7 @@
package org.springframework.boot.autoconfigure.diagnostics.analyzer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.junit.Test;
@ -83,30 +81,6 @@ public class NoSuchBeanDefinitionFailureAnalyzerTests {
assertActionMissingType(analysis, String.class);
}
@Test
public void failureAnalysisForMissingCollectionType() {
FailureAnalysis analysis = analyzeFailure(
createFailure(StringCollectionConfiguration.class));
assertDescriptionConstructorMissingType(analysis, StringCollectionHandler.class,
0, String.class);
assertBeanMethodDisabled(analysis,
"did not find property 'spring.string.enabled'",
TestPropertyAutoConfiguration.class, "string");
assertActionMissingType(analysis, String.class);
}
@Test
public void failureAnalysisForMissingMapType() {
FailureAnalysis analysis = analyzeFailure(
createFailure(StringMapConfiguration.class));
assertDescriptionConstructorMissingType(analysis, StringMapHandler.class, 0,
String.class);
assertBeanMethodDisabled(analysis,
"did not find property 'spring.string.enabled'",
TestPropertyAutoConfiguration.class, "string");
assertActionMissingType(analysis, String.class);
}
@Test
public void failureAnalysisForMissingPropertySubType() {
FailureAnalysis analysis = analyzeFailure(
@ -281,20 +255,6 @@ public class NoSuchBeanDefinitionFailureAnalyzerTests {
}
@Configuration
@ImportAutoConfiguration(TestPropertyAutoConfiguration.class)
@Import(StringCollectionHandler.class)
protected static class StringCollectionConfiguration {
}
@Configuration
@ImportAutoConfiguration(TestPropertyAutoConfiguration.class)
@Import(StringMapHandler.class)
protected static class StringMapConfiguration {
}
@Configuration
@ImportAutoConfiguration(TestPropertyAutoConfiguration.class)
@Import(NumberHandler.class)
@ -402,18 +362,4 @@ public class NoSuchBeanDefinitionFailureAnalyzerTests {
}
protected static class StringCollectionHandler {
public StringCollectionHandler(Collection<String> collection) {
}
}
protected static class StringMapHandler {
public StringMapHandler(Map<String, String> map) {
}
}
}

Loading…
Cancel
Save