mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-10-01 19:59:03 +00:00
Clean up warnings related to deprecated HttpStatus values, etc.
This commit is contained in:
+2
-6
@@ -134,20 +134,16 @@ class ResourceElementResolverMethodTests {
|
||||
|
||||
private String one;
|
||||
|
||||
private String test;
|
||||
|
||||
private Integer count;
|
||||
|
||||
public void setOne(String one) {
|
||||
this.one = one;
|
||||
}
|
||||
|
||||
public void setTest(String test) {
|
||||
this.test = test;
|
||||
// no-op
|
||||
}
|
||||
|
||||
public void setCount(Integer count) {
|
||||
this.count = count;
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ import jakarta.annotation.Resource;
|
||||
|
||||
public class PackagePrivateMethodResourceSample {
|
||||
|
||||
private String one;
|
||||
String one;
|
||||
|
||||
@Resource
|
||||
void setOne(String one) {
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ import jakarta.annotation.Resource;
|
||||
|
||||
public class PrivateMethodResourceSample {
|
||||
|
||||
private String one;
|
||||
String one;
|
||||
|
||||
@Resource
|
||||
private void setOne(String one) {
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ import jakarta.annotation.Resource;
|
||||
|
||||
public class PrivateMethodResourceWithCustomNameSample {
|
||||
|
||||
private String text;
|
||||
String text;
|
||||
|
||||
@Resource(name = "one")
|
||||
private void setText(String text) {
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ import jakarta.annotation.Resource;
|
||||
|
||||
public class PublicMethodResourceSample {
|
||||
|
||||
private String one;
|
||||
String one;
|
||||
|
||||
@Resource
|
||||
public void setOne(String one) {
|
||||
|
||||
+1
-1
@@ -149,7 +149,7 @@ class JsonContentTests {
|
||||
}
|
||||
|
||||
|
||||
private static class Person {
|
||||
static class Person {
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
|
||||
|
||||
+3
-3
@@ -29,11 +29,11 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.web.servlet.client.RestTestClient;
|
||||
import org.springframework.web.servlet.function.ServerResponse;
|
||||
|
||||
import static org.springframework.http.HttpStatus.I_AM_A_TEAPOT;
|
||||
|
||||
import static org.springframework.http.HttpStatus.EXPECTATION_FAILED;
|
||||
|
||||
/**
|
||||
* Tests for a {@link Filter}.
|
||||
*
|
||||
* @author Rob Worsnop
|
||||
*/
|
||||
class FilterTests {
|
||||
@@ -49,7 +49,7 @@ class FilterTests {
|
||||
};
|
||||
|
||||
RestTestClient client = RestTestClient.bindToRouterFunction(
|
||||
request -> Optional.of(req -> ServerResponse.status(I_AM_A_TEAPOT).build()))
|
||||
request -> Optional.of(req -> ServerResponse.status(EXPECTATION_FAILED).build()))
|
||||
.configureServer(builder -> builder.addFilters(filter))
|
||||
.build();
|
||||
|
||||
|
||||
+4
-4
@@ -35,8 +35,8 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
|
||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.EXPECTATION_FAILED;
|
||||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
import static org.springframework.http.HttpStatus.I_AM_A_TEAPOT;
|
||||
import static org.springframework.http.HttpStatus.NOT_IMPLEMENTED;
|
||||
|
||||
/**
|
||||
@@ -55,11 +55,11 @@ class StatusAssertionTests {
|
||||
|
||||
@Test
|
||||
void statusInt() {
|
||||
testClient.get().uri("/teaPot").exchange().expectStatus().isEqualTo(I_AM_A_TEAPOT.value());
|
||||
testClient.get().uri("/teaPot").exchange().expectStatus().isEqualTo(EXPECTATION_FAILED.value());
|
||||
testClient.get().uri("/created").exchange().expectStatus().isEqualTo(CREATED.value());
|
||||
testClient.get().uri("/createdWithComposedAnnotation").exchange().expectStatus().isEqualTo(CREATED.value());
|
||||
testClient.get().uri("/badRequest").exchange().expectStatus().isEqualTo(BAD_REQUEST.value());
|
||||
testClient.get().uri("/throwsException").exchange().expectStatus().isEqualTo(I_AM_A_TEAPOT.value());
|
||||
testClient.get().uri("/throwsException").exchange().expectStatus().isEqualTo(EXPECTATION_FAILED.value());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,7 +88,7 @@ class StatusAssertionTests {
|
||||
}
|
||||
|
||||
@RestController
|
||||
@ResponseStatus(I_AM_A_TEAPOT)
|
||||
@ResponseStatus(EXPECTATION_FAILED)
|
||||
private static class StatusController {
|
||||
|
||||
@RequestMapping("/teaPot")
|
||||
|
||||
+6
-6
@@ -35,8 +35,8 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
|
||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.EXPECTATION_FAILED;
|
||||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
import static org.springframework.http.HttpStatus.I_AM_A_TEAPOT;
|
||||
import static org.springframework.http.HttpStatus.NOT_IMPLEMENTED;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
@@ -62,11 +62,11 @@ class StatusAssertionTests {
|
||||
|
||||
@Test
|
||||
void statusCode() throws Exception {
|
||||
this.mockMvc.perform(get("/teaPot")).andExpect(status().is(I_AM_A_TEAPOT.value()));
|
||||
this.mockMvc.perform(get("/expectationFailed")).andExpect(status().is(EXPECTATION_FAILED.value()));
|
||||
this.mockMvc.perform(get("/created")).andExpect(status().is(CREATED.value()));
|
||||
this.mockMvc.perform(get("/createdWithComposedAnnotation")).andExpect(status().is(CREATED.value()));
|
||||
this.mockMvc.perform(get("/badRequest")).andExpect(status().is(BAD_REQUEST.value()));
|
||||
this.mockMvc.perform(get("/throwsException")).andExpect(status().is(I_AM_A_TEAPOT.value()));
|
||||
this.mockMvc.perform(get("/throwsException")).andExpect(status().is(EXPECTATION_FAILED.value()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,11 +99,11 @@ class StatusAssertionTests {
|
||||
}
|
||||
|
||||
@RestController
|
||||
@ResponseStatus(I_AM_A_TEAPOT)
|
||||
@ResponseStatus(EXPECTATION_FAILED)
|
||||
private static class StatusController {
|
||||
|
||||
@RequestMapping("/teaPot")
|
||||
void teaPot() {
|
||||
@RequestMapping("/expectationFailed")
|
||||
void expectationFailed() {
|
||||
}
|
||||
|
||||
@RequestMapping("/created")
|
||||
|
||||
@@ -95,6 +95,7 @@ public class HttpClientErrorException extends HttpStatusCodeException {
|
||||
* with an optional prepared message.
|
||||
* @since 5.2.2
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static HttpClientErrorException create(@Nullable String message, HttpStatusCode statusCode,
|
||||
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ class ResponseEntityTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecate")
|
||||
@SuppressWarnings("deprecation")
|
||||
void unprocessableEntity() {
|
||||
ResponseEntity<String> responseEntity = ResponseEntity.unprocessableEntity().body("error");
|
||||
|
||||
|
||||
+1
@@ -86,6 +86,7 @@ class DefaultResponseErrorHandlerHttpStatusTests {
|
||||
.isThrownBy(() -> this.handler.handleError(URI.create("/"), HttpMethod.GET, this.response));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
static Stream<Arguments> errorCodes() {
|
||||
return Stream.of(
|
||||
// 4xx
|
||||
|
||||
+4
-4
@@ -57,14 +57,14 @@ class ExtractingResponseErrorHandlerTests {
|
||||
HttpMessageConverter<Object> converter = new JacksonJsonHttpMessageConverter();
|
||||
this.errorHandler = new ExtractingResponseErrorHandler(List.of(converter));
|
||||
|
||||
this.errorHandler.setStatusMapping(Map.of(HttpStatus.I_AM_A_TEAPOT, MyRestClientException.class));
|
||||
this.errorHandler.setStatusMapping(Map.of(HttpStatus.EXPECTATION_FAILED, MyRestClientException.class));
|
||||
this.errorHandler.setSeriesMapping(Map.of(HttpStatus.Series.SERVER_ERROR, MyRestClientException.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void hasError() throws Exception {
|
||||
given(this.response.getStatusCode()).willReturn(HttpStatus.I_AM_A_TEAPOT);
|
||||
given(this.response.getStatusCode()).willReturn(HttpStatus.EXPECTATION_FAILED);
|
||||
assertThat(this.errorHandler.hasError(this.response)).isTrue();
|
||||
|
||||
given(this.response.getStatusCode()).willReturn(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
@@ -78,7 +78,7 @@ class ExtractingResponseErrorHandlerTests {
|
||||
void hasErrorOverride() throws Exception {
|
||||
this.errorHandler.setSeriesMapping(Collections.singletonMap(HttpStatus.Series.CLIENT_ERROR, null));
|
||||
|
||||
given(this.response.getStatusCode()).willReturn(HttpStatus.I_AM_A_TEAPOT);
|
||||
given(this.response.getStatusCode()).willReturn(HttpStatus.EXPECTATION_FAILED);
|
||||
assertThat(this.errorHandler.hasError(this.response)).isTrue();
|
||||
|
||||
given(this.response.getStatusCode()).willReturn(HttpStatus.NOT_FOUND);
|
||||
@@ -90,7 +90,7 @@ class ExtractingResponseErrorHandlerTests {
|
||||
|
||||
@Test
|
||||
void handleErrorStatusMatch() throws Exception {
|
||||
given(this.response.getStatusCode()).willReturn(HttpStatus.I_AM_A_TEAPOT);
|
||||
given(this.response.getStatusCode()).willReturn(HttpStatus.EXPECTATION_FAILED);
|
||||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||
given(this.response.getHeaders()).willReturn(responseHeaders);
|
||||
|
||||
+1
@@ -297,6 +297,7 @@ public class WebClientResponseException extends WebClientException {
|
||||
* Create {@code WebClientResponseException} or an HTTP status specific subclass.
|
||||
* @since 6.0
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static WebClientResponseException create(
|
||||
HttpStatusCode statusCode, String statusText, HttpHeaders headers,
|
||||
byte[] body, @Nullable Charset charset, @Nullable HttpRequest request) {
|
||||
|
||||
+1
@@ -178,6 +178,7 @@ class DefaultServerResponseBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void unprocessableEntity() {
|
||||
Mono<ServerResponse> result = ServerResponse.unprocessableEntity().build();
|
||||
StepVerifier.create(result)
|
||||
|
||||
+3
-3
@@ -45,19 +45,19 @@ class WebFluxResponseStatusExceptionHandlerTests extends AbstractResponseStatusE
|
||||
void handleAnnotatedException() {
|
||||
Throwable ex = new CustomException();
|
||||
this.handler.handle(this.exchange, ex).block(Duration.ofSeconds(5));
|
||||
assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.I_AM_A_TEAPOT);
|
||||
assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.ALREADY_REPORTED);
|
||||
}
|
||||
|
||||
@Test
|
||||
void handleNestedAnnotatedException() {
|
||||
Throwable ex = new Exception(new CustomException());
|
||||
this.handler.handle(this.exchange, ex).block(Duration.ofSeconds(5));
|
||||
assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.I_AM_A_TEAPOT);
|
||||
assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.ALREADY_REPORTED);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@ResponseStatus(HttpStatus.I_AM_A_TEAPOT)
|
||||
@ResponseStatus(HttpStatus.ALREADY_REPORTED)
|
||||
private static class CustomException extends Exception {
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -199,6 +199,7 @@ class ViewResolutionResultHandlerTests {
|
||||
testHandle("/account", returnType, 99L, "account: {id=123, myLong=99}", resolver);
|
||||
|
||||
returnType = on(Handler.class).resolveReturnType(Rendering.class);
|
||||
@SuppressWarnings("deprecation")
|
||||
HttpStatus status = HttpStatus.UNPROCESSABLE_ENTITY;
|
||||
returnValue = Rendering.view("account").modelAttribute("a", "a1").status(status).header("h", "h1").build();
|
||||
String expected = "account: {a=a1, id=123}";
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ class DefaultRenderingResponseTests {
|
||||
|
||||
@Test
|
||||
void status() throws Exception {
|
||||
HttpStatus status = HttpStatus.I_AM_A_TEAPOT;
|
||||
HttpStatus status = HttpStatus.ALREADY_REPORTED;
|
||||
RenderingResponse result = RenderingResponse.create("foo").status(status).build();
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
+1
@@ -138,6 +138,7 @@ class DefaultServerResponseBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void unprocessableEntity() {
|
||||
ServerResponse response = ServerResponse.unprocessableEntity().build();
|
||||
assertThat(response.statusCode()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
|
||||
+2
-2
@@ -3889,7 +3889,7 @@ class ServletAnnotationControllerHandlerMethodTests extends AbstractServletHandl
|
||||
|
||||
@RequestMapping("/path")
|
||||
public ModelAndView methodWithHttpStatus(MyEntity object) {
|
||||
return new ModelAndView("view", HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
return new ModelAndView("view", HttpStatus.UNPROCESSABLE_CONTENT);
|
||||
}
|
||||
|
||||
@RequestMapping("/redirect")
|
||||
@@ -3904,7 +3904,7 @@ class ServletAnnotationControllerHandlerMethodTests extends AbstractServletHandl
|
||||
|
||||
@ExceptionHandler(TestException.class)
|
||||
public ModelAndView handleException() {
|
||||
return new ModelAndView("view", HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
return new ModelAndView("view", HttpStatus.UNPROCESSABLE_CONTENT);
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
|
||||
Reference in New Issue
Block a user