mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 20:19:06 +00:00
Merge branch '3.5.x' into 4.0.x
Closes gh-50498
This commit is contained in:
+3
-2
@@ -56,8 +56,8 @@ public interface ApplicationContextAssertProvider<C extends ApplicationContext>
|
||||
extends ApplicationContext, AssertProvider<ApplicationContextAssert<C>>, Closeable {
|
||||
|
||||
/**
|
||||
* Return an assert for AspectJ.
|
||||
* @return an AspectJ assert
|
||||
* Return an assert for AssertJ.
|
||||
* @return an AssertJ assert
|
||||
* @deprecated to prevent accidental use. Prefer standard AssertJ
|
||||
* {@code assertThat(context)...} calls instead.
|
||||
*/
|
||||
@@ -132,6 +132,7 @@ public interface ApplicationContextAssertProvider<C extends ApplicationContext>
|
||||
Assert.isTrue(type.isInterface(), "'type' must be an interface");
|
||||
Assert.notNull(contextType, "'contextType' must not be null");
|
||||
Assert.isTrue(contextType.isInterface(), "'contextType' must be an interface");
|
||||
Assert.notNull(contextSupplier, "'contextSupplier' must not be null");
|
||||
Class<?>[] interfaces = merge(new Class<?>[] { type, contextType }, additionalContextInterfaces);
|
||||
return (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces,
|
||||
new AssertProviderApplicationContextInvocationHandler(contextType, contextSupplier));
|
||||
|
||||
+13
-15
@@ -20,9 +20,7 @@ import java.util.function.Supplier;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -32,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link ApplicationContextAssertProvider} and
|
||||
@@ -39,12 +38,10 @@ import static org.mockito.BDDMockito.then;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ApplicationContextAssertProviderTests {
|
||||
|
||||
@Mock
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private ConfigurableApplicationContext mockContext;
|
||||
private final ConfigurableApplicationContext mockContext = mock();
|
||||
|
||||
private RuntimeException startupFailure;
|
||||
|
||||
@@ -70,15 +67,7 @@ class ApplicationContextAssertProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("NullAway") // Test null check
|
||||
void getWhenTypeIsClassShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> ApplicationContextAssertProvider.get(null, ApplicationContext.class, this.mockContextSupplier))
|
||||
.withMessageContaining("'type' must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWhenContextTypeIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContextClass.class,
|
||||
ApplicationContext.class, this.mockContextSupplier))
|
||||
@@ -87,7 +76,7 @@ class ApplicationContextAssertProviderTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("NullAway") // Test null check
|
||||
void getWhenContextTypeIsClassShouldThrowException() {
|
||||
void getWhenContextTypeIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class, null,
|
||||
this.mockContextSupplier))
|
||||
@@ -95,13 +84,22 @@ class ApplicationContextAssertProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWhenSupplierIsNullShouldThrowException() {
|
||||
void getWhenContextTypeIsClassShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class,
|
||||
StaticApplicationContext.class, this.mockContextSupplier))
|
||||
.withMessageContaining("'contextType' must be an interface");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("NullAway") // Test null check
|
||||
void getWhenSupplierIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class,
|
||||
ApplicationContext.class, null))
|
||||
.withMessageContaining("'contextSupplier' must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWhenContextStartsShouldReturnProxyThatCallsRealMethods() {
|
||||
ApplicationContextAssertProvider<ApplicationContext> context = get(this.mockContextSupplier);
|
||||
|
||||
Reference in New Issue
Block a user