Skip to content

Commit 86fed81

Browse files
committed
Merge branch '3.5.x' into 4.0.x
Closes gh-50498
2 parents 8e337c5 + 596e905 commit 86fed81

2 files changed

Lines changed: 16 additions & 17 deletions

File tree

core/spring-boot-test/src/main/java/org/springframework/boot/test/context/assertj/ApplicationContextAssertProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public interface ApplicationContextAssertProvider<C extends ApplicationContext>
5656
extends ApplicationContext, AssertProvider<ApplicationContextAssert<C>>, Closeable {
5757

5858
/**
59-
* Return an assert for AspectJ.
60-
* @return an AspectJ assert
59+
* Return an assert for AssertJ.
60+
* @return an AssertJ assert
6161
* @deprecated to prevent accidental use. Prefer standard AssertJ
6262
* {@code assertThat(context)...} calls instead.
6363
*/
@@ -132,6 +132,7 @@ static <T extends ApplicationContextAssertProvider<C>, C extends ApplicationCont
132132
Assert.isTrue(type.isInterface(), "'type' must be an interface");
133133
Assert.notNull(contextType, "'contextType' must not be null");
134134
Assert.isTrue(contextType.isInterface(), "'contextType' must be an interface");
135+
Assert.notNull(contextSupplier, "'contextSupplier' must not be null");
135136
Class<?>[] interfaces = merge(new Class<?>[] { type, contextType }, additionalContextInterfaces);
136137
return (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces,
137138
new AssertProviderApplicationContextInvocationHandler(contextType, contextSupplier));

core/spring-boot-test/src/test/java/org/springframework/boot/test/context/assertj/ApplicationContextAssertProviderTests.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020

2121
import org.junit.jupiter.api.BeforeEach;
2222
import org.junit.jupiter.api.Test;
23-
import org.junit.jupiter.api.extension.ExtendWith;
2423
import org.mockito.Mock;
25-
import org.mockito.junit.jupiter.MockitoExtension;
2624

2725
import org.springframework.context.ApplicationContext;
2826
import org.springframework.context.ConfigurableApplicationContext;
@@ -32,19 +30,18 @@
3230
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
3331
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
3432
import static org.mockito.BDDMockito.then;
33+
import static org.mockito.Mockito.mock;
3534

3635
/**
3736
* Tests for {@link ApplicationContextAssertProvider} and
3837
* {@link AssertProviderApplicationContextInvocationHandler}.
3938
*
4039
* @author Phillip Webb
4140
*/
42-
@ExtendWith(MockitoExtension.class)
4341
class ApplicationContextAssertProviderTests {
4442

4543
@Mock
46-
@SuppressWarnings("NullAway.Init")
47-
private ConfigurableApplicationContext mockContext;
44+
private final ConfigurableApplicationContext mockContext = mock();
4845

4946
private RuntimeException startupFailure;
5047

@@ -70,15 +67,7 @@ void getWhenTypeIsNullShouldThrowException() {
7067
}
7168

7269
@Test
73-
@SuppressWarnings("NullAway") // Test null check
7470
void getWhenTypeIsClassShouldThrowException() {
75-
assertThatIllegalArgumentException().isThrownBy(
76-
() -> ApplicationContextAssertProvider.get(null, ApplicationContext.class, this.mockContextSupplier))
77-
.withMessageContaining("'type' must not be null");
78-
}
79-
80-
@Test
81-
void getWhenContextTypeIsNullShouldThrowException() {
8271
assertThatIllegalArgumentException()
8372
.isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContextClass.class,
8473
ApplicationContext.class, this.mockContextSupplier))
@@ -87,21 +76,30 @@ void getWhenContextTypeIsNullShouldThrowException() {
8776

8877
@Test
8978
@SuppressWarnings("NullAway") // Test null check
90-
void getWhenContextTypeIsClassShouldThrowException() {
79+
void getWhenContextTypeIsNullShouldThrowException() {
9180
assertThatIllegalArgumentException()
9281
.isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class, null,
9382
this.mockContextSupplier))
9483
.withMessageContaining("'contextType' must not be null");
9584
}
9685

9786
@Test
98-
void getWhenSupplierIsNullShouldThrowException() {
87+
void getWhenContextTypeIsClassShouldThrowException() {
9988
assertThatIllegalArgumentException()
10089
.isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class,
10190
StaticApplicationContext.class, this.mockContextSupplier))
10291
.withMessageContaining("'contextType' must be an interface");
10392
}
10493

94+
@Test
95+
@SuppressWarnings("NullAway") // Test null check
96+
void getWhenSupplierIsNullShouldThrowException() {
97+
assertThatIllegalArgumentException()
98+
.isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class,
99+
ApplicationContext.class, null))
100+
.withMessageContaining("'contextSupplier' must not be null");
101+
}
102+
105103
@Test
106104
void getWhenContextStartsShouldReturnProxyThatCallsRealMethods() {
107105
ApplicationContextAssertProvider<ApplicationContext> context = get(this.mockContextSupplier);

0 commit comments

Comments
 (0)