@ -1,5 +1,5 @@
@@ -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,16 +21,12 @@ import org.junit.jupiter.api.Test;
@@ -21,16 +21,12 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith ;
import org.springframework.beans.factory.BeanFactory ;
import org.springframework.beans.factory.BeanFactoryAware ;
import org.springframework.boot.testsupport.system.CapturedOutput ;
import org.springframework.boot.testsupport.system.OutputCaptureExtension ;
import org.springframework.context.EnvironmentAware ;
import org.springframework.context.annotation.AnnotationConfigApplicationContext ;
import org.springframework.core.env.Environment ;
import org.springframework.core.test.io.support.MockSpringFactoriesLoader ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.mockito.ArgumentMatchers.same ;
import static org.mockito.BDDMockito.then ;
import static org.mockito.Mockito.mock ;
import static org.mockito.Mockito.times ;
@ -45,52 +41,34 @@ import static org.mockito.Mockito.times;
@@ -45,52 +41,34 @@ import static org.mockito.Mockito.times;
@ExtendWith ( OutputCaptureExtension . class )
class FailureAnalyzersTests {
private static Aware FailureAnalyzer failureAnalyzer ;
private static FailureAnalyzer failureAnalyzer ;
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ( ) ;
@BeforeEach
void configureMock ( ) {
failureAnalyzer = mock ( Aware FailureAnalyzer. class ) ;
failureAnalyzer = mock ( FailureAnalyzer . class ) ;
}
@Test
void analyzersAreLoadedAndCalled ( ) {
RuntimeException failure = new RuntimeException ( ) ;
analyzeAndReport ( failure , BasicFailureAnalyzer . class , StandardAware FailureAnalyzer. class ) ;
analyzeAndReport ( failure , BasicFailureAnalyzer . class , Basic FailureAnalyzer. class ) ;
then ( failureAnalyzer ) . should ( times ( 2 ) ) . analyze ( failure ) ;
}
@Test
void analyzerIsConstructedWithBeanFactory ( CapturedOutput output ) {
void analyzerIsConstructedWithBeanFactory ( ) {
RuntimeException failure = new RuntimeException ( ) ;
analyzeAndReport ( failure , BasicFailureAnalyzer . class , BeanFactoryConstructorFailureAnalyzer . class ) ;
then ( failureAnalyzer ) . should ( times ( 2 ) ) . analyze ( failure ) ;
assertThat ( output ) . doesNotContain ( "implement BeanFactoryAware or EnvironmentAware" ) ;
}
@Test
void analyzerIsConstructedWithEnvironment ( CapturedOutput output ) {
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
void beanFactoryIsInjectedIntoBeanFactoryAwareFailureAnalyzers ( CapturedOutput output ) {
RuntimeException failure = new RuntimeException ( ) ;
analyzeAndReport ( failure , BasicFailureAnalyzer . class , StandardAwareFailureAnalyzer . class ) ;
then ( failureAnalyzer ) . should ( ) . setBeanFactory ( same ( this . context . getBeanFactory ( ) ) ) ;
assertThat ( output ) . contains ( "FailureAnalyzers [" + StandardAwareFailureAnalyzer . class . getName ( )
+ "] implement BeanFactoryAware or EnvironmentAware." ) ;
}
@Test
void environmentIsInjectedIntoEnvironmentAwareFailureAnalyzers ( ) {
RuntimeException failure = new RuntimeException ( ) ;
analyzeAndReport ( failure , BasicFailureAnalyzer . class , StandardAwareFailureAnalyzer . class ) ;
then ( failureAnalyzer ) . should ( ) . setEnvironment ( same ( this . context . getEnvironment ( ) ) ) ;
}
@Test
@ -170,22 +148,4 @@ class FailureAnalyzersTests {
@@ -170,22 +148,4 @@ class FailureAnalyzersTests {
}
interface AwareFailureAnalyzer extends BeanFactoryAware , EnvironmentAware , FailureAnalyzer {
}
static class StandardAwareFailureAnalyzer extends BasicFailureAnalyzer implements AwareFailureAnalyzer {
@Override
public void setEnvironment ( Environment environment ) {
failureAnalyzer . setEnvironment ( environment ) ;
}
@Override
public void setBeanFactory ( BeanFactory beanFactory ) {
failureAnalyzer . setBeanFactory ( beanFactory ) ;
}
}
}