File tree Expand file tree Collapse file tree 4 files changed +25
-50
lines changed
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure Expand file tree Collapse file tree 4 files changed +25
-50
lines changed Original file line number Diff line number Diff line change 16
16
17
17
package org .springframework .boot .autoconfigure .condition ;
18
18
19
- import org .junit .After ;
20
19
import org .junit .Test ;
21
20
import org .junit .runner .RunWith ;
22
21
22
+ import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
23
23
import org .springframework .boot .testsupport .runner .classpath .ClassPathExclusions ;
24
24
import org .springframework .boot .testsupport .runner .classpath .ModifiedClassPathRunner ;
25
25
import org .springframework .cache .caffeine .CaffeineCacheManager ;
26
- import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
27
26
import org .springframework .context .annotation .Bean ;
28
27
import org .springframework .context .annotation .Configuration ;
29
28
40
39
@ ClassPathExclusions ("spring-context-support-*.jar" )
41
40
public class ConditionalOnMissingBeanWithFilteredClasspathTests {
42
41
43
- private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ();
44
-
45
- @ After
46
- public void closeContext () {
47
- this .context .close ();
48
- }
42
+ private final ApplicationContextRunner contextRunner = new ApplicationContextRunner ()
43
+ .withUserConfiguration (OnBeanTypeConfiguration .class );
49
44
50
45
@ Test
51
46
public void testNameOnMissingBeanTypeWithMissingImport () {
52
- this .context .register (OnBeanTypeConfiguration .class );
53
- this .context .refresh ();
54
- assertThat (this .context .containsBean ("foo" )).isTrue ();
47
+ this .contextRunner .run ((context ) -> assertThat (context ).hasBean ("foo" ));
55
48
}
56
49
57
50
@ Configuration (proxyBeanMethods = false )
Original file line number Diff line number Diff line change 16
16
17
17
package org .springframework .boot .autoconfigure .http ;
18
18
19
- import org .junit .After ;
20
19
import org .junit .Test ;
21
20
import org .junit .runner .RunWith ;
22
21
22
+ import org .springframework .boot .autoconfigure .AutoConfigurations ;
23
+ import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
23
24
import org .springframework .boot .testsupport .runner .classpath .ClassPathExclusions ;
24
25
import org .springframework .boot .testsupport .runner .classpath .ModifiedClassPathRunner ;
25
- import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
26
26
27
27
import static org .assertj .core .api .Assertions .assertThat ;
28
28
36
36
@ ClassPathExclusions ("jackson-*.jar" )
37
37
public class HttpMessageConvertersAutoConfigurationWithoutJacksonTests {
38
38
39
- private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ();
40
-
41
- @ After
42
- public void close () {
43
- if (this .context != null ) {
44
- this .context .close ();
45
- }
46
- }
39
+ private final ApplicationContextRunner contextRunner = new ApplicationContextRunner ()
40
+ .withConfiguration (AutoConfigurations .of (HttpMessageConvertersAutoConfiguration .class ));
47
41
48
42
@ Test
49
43
public void autoConfigurationWorksWithSpringHateoasButWithoutJackson () {
50
- this .context .register (HttpMessageConvertersAutoConfiguration .class );
51
- this .context .refresh ();
52
- assertThat (this .context .getBeansOfType (HttpMessageConverters .class )).hasSize (1 );
44
+ this .contextRunner .run ((context ) -> assertThat (context ).hasSingleBean (HttpMessageConverters .class ));
53
45
}
54
46
55
47
}
Original file line number Diff line number Diff line change 18
18
19
19
import javax .validation .Validator ;
20
20
21
- import org .junit .After ;
22
21
import org .junit .Test ;
23
22
import org .junit .runner .RunWith ;
24
23
24
+ import org .springframework .boot .autoconfigure .AutoConfigurations ;
25
+ import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
25
26
import org .springframework .boot .testsupport .runner .classpath .ClassPathExclusions ;
26
27
import org .springframework .boot .testsupport .runner .classpath .ModifiedClassPathRunner ;
27
- import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
28
28
import org .springframework .validation .beanvalidation .MethodValidationPostProcessor ;
29
29
30
30
import static org .assertj .core .api .Assertions .assertThat ;
39
39
@ ClassPathExclusions ({ "tomcat-embed-el-*.jar" , "el-api-*.jar" })
40
40
public class ValidationAutoConfigurationWithHibernateValidatorMissingElImplTests {
41
41
42
- private AnnotationConfigApplicationContext context ;
43
-
44
- @ After
45
- public void close () {
46
- if (this .context != null ) {
47
- this .context .close ();
48
- }
49
- }
42
+ private final ApplicationContextRunner contextRunner = new ApplicationContextRunner ()
43
+ .withConfiguration (AutoConfigurations .of (ValidationAutoConfiguration .class ));
50
44
51
45
@ Test
52
46
public void missingElDependencyIsTolerated () {
53
- this .context = new AnnotationConfigApplicationContext (ValidationAutoConfiguration .class );
54
- assertThat (this .context .getBeansOfType (Validator .class )).hasSize (1 );
55
- assertThat (this .context .getBeansOfType (MethodValidationPostProcessor .class )).hasSize (1 );
47
+ this .contextRunner .run ((context ) -> {
48
+ assertThat (context ).hasSingleBean (Validator .class );
49
+ assertThat (context ).hasSingleBean (MethodValidationPostProcessor .class );
50
+ });
56
51
}
57
52
58
53
}
Original file line number Diff line number Diff line change 18
18
19
19
import javax .validation .Validator ;
20
20
21
- import org .junit .After ;
22
21
import org .junit .Test ;
23
22
import org .junit .runner .RunWith ;
24
23
24
+ import org .springframework .boot .autoconfigure .AutoConfigurations ;
25
+ import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
25
26
import org .springframework .boot .testsupport .runner .classpath .ClassPathExclusions ;
26
27
import org .springframework .boot .testsupport .runner .classpath .ModifiedClassPathRunner ;
27
- import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
28
28
import org .springframework .validation .beanvalidation .MethodValidationPostProcessor ;
29
29
30
30
import static org .assertj .core .api .Assertions .assertThat ;
38
38
@ ClassPathExclusions ("hibernate-validator-*.jar" )
39
39
public class ValidationAutoConfigurationWithoutValidatorTests {
40
40
41
- private AnnotationConfigApplicationContext context ;
42
-
43
- @ After
44
- public void close () {
45
- if (this .context != null ) {
46
- this .context .close ();
47
- }
48
- }
41
+ private final ApplicationContextRunner contextRunner = new ApplicationContextRunner ()
42
+ .withConfiguration (AutoConfigurations .of (ValidationAutoConfiguration .class ));
49
43
50
44
@ Test
51
45
public void validationIsDisabled () {
52
- this .context = new AnnotationConfigApplicationContext (ValidationAutoConfiguration .class );
53
- assertThat (this .context .getBeansOfType (Validator .class )).isEmpty ();
54
- assertThat (this .context .getBeansOfType (MethodValidationPostProcessor .class )).isEmpty ();
46
+ this .contextRunner .run ((context ) -> {
47
+ assertThat (context ).doesNotHaveBean (Validator .class );
48
+ assertThat (context ).doesNotHaveBean (MethodValidationPostProcessor .class );
49
+ });
55
50
}
56
51
57
52
}
You can’t perform that action at this time.
0 commit comments