|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2021 the original author or authors.
|
|
|
|
* Copyright 2012-2022 the original author or authors.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
@ -43,10 +43,14 @@ import static org.junit.jupiter.api.Assertions.fail;
|
|
|
|
* Tests for {@link BeanCurrentlyInCreationFailureAnalyzer}.
|
|
|
|
* Tests for {@link BeanCurrentlyInCreationFailureAnalyzer}.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Andy Wilkinson
|
|
|
|
* @author Andy Wilkinson
|
|
|
|
|
|
|
|
* @author Scott Frederick
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class BeanCurrentlyInCreationFailureAnalyzerTests {
|
|
|
|
class BeanCurrentlyInCreationFailureAnalyzerTests {
|
|
|
|
|
|
|
|
|
|
|
|
private final BeanCurrentlyInCreationFailureAnalyzer analyzer = new BeanCurrentlyInCreationFailureAnalyzer();
|
|
|
|
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final BeanCurrentlyInCreationFailureAnalyzer analyzer = new BeanCurrentlyInCreationFailureAnalyzer(
|
|
|
|
|
|
|
|
this.context.getBeanFactory());
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void cyclicBeanMethods() throws IOException {
|
|
|
|
void cyclicBeanMethods() throws IOException {
|
|
|
@ -131,13 +135,13 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void cycleWithCircularReferencesAllowed() throws IOException {
|
|
|
|
void cycleWithCircularReferencesAllowed() {
|
|
|
|
FailureAnalysis analysis = performAnalysis(CyclicBeanMethodsConfiguration.class, true);
|
|
|
|
FailureAnalysis analysis = performAnalysis(CyclicBeanMethodsConfiguration.class, true);
|
|
|
|
assertThat(analysis.getAction()).contains("Despite circular references being allowed");
|
|
|
|
assertThat(analysis.getAction()).contains("Despite circular references being allowed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void cycleWithCircularReferencesProhibited() throws IOException {
|
|
|
|
void cycleWithCircularReferencesProhibited() {
|
|
|
|
FailureAnalysis analysis = performAnalysis(CyclicBeanMethodsConfiguration.class, false);
|
|
|
|
FailureAnalysis analysis = performAnalysis(CyclicBeanMethodsConfiguration.class, false);
|
|
|
|
assertThat(analysis.getAction()).contains("As a last resort");
|
|
|
|
assertThat(analysis.getAction()).contains("As a last resort");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -159,13 +163,12 @@ class BeanCurrentlyInCreationFailureAnalyzerTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Exception createFailure(Class<?> configuration, boolean allowCircularReferences) {
|
|
|
|
private Exception createFailure(Class<?> configuration, boolean allowCircularReferences) {
|
|
|
|
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
|
|
|
|
try {
|
|
|
|
context.register(configuration);
|
|
|
|
this.context.register(configuration);
|
|
|
|
AbstractAutowireCapableBeanFactory beanFactory = (AbstractAutowireCapableBeanFactory) context
|
|
|
|
AbstractAutowireCapableBeanFactory beanFactory = (AbstractAutowireCapableBeanFactory) this.context
|
|
|
|
.getBeanFactory();
|
|
|
|
.getBeanFactory();
|
|
|
|
this.analyzer.setBeanFactory(beanFactory);
|
|
|
|
|
|
|
|
beanFactory.setAllowCircularReferences(allowCircularReferences);
|
|
|
|
beanFactory.setAllowCircularReferences(allowCircularReferences);
|
|
|
|
context.refresh();
|
|
|
|
this.context.refresh();
|
|
|
|
fail("Expected failure did not occur");
|
|
|
|
fail("Expected failure did not occur");
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|