Add nullability annotations to tests in smoke-test/spring-boot-smoke-test-web-security-method

See gh-47263
This commit is contained in:
Moritz Halbritter
2025-10-16 11:24:49 +02:00
parent c40ba46776
commit eab04ea2cd
2 changed files with 12 additions and 3 deletions
@@ -28,3 +28,7 @@ dependencies {
testImplementation(project(":starter:spring-boot-starter-webmvc-test"))
testImplementation(project(":starter:spring-boot-starter-test"))
}
tasks.named("compileTestJava") {
options.nullability.checking = "tests"
}
@@ -16,6 +16,7 @@
package smoketest.security.method;
import java.net.URI;
import java.util.Collections;
import org.junit.jupiter.api.Test;
@@ -74,7 +75,9 @@ class SampleMethodSecurityApplicationTests {
ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST,
new HttpEntity<>(form, headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/");
URI location = entity.getHeaders().getLocation();
assertThat(location).isNotNull();
assertThat(location.toString()).endsWith(this.port + "/");
}
@Test
@@ -89,8 +92,10 @@ class SampleMethodSecurityApplicationTests {
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
String cookie = entity.getHeaders().getFirst("Set-Cookie");
headers.set("Cookie", cookie);
ResponseEntity<String> page = this.restTemplate.exchange(entity.getHeaders().getLocation(), HttpMethod.GET,
new HttpEntity<>(headers), String.class);
URI location = entity.getHeaders().getLocation();
assertThat(location).isNotNull();
ResponseEntity<String> page = this.restTemplate.exchange(location, HttpMethod.GET, new HttpEntity<>(headers),
String.class);
assertThat(page.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
assertThat(page.getBody()).contains("Access denied");
}