|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2022 the original author or authors. |
| 2 | + * Copyright 2012-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
21 | 21 | import org.junit.jupiter.api.extension.ExtendWith;
|
22 | 22 |
|
23 | 23 | import org.springframework.beans.factory.BeanFactory;
|
24 |
| -import org.springframework.beans.factory.BeanFactoryAware; |
25 |
| -import org.springframework.boot.testsupport.system.CapturedOutput; |
26 | 24 | import org.springframework.boot.testsupport.system.OutputCaptureExtension;
|
27 |
| -import org.springframework.context.EnvironmentAware; |
28 | 25 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
29 | 26 | import org.springframework.core.env.Environment;
|
30 | 27 | import org.springframework.core.test.io.support.MockSpringFactoriesLoader;
|
31 | 28 |
|
32 | 29 | import static org.assertj.core.api.Assertions.assertThat;
|
33 |
| -import static org.mockito.ArgumentMatchers.same; |
34 | 30 | import static org.mockito.BDDMockito.then;
|
35 | 31 | import static org.mockito.Mockito.mock;
|
36 | 32 | import static org.mockito.Mockito.times;
|
|
45 | 41 | @ExtendWith(OutputCaptureExtension.class)
|
46 | 42 | class FailureAnalyzersTests {
|
47 | 43 |
|
48 |
| - private static AwareFailureAnalyzer failureAnalyzer; |
| 44 | + private static FailureAnalyzer failureAnalyzer; |
49 | 45 |
|
50 | 46 | private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
51 | 47 |
|
52 | 48 | @BeforeEach
|
53 | 49 | void configureMock() {
|
54 |
| - failureAnalyzer = mock(AwareFailureAnalyzer.class); |
| 50 | + failureAnalyzer = mock(FailureAnalyzer.class); |
55 | 51 | }
|
56 | 52 |
|
57 | 53 | @Test
|
58 | 54 | void analyzersAreLoadedAndCalled() {
|
59 | 55 | RuntimeException failure = new RuntimeException();
|
60 |
| - analyzeAndReport(failure, BasicFailureAnalyzer.class, StandardAwareFailureAnalyzer.class); |
| 56 | + analyzeAndReport(failure, BasicFailureAnalyzer.class, BasicFailureAnalyzer.class); |
61 | 57 | then(failureAnalyzer).should(times(2)).analyze(failure);
|
62 | 58 | }
|
63 | 59 |
|
64 | 60 | @Test
|
65 |
| - void analyzerIsConstructedWithBeanFactory(CapturedOutput output) { |
| 61 | + void analyzerIsConstructedWithBeanFactory() { |
66 | 62 | RuntimeException failure = new RuntimeException();
|
67 | 63 | analyzeAndReport(failure, BasicFailureAnalyzer.class, BeanFactoryConstructorFailureAnalyzer.class);
|
68 | 64 | then(failureAnalyzer).should(times(2)).analyze(failure);
|
69 |
| - assertThat(output).doesNotContain("implement BeanFactoryAware or EnvironmentAware"); |
70 | 65 | }
|
71 | 66 |
|
72 | 67 | @Test
|
73 |
| - void analyzerIsConstructedWithEnvironment(CapturedOutput output) { |
| 68 | + void analyzerIsConstructedWithEnvironment() { |
74 | 69 | RuntimeException failure = new RuntimeException();
|
75 | 70 | analyzeAndReport(failure, BasicFailureAnalyzer.class, EnvironmentConstructorFailureAnalyzer.class);
|
76 | 71 | then(failureAnalyzer).should(times(2)).analyze(failure);
|
77 |
| - assertThat(output).doesNotContain("implement BeanFactoryAware or EnvironmentAware"); |
78 |
| - } |
79 |
| - |
80 |
| - @Test |
81 |
| - void beanFactoryIsInjectedIntoBeanFactoryAwareFailureAnalyzers(CapturedOutput output) { |
82 |
| - RuntimeException failure = new RuntimeException(); |
83 |
| - analyzeAndReport(failure, BasicFailureAnalyzer.class, StandardAwareFailureAnalyzer.class); |
84 |
| - then(failureAnalyzer).should().setBeanFactory(same(this.context.getBeanFactory())); |
85 |
| - assertThat(output).contains("FailureAnalyzers [" + StandardAwareFailureAnalyzer.class.getName() |
86 |
| - + "] implement BeanFactoryAware or EnvironmentAware."); |
87 |
| - } |
88 |
| - |
89 |
| - @Test |
90 |
| - void environmentIsInjectedIntoEnvironmentAwareFailureAnalyzers() { |
91 |
| - RuntimeException failure = new RuntimeException(); |
92 |
| - analyzeAndReport(failure, BasicFailureAnalyzer.class, StandardAwareFailureAnalyzer.class); |
93 |
| - then(failureAnalyzer).should().setEnvironment(same(this.context.getEnvironment())); |
94 | 72 | }
|
95 | 73 |
|
96 | 74 | @Test
|
@@ -170,22 +148,4 @@ static class EnvironmentConstructorFailureAnalyzer extends BasicFailureAnalyzer
|
170 | 148 |
|
171 | 149 | }
|
172 | 150 |
|
173 |
| - interface AwareFailureAnalyzer extends BeanFactoryAware, EnvironmentAware, FailureAnalyzer { |
174 |
| - |
175 |
| - } |
176 |
| - |
177 |
| - static class StandardAwareFailureAnalyzer extends BasicFailureAnalyzer implements AwareFailureAnalyzer { |
178 |
| - |
179 |
| - @Override |
180 |
| - public void setEnvironment(Environment environment) { |
181 |
| - failureAnalyzer.setEnvironment(environment); |
182 |
| - } |
183 |
| - |
184 |
| - @Override |
185 |
| - public void setBeanFactory(BeanFactory beanFactory) { |
186 |
| - failureAnalyzer.setBeanFactory(beanFactory); |
187 |
| - } |
188 |
| - |
189 |
| - } |
190 |
| - |
191 | 151 | }
|
0 commit comments