Polish "Remove deprecated support for FailureAnalyzer setter injection"

See gh-38322
This commit is contained in:
Andy Wilkinson
2024-01-11 14:08:03 +00:00
parent 697b252957
commit 9b8c45c35d
2 changed files with 18 additions and 9 deletions

View File

@@ -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.
@@ -58,7 +58,12 @@ final class FailureAnalyzers implements SpringBootExceptionReporter {
FailureAnalyzers(ConfigurableApplicationContext context, SpringFactoriesLoader springFactoriesLoader) {
this.springFactoriesLoader = springFactoriesLoader;
this.analyzers = springFactoriesLoader.load(FailureAnalyzer.class, getArgumentResolver(context),
this.analyzers = loadFailureAnalyzers(context, this.springFactoriesLoader);
}
private static List<FailureAnalyzer> loadFailureAnalyzers(ConfigurableApplicationContext context,
SpringFactoriesLoader springFactoriesLoader) {
return springFactoriesLoader.load(FailureAnalyzer.class, getArgumentResolver(context),
FailureHandler.logging(logger));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 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.
@@ -21,7 +21,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.boot.testsupport.system.CapturedOutput;
import org.springframework.boot.testsupport.system.OutputCaptureExtension;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.Environment;
@@ -52,19 +51,24 @@ class FailureAnalyzersTests {
}
@Test
void analyzerIsConstructedWithBeanFactory(CapturedOutput output) {
void analyzersAreLoadedAndCalled() {
RuntimeException failure = new RuntimeException();
analyzeAndReport(failure, BasicFailureAnalyzer.class, BeanFactoryConstructorFailureAnalyzer.class);
analyzeAndReport(failure, BasicFailureAnalyzer.class, BasicFailureAnalyzer.class);
then(failureAnalyzer).should(times(2)).analyze(failure);
assertThat(output).doesNotContain("implement BeanFactoryAware or EnvironmentAware");
}
@Test
void analyzerIsConstructedWithEnvironment(CapturedOutput output) {
void analyzerIsConstructedWithBeanFactory() {
RuntimeException failure = new RuntimeException();
analyzeAndReport(failure, BasicFailureAnalyzer.class, BeanFactoryConstructorFailureAnalyzer.class);
then(failureAnalyzer).should(times(2)).analyze(failure);
}
@Test
void analyzerIsConstructedWithEnvironment() {
RuntimeException failure = new RuntimeException();
analyzeAndReport(failure, BasicFailureAnalyzer.class, EnvironmentConstructorFailureAnalyzer.class);
then(failureAnalyzer).should(times(2)).analyze(failure);
assertThat(output).doesNotContain("implement BeanFactoryAware or EnvironmentAware");
}
@Test