Skip to content

Commit 910a8a4

Browse files
committed
Add nullability annotations to module/spring-boot-graphql-test
See gh-46587
1 parent 8d2389a commit 910a8a4

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

module/spring-boot-graphql-test/src/main/java/org/springframework/boot/test/graphql/tester/HttpGraphQlTesterContextCustomizer.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package org.springframework.boot.test.graphql.tester;
1818

19+
import jakarta.servlet.ServletContext;
20+
import org.jspecify.annotations.Nullable;
21+
1922
import org.springframework.aot.AotDetector;
2023
import org.springframework.beans.BeansException;
2124
import org.springframework.beans.factory.BeanFactory;
@@ -41,6 +44,7 @@
4144
import org.springframework.test.context.MergedContextConfiguration;
4245
import org.springframework.test.context.TestContextAnnotationUtils;
4346
import org.springframework.test.web.reactive.server.WebTestClient;
47+
import org.springframework.util.Assert;
4448
import org.springframework.util.ClassUtils;
4549
import org.springframework.util.StringUtils;
4650
import org.springframework.web.context.WebApplicationContext;
@@ -59,6 +63,7 @@ public void customizeContext(ConfigurableApplicationContext context, MergedConte
5963
}
6064
SpringBootTest springBootTest = TestContextAnnotationUtils.findMergedAnnotation(mergedConfig.getTestClass(),
6165
SpringBootTest.class);
66+
Assert.state(springBootTest != null, "'springBootTest' must not be null");
6267
if (springBootTest.webEnvironment().isEmbedded()) {
6368
registerHttpGraphQlTester(context);
6469
}
@@ -78,7 +83,7 @@ private void registerHttpGraphQlTester(BeanDefinitionRegistry registry) {
7883
}
7984

8085
@Override
81-
public boolean equals(Object obj) {
86+
public boolean equals(@Nullable Object obj) {
8287
return (obj != null) && (obj.getClass() == getClass());
8388
}
8489

@@ -89,6 +94,7 @@ public int hashCode() {
8994

9095
static class HttpGraphQlTesterRegistrar implements BeanDefinitionRegistryPostProcessor, Ordered, BeanFactoryAware {
9196

97+
@SuppressWarnings("NullAway.Init")
9298
private BeanFactory beanFactory;
9399

94100
@Override
@@ -126,9 +132,10 @@ public static class HttpGraphQlTesterFactory implements FactoryBean<HttpGraphQlT
126132

127133
private static final String REACTIVE_APPLICATION_CONTEXT_CLASS = "org.springframework.boot.web.context.reactive.ReactiveWebApplicationContext";
128134

135+
@SuppressWarnings("NullAway.Init")
129136
private ApplicationContext applicationContext;
130137

131-
private HttpGraphQlTester object;
138+
private @Nullable HttpGraphQlTester object;
132139

133140
@Override
134141
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
@@ -183,7 +190,9 @@ private String deduceServerBasePath() {
183190

184191
}
185192
else if (webApplicationType == WebApplicationType.SERVLET) {
186-
serverBasePath = ((WebApplicationContext) this.applicationContext).getServletContext().getContextPath();
193+
ServletContext servletContext = ((WebApplicationContext) this.applicationContext).getServletContext();
194+
Assert.state(servletContext != null, "'servletContext' must not be null");
195+
serverBasePath = servletContext.getContextPath();
187196
}
188197
return (serverBasePath != null) ? serverBasePath : "";
189198
}

module/spring-boot-graphql-test/src/main/java/org/springframework/boot/test/graphql/tester/HttpGraphQlTesterContextCustomizerFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.util.List;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
import org.springframework.boot.test.context.SpringBootTest;
2224
import org.springframework.graphql.test.tester.HttpGraphQlTester;
2325
import org.springframework.test.context.ContextConfigurationAttributes;
@@ -39,7 +41,7 @@ class HttpGraphQlTesterContextCustomizerFactory implements ContextCustomizerFact
3941
private static final String WEBTESTCLIENT_CLASS = "org.springframework.test.web.reactive.server.WebTestClient";
4042

4143
@Override
42-
public ContextCustomizer createContextCustomizer(Class<?> testClass,
44+
public @Nullable ContextCustomizer createContextCustomizer(Class<?> testClass,
4345
List<ContextConfigurationAttributes> configAttributes) {
4446
SpringBootTest springBootTest = TestContextAnnotationUtils.findMergedAnnotation(testClass,
4547
SpringBootTest.class);

module/spring-boot-graphql-test/src/main/java/org/springframework/boot/test/graphql/tester/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* {@link org.springframework.graphql.test.tester.GraphQlTester} utilities.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.test.graphql.tester;
22+
23+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)