ResponseEntity provides static "badRequest()" convenience method as well
Issue: SPR-12112
This commit is contained in:
@@ -228,6 +228,15 @@ public class ResponseEntity<T> extends HttpEntity<T> {
|
|||||||
return status(HttpStatus.NO_CONTENT);
|
return status(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a builder with a {@link HttpStatus#BAD_REQUEST} status.
|
||||||
|
* @return the created builder
|
||||||
|
* @since 4.1
|
||||||
|
*/
|
||||||
|
public static BodyBuilder badRequest() {
|
||||||
|
return status(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a builder with a {@link HttpStatus#NOT_FOUND NOT_FOUND} status.
|
* Creates a builder with a {@link HttpStatus#NOT_FOUND NOT_FOUND} status.
|
||||||
* @return the created builder
|
* @return the created builder
|
||||||
|
|||||||
@@ -101,6 +101,15 @@ public class ResponseEntityTests {
|
|||||||
assertNull(responseEntity.getBody());
|
assertNull(responseEntity.getBody());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void badRequest() throws URISyntaxException {
|
||||||
|
ResponseEntity<Void> responseEntity = ResponseEntity.badRequest().build();
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
assertNull(responseEntity.getBody());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notFound() throws URISyntaxException {
|
public void notFound() throws URISyntaxException {
|
||||||
ResponseEntity<Void> responseEntity = ResponseEntity.notFound().build();
|
ResponseEntity<Void> responseEntity = ResponseEntity.notFound().build();
|
||||||
|
|||||||
Reference in New Issue
Block a user