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
24
import org .springframework .boot .testsupport .system .CapturedOutput ;
26
25
import org .springframework .boot .testsupport .system .OutputCaptureExtension ;
27
- import org .springframework .context .EnvironmentAware ;
28
26
import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
29
27
import org .springframework .core .env .Environment ;
30
28
import org .springframework .core .test .io .support .MockSpringFactoriesLoader ;
31
29
32
30
import static org .assertj .core .api .Assertions .assertThat ;
33
- import static org .mockito .ArgumentMatchers .same ;
34
31
import static org .mockito .BDDMockito .then ;
35
32
import static org .mockito .Mockito .mock ;
36
33
import static org .mockito .Mockito .times ;
45
42
@ ExtendWith (OutputCaptureExtension .class )
46
43
class FailureAnalyzersTests {
47
44
48
- private static AwareFailureAnalyzer failureAnalyzer ;
45
+ private static FailureAnalyzer failureAnalyzer ;
49
46
50
47
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ();
51
48
52
49
@ BeforeEach
53
50
void configureMock () {
54
- failureAnalyzer = mock (AwareFailureAnalyzer .class );
55
- }
56
-
57
- @ Test
58
- void analyzersAreLoadedAndCalled () {
59
- RuntimeException failure = new RuntimeException ();
60
- analyzeAndReport (failure , BasicFailureAnalyzer .class , StandardAwareFailureAnalyzer .class );
61
- then (failureAnalyzer ).should (times (2 )).analyze (failure );
51
+ failureAnalyzer = mock (FailureAnalyzer .class );
62
52
}
63
53
64
54
@ Test
@@ -77,22 +67,6 @@ void analyzerIsConstructedWithEnvironment(CapturedOutput output) {
77
67
assertThat (output ).doesNotContain ("implement BeanFactoryAware or EnvironmentAware" );
78
68
}
79
69
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
- }
95
-
96
70
@ Test
97
71
void analyzerThatFailsDuringInitializationDoesNotPreventOtherAnalyzersFromBeingCalled () {
98
72
RuntimeException failure = new RuntimeException ();
@@ -170,22 +144,4 @@ static class EnvironmentConstructorFailureAnalyzer extends BasicFailureAnalyzer
170
144
171
145
}
172
146
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
147
}
0 commit comments