Add nullability annotations to tests in module/spring-boot-data-commons
See gh-47263
This commit is contained in:
parent
4a62872d63
commit
af2436de84
|
@ -45,3 +45,7 @@ dependencies {
|
|||
testRuntimeOnly("com.zaxxer:HikariCP")
|
||||
testRuntimeOnly("jakarta.servlet:jakarta.servlet-api")
|
||||
}
|
||||
|
||||
tasks.named("compileTestJava") {
|
||||
options.nullability.checking = "tests"
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.io.IOException;
|
|||
import java.lang.reflect.Method;
|
||||
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.repository.Repository;
|
||||
|
@ -80,9 +81,10 @@ class DefaultRepositoryTagsProviderTests {
|
|||
return createInvocation(null);
|
||||
}
|
||||
|
||||
private RepositoryMethodInvocation createInvocation(Throwable error) {
|
||||
private RepositoryMethodInvocation createInvocation(@Nullable Throwable error) {
|
||||
Class<?> repositoryInterface = ExampleRepository.class;
|
||||
Method method = ReflectionUtils.findMethod(repositoryInterface, "findById", long.class);
|
||||
assertThat(method).isNotNull();
|
||||
RepositoryMethodInvocationResult result = mock(RepositoryMethodInvocationResult.class);
|
||||
given(result.getState()).willReturn((error != null) ? State.ERROR : State.SUCCESS);
|
||||
given(result.getError()).willReturn(error);
|
||||
|
|
|
@ -90,6 +90,7 @@ class MetricsRepositoryMethodInvocationListenerTests {
|
|||
|
||||
private RepositoryMethodInvocation createInvocation(Class<?> repositoryInterface) {
|
||||
Method method = ReflectionUtils.findMethod(repositoryInterface, "findById", long.class);
|
||||
assertThat(method).isNotNull();
|
||||
RepositoryMethodInvocationResult result = mock(RepositoryMethodInvocationResult.class);
|
||||
given(result.getState()).willReturn(State.SUCCESS);
|
||||
return new RepositoryMethodInvocation(repositoryInterface, method, result, 0);
|
||||
|
|
|
@ -37,6 +37,7 @@ class TimedAnnotationsTests {
|
|||
void getWhenNoneReturnsEmptySet() {
|
||||
Object bean = new None();
|
||||
Method method = ReflectionUtils.findMethod(bean.getClass(), "handle");
|
||||
assertThat(method).isNotNull();
|
||||
Set<Timed> annotations = TimedAnnotations.get(method, bean.getClass());
|
||||
assertThat(annotations).isEmpty();
|
||||
}
|
||||
|
@ -45,6 +46,7 @@ class TimedAnnotationsTests {
|
|||
void getWhenOnMethodReturnsMethodAnnotations() {
|
||||
Object bean = new OnMethod();
|
||||
Method method = ReflectionUtils.findMethod(bean.getClass(), "handle");
|
||||
assertThat(method).isNotNull();
|
||||
Set<Timed> annotations = TimedAnnotations.get(method, bean.getClass());
|
||||
assertThat(annotations).extracting(Timed::value).containsOnly("y", "z");
|
||||
}
|
||||
|
@ -53,6 +55,7 @@ class TimedAnnotationsTests {
|
|||
void getWhenNonOnMethodReturnsBeanAnnotations() {
|
||||
Object bean = new OnBean();
|
||||
Method method = ReflectionUtils.findMethod(bean.getClass(), "handle");
|
||||
assertThat(method).isNotNull();
|
||||
Set<Timed> annotations = TimedAnnotations.get(method, bean.getClass());
|
||||
assertThat(annotations).extracting(Timed::value).containsOnly("y", "z");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue