2020
2121import org .junit .jupiter .api .BeforeEach ;
2222import org .junit .jupiter .api .Test ;
23- import org .junit .jupiter .api .extension .ExtendWith ;
2423import org .mockito .Mock ;
25- import org .mockito .junit .jupiter .MockitoExtension ;
2624
2725import org .springframework .context .ApplicationContext ;
2826import org .springframework .context .ConfigurableApplicationContext ;
3230import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
3331import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
3432import 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 )
4341class 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