Allow ApplicationContextRunner to return non-refreshed context
Add `AbstractApplicationContextRunner.prepare` which can be used to test an `ApplicationContext` that has been prepared but not refreshed. Closes gh-31302
This commit is contained in:
@@ -47,6 +47,7 @@ import org.springframework.util.ClassUtils;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIOException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
* Abstract tests for {@link AbstractApplicationContextRunner} implementations.
|
||||
@@ -238,6 +239,16 @@ abstract class AbstractApplicationContextRunnerTests<T extends AbstractApplicati
|
||||
.run((context) -> assertThat(context).hasSingleBean(ProfileConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void prepareDoesNotRefreshContext() {
|
||||
get().withUserConfiguration(FooConfig.class).prepare((context) -> {
|
||||
assertThatIllegalStateException().isThrownBy(() -> context.getBean(String.class))
|
||||
.withMessageContaining("not been refreshed");
|
||||
context.getSourceApplicationContext().refresh();
|
||||
assertThat(context.getBean(String.class)).isEqualTo("foo");
|
||||
});
|
||||
}
|
||||
|
||||
protected abstract T get();
|
||||
|
||||
private static void throwCheckedException(String message) throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user