1616
1717package org .springframework .boot .data .ldap .autoconfigure ;
1818
19+ import org .jspecify .annotations .Nullable ;
1920import org .junit .jupiter .api .AfterEach ;
2021import org .junit .jupiter .api .Test ;
2122
3940 */
4041class DataLdapRepositoriesAutoConfigurationTests {
4142
42- private AnnotationConfigApplicationContext context ;
43+ private @ Nullable AnnotationConfigApplicationContext context ;
4344
4445 @ AfterEach
4546 void close () {
46- if (this . context != null ) {
47- this . context .close ();
47+ if (getContext () != null ) {
48+ getContext () .close ();
4849 }
4950 }
5051
5152 @ Test
5253 void testDefaultRepositoryConfiguration () {
5354 load (TestConfiguration .class );
54- assertThat (this . context .getBean (PersonRepository .class )).isNotNull ();
55+ assertThat (getContext () .getBean (PersonRepository .class )).isNotNull ();
5556 }
5657
5758 @ Test
5859 void testNoRepositoryConfiguration () {
5960 load (EmptyConfiguration .class );
60- assertThat (this . context .getBeanNamesForType (PersonRepository .class )).isEmpty ();
61+ assertThat (getContext () .getBeanNamesForType (PersonRepository .class )).isEmpty ();
6162 }
6263
6364 @ Test
6465 void doesNotTriggerDefaultRepositoryDetectionIfCustomized () {
6566 load (CustomizedConfiguration .class );
66- assertThat (this . context .getBean (PersonRepository .class )).isNotNull ();
67+ assertThat (getContext () .getBean (PersonRepository .class )).isNotNull ();
6768 }
6869
6970 private void load (Class <?>... configurationClasses ) {
@@ -75,6 +76,12 @@ private void load(Class<?>... configurationClasses) {
7576 this .context .refresh ();
7677 }
7778
79+ private AnnotationConfigApplicationContext getContext () {
80+ AnnotationConfigApplicationContext context = this .context ;
81+ assertThat (context ).isNotNull ();
82+ return context ;
83+ }
84+
7885 @ Configuration (proxyBeanMethods = false )
7986 @ TestAutoConfigurationPackage (Person .class )
8087 static class TestConfiguration {
0 commit comments