Browse Source

Add nullability annotations to tests in module/spring-boot-data-ldap

See gh-47263
pull/47387/head
Moritz Halbritter 3 months ago
parent
commit
5c0d2ee180
  1. 4
      module/spring-boot-data-ldap/build.gradle
  2. 19
      module/spring-boot-data-ldap/src/test/java/org/springframework/boot/data/ldap/autoconfigure/DataLdapRepositoriesAutoConfigurationTests.java

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

@ -38,3 +38,7 @@ dependencies { @@ -38,3 +38,7 @@ dependencies {
testRuntimeOnly("ch.qos.logback:logback-classic")
}
tasks.named("compileTestJava") {
options.nullability.checking = "tests"
}

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

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
package org.springframework.boot.data.ldap.autoconfigure;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
@ -39,31 +40,31 @@ import static org.assertj.core.api.Assertions.assertThat; @@ -39,31 +40,31 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class DataLdapRepositoriesAutoConfigurationTests {
private AnnotationConfigApplicationContext context;
private @Nullable AnnotationConfigApplicationContext context;
@AfterEach
void close() {
if (this.context != null) {
this.context.close();
if (getContext() != null) {
getContext().close();
}
}
@Test
void testDefaultRepositoryConfiguration() {
load(TestConfiguration.class);
assertThat(this.context.getBean(PersonRepository.class)).isNotNull();
assertThat(getContext().getBean(PersonRepository.class)).isNotNull();
}
@Test
void testNoRepositoryConfiguration() {
load(EmptyConfiguration.class);
assertThat(this.context.getBeanNamesForType(PersonRepository.class)).isEmpty();
assertThat(getContext().getBeanNamesForType(PersonRepository.class)).isEmpty();
}
@Test
void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
load(CustomizedConfiguration.class);
assertThat(this.context.getBean(PersonRepository.class)).isNotNull();
assertThat(getContext().getBean(PersonRepository.class)).isNotNull();
}
private void load(Class<?>... configurationClasses) {
@ -75,6 +76,12 @@ class DataLdapRepositoriesAutoConfigurationTests { @@ -75,6 +76,12 @@ class DataLdapRepositoriesAutoConfigurationTests {
this.context.refresh();
}
private AnnotationConfigApplicationContext getContext() {
AnnotationConfigApplicationContext context = this.context;
assertThat(context).isNotNull();
return context;
}
@Configuration(proxyBeanMethods = false)
@TestAutoConfigurationPackage(Person.class)
static class TestConfiguration {

Loading…
Cancel
Save