Add nullability annotations to tests in module/spring-boot-graphql
See gh-47263
This commit is contained in:
		
							parent
							
								
									e83ad75d3e
								
							
						
					
					
						commit
						4854fec275
					
				|  | @ -54,5 +54,11 @@ dependencies { | ||||||
| 	testImplementation("org.springframework.graphql:spring-graphql-test") | 	testImplementation("org.springframework.graphql:spring-graphql-test") | ||||||
| 	testImplementation("org.springframework.security:spring-security-test") | 	testImplementation("org.springframework.security:spring-security-test") | ||||||
| 
 | 
 | ||||||
|  | 	testCompileOnly("com.google.code.findbugs:jsr305") | ||||||
|  | 
 | ||||||
| 	testRuntimeOnly("ch.qos.logback:logback-classic") | 	testRuntimeOnly("ch.qos.logback:logback-classic") | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | tasks.named("compileTestJava") { | ||||||
|  | 	options.nullability.checking = "tests" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -26,15 +26,19 @@ import org.springframework.data.annotation.Id; | ||||||
| public class Book { | public class Book { | ||||||
| 
 | 
 | ||||||
| 	@Id | 	@Id | ||||||
|  | 	@SuppressWarnings("NullAway.Init") | ||||||
| 	String id; | 	String id; | ||||||
| 
 | 
 | ||||||
|  | 	@SuppressWarnings("NullAway.Init") | ||||||
| 	String name; | 	String name; | ||||||
| 
 | 
 | ||||||
|  | 	@SuppressWarnings("NullAway.Init") | ||||||
| 	int pageCount; | 	int pageCount; | ||||||
| 
 | 
 | ||||||
|  | 	@SuppressWarnings("NullAway.Init") | ||||||
| 	String author; | 	String author; | ||||||
| 
 | 
 | ||||||
| 	public Book() { | 	protected Book() { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public Book(String id, String name, int pageCount, String author) { | 	public Book(String id, String name, int pageCount, String author) { | ||||||
|  |  | ||||||
|  | @ -18,6 +18,7 @@ package org.springframework.boot.graphql.autoconfigure; | ||||||
| 
 | 
 | ||||||
| import java.util.Collection; | import java.util.Collection; | ||||||
| 
 | 
 | ||||||
|  | import org.jspecify.annotations.Nullable; | ||||||
| import org.junit.jupiter.api.Test; | import org.junit.jupiter.api.Test; | ||||||
| 
 | 
 | ||||||
| import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; | import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; | ||||||
|  | @ -78,7 +79,7 @@ class DefaultGraphQlSchemaConditionTests { | ||||||
| 		assertThat(context.getBean("success")).isEqualTo("success"); | 		assertThat(context.getBean("success")).isEqualTo("success"); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	private String conditionReportMessage(AssertableApplicationContext context) { | 	private @Nullable String conditionReportMessage(AssertableApplicationContext context) { | ||||||
| 		Collection<ConditionEvaluationReport.ConditionAndOutcomes> conditionAndOutcomes = ConditionEvaluationReport | 		Collection<ConditionEvaluationReport.ConditionAndOutcomes> conditionAndOutcomes = ConditionEvaluationReport | ||||||
| 			.get(context.getSourceApplicationContext().getBeanFactory()) | 			.get(context.getSourceApplicationContext().getBeanFactory()) | ||||||
| 			.getConditionAndOutcomesBySource() | 			.getConditionAndOutcomesBySource() | ||||||
|  |  | ||||||
|  | @ -20,8 +20,11 @@ import java.util.Arrays; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| 
 | 
 | ||||||
| import graphql.schema.DataFetcher; | import graphql.schema.DataFetcher; | ||||||
|  | import org.jspecify.annotations.Nullable; | ||||||
| import reactor.core.publisher.Flux; | import reactor.core.publisher.Flux; | ||||||
| 
 | 
 | ||||||
|  | import static org.assertj.core.api.Assertions.assertThat; | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * Test utility class holding {@link DataFetcher} implementations. |  * Test utility class holding {@link DataFetcher} implementations. | ||||||
|  * |  * | ||||||
|  | @ -39,14 +42,22 @@ public final class GraphQlTestDataFetchers { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public static DataFetcher<Book> getBookByIdDataFetcher() { | 	public static DataFetcher<Book> getBookByIdDataFetcher() { | ||||||
| 		return (environment) -> getBookById(environment.getArgument("id")); | 		return (environment) -> { | ||||||
|  | 			String id = environment.getArgument("id"); | ||||||
|  | 			assertThat(id).isNotNull(); | ||||||
|  | 			return getBookById(id); | ||||||
|  | 		}; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public static DataFetcher<Flux<Book>> getBooksOnSaleDataFetcher() { | 	public static DataFetcher<Flux<Book>> getBooksOnSaleDataFetcher() { | ||||||
| 		return (environment) -> getBooksOnSale(environment.getArgument("minPages")); | 		return (environment) -> { | ||||||
|  | 			Integer minPages = environment.getArgument("minPages"); | ||||||
|  | 			assertThat(minPages).isNotNull(); | ||||||
|  | 			return getBooksOnSale(minPages); | ||||||
|  | 		}; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public static Book getBookById(String id) { | 	public static @Nullable Book getBookById(String id) { | ||||||
| 		return books.stream().filter((book) -> book.getId().equals(id)).findFirst().orElse(null); | 		return books.stream().filter((book) -> book.getId().equals(id)).findFirst().orElse(null); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -23,6 +23,7 @@ import java.util.function.Consumer; | ||||||
| 
 | 
 | ||||||
| import graphql.schema.idl.TypeRuntimeWiring; | import graphql.schema.idl.TypeRuntimeWiring; | ||||||
| import org.junit.jupiter.api.Test; | import org.junit.jupiter.api.Test; | ||||||
|  | import reactor.core.publisher.Mono; | ||||||
| 
 | 
 | ||||||
| import org.springframework.aot.hint.RuntimeHints; | import org.springframework.aot.hint.RuntimeHints; | ||||||
| import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; | import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; | ||||||
|  | @ -354,13 +355,13 @@ class GraphQlWebFluxAutoConfigurationTests { | ||||||
| 		@Bean | 		@Bean | ||||||
| 		@Order(-1) | 		@Order(-1) | ||||||
| 		RouterFunction<?> before() { | 		RouterFunction<?> before() { | ||||||
| 			return (r) -> null; | 			return (r) -> Mono.empty(); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		@Bean | 		@Bean | ||||||
| 		@Order(1) | 		@Order(1) | ||||||
| 		RouterFunction<?> after() { | 		RouterFunction<?> after() { | ||||||
| 			return (r) -> null; | 			return (r) -> Mono.empty(); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -153,8 +153,11 @@ class GraphQlWebFluxSecurityAutoConfigurationTests { | ||||||
| 
 | 
 | ||||||
| 		@Bean | 		@Bean | ||||||
| 		RuntimeWiringConfigurer bookDataFetcher(BookService bookService) { | 		RuntimeWiringConfigurer bookDataFetcher(BookService bookService) { | ||||||
| 			return (builder) -> builder.type(TypeRuntimeWiring.newTypeWiring("Query") | 			return (builder) -> builder.type(TypeRuntimeWiring.newTypeWiring("Query").dataFetcher("bookById", (env) -> { | ||||||
| 				.dataFetcher("bookById", (env) -> bookService.getBookdById(env.getArgument("id")))); | 				String id = env.getArgument("id"); | ||||||
|  | 				assertThat(id).isNotNull(); | ||||||
|  | 				return bookService.getBookdById(id); | ||||||
|  | 			})); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		@Bean | 		@Bean | ||||||
|  |  | ||||||
|  | @ -18,6 +18,7 @@ package org.springframework.boot.graphql.autoconfigure.security; | ||||||
| 
 | 
 | ||||||
| import graphql.schema.idl.TypeRuntimeWiring; | import graphql.schema.idl.TypeRuntimeWiring; | ||||||
| import org.assertj.core.api.ThrowingConsumer; | import org.assertj.core.api.ThrowingConsumer; | ||||||
|  | import org.jspecify.annotations.Nullable; | ||||||
| import org.junit.jupiter.api.Test; | import org.junit.jupiter.api.Test; | ||||||
| 
 | 
 | ||||||
| import org.springframework.boot.autoconfigure.AutoConfigurations; | import org.springframework.boot.autoconfigure.AutoConfigurations; | ||||||
|  | @ -142,8 +143,11 @@ class GraphQlWebMvcSecurityAutoConfigurationTests { | ||||||
| 
 | 
 | ||||||
| 		@Bean | 		@Bean | ||||||
| 		RuntimeWiringConfigurer bookDataFetcher(BookService bookService) { | 		RuntimeWiringConfigurer bookDataFetcher(BookService bookService) { | ||||||
| 			return (builder) -> builder.type(TypeRuntimeWiring.newTypeWiring("Query") | 			return (builder) -> builder.type(TypeRuntimeWiring.newTypeWiring("Query").dataFetcher("bookById", (env) -> { | ||||||
| 				.dataFetcher("bookById", (env) -> bookService.getBookdById(env.getArgument("id")))); | 				String id = env.getArgument("id"); | ||||||
|  | 				assertThat(id).isNotNull(); | ||||||
|  | 				return bookService.getBookdById(id); | ||||||
|  | 			})); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		@Bean | 		@Bean | ||||||
|  | @ -156,7 +160,7 @@ class GraphQlWebMvcSecurityAutoConfigurationTests { | ||||||
| 	static class BookService { | 	static class BookService { | ||||||
| 
 | 
 | ||||||
| 		@PreAuthorize("hasRole('USER')") | 		@PreAuthorize("hasRole('USER')") | ||||||
| 		Book getBookdById(String id) { | 		@Nullable Book getBookdById(String id) { | ||||||
| 			return GraphQlTestDataFetchers.getBookById(id); | 			return GraphQlTestDataFetchers.getBookById(id); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -18,6 +18,7 @@ package org.springframework.boot.graphql.autoconfigure.servlet; | ||||||
| 
 | 
 | ||||||
| import java.time.Duration; | import java.time.Duration; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
|  | import java.util.Optional; | ||||||
| 
 | 
 | ||||||
| import graphql.schema.idl.TypeRuntimeWiring; | import graphql.schema.idl.TypeRuntimeWiring; | ||||||
| import org.assertj.core.api.ThrowingConsumer; | import org.assertj.core.api.ThrowingConsumer; | ||||||
|  | @ -313,13 +314,13 @@ class GraphQlWebMvcAutoConfigurationTests { | ||||||
| 		@Bean | 		@Bean | ||||||
| 		@Order(-1) | 		@Order(-1) | ||||||
| 		RouterFunction<?> before() { | 		RouterFunction<?> before() { | ||||||
| 			return (r) -> null; | 			return (r) -> Optional.empty(); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		@Bean | 		@Bean | ||||||
| 		@Order(1) | 		@Order(1) | ||||||
| 		RouterFunction<?> after() { | 		RouterFunction<?> after() { | ||||||
| 			return (r) -> null; | 			return (r) -> Optional.empty(); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue