Skip to content

Commit 5c0d2ee

Browse files
committed
Add nullability annotations to tests in module/spring-boot-data-ldap
See gh-47263
1 parent bb19585 commit 5c0d2ee

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

module/spring-boot-data-ldap/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ dependencies {
3838

3939
testRuntimeOnly("ch.qos.logback:logback-classic")
4040
}
41+
42+
tasks.named("compileTestJava") {
43+
options.nullability.checking = "tests"
44+
}

module/spring-boot-data-ldap/src/test/java/org/springframework/boot/data/ldap/autoconfigure/DataLdapRepositoriesAutoConfigurationTests.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.data.ldap.autoconfigure;
1818

19+
import org.jspecify.annotations.Nullable;
1920
import org.junit.jupiter.api.AfterEach;
2021
import org.junit.jupiter.api.Test;
2122

@@ -39,31 +40,31 @@
3940
*/
4041
class 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

Comments
 (0)