Add StatusAssertions.isForbidden
Includes aligned quoting for header assertion messages. Also aligns HeaderAssertionTests class name. Issue: SPR-16129
This commit is contained in:
@@ -30,10 +30,8 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.http.client.reactive.MockClientHttpRequest;
|
||||
import org.springframework.mock.http.client.reactive.MockClientHttpResponse;
|
||||
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link HeaderAssertions}.
|
||||
@@ -41,11 +39,10 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
*/
|
||||
public class HeaderAssertionsTests {
|
||||
|
||||
public class HeaderAssertionTests {
|
||||
|
||||
@Test
|
||||
public void valueEquals() throws Exception {
|
||||
public void valueEquals() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("foo", "bar");
|
||||
HeaderAssertions assertions = headerAssertions(headers);
|
||||
@@ -79,7 +76,7 @@ public class HeaderAssertionsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueEqualsWithMultipeValues() throws Exception {
|
||||
public void valueEqualsWithMultipeValues() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("foo", "bar");
|
||||
headers.add("foo", "baz");
|
||||
@@ -107,7 +104,7 @@ public class HeaderAssertionsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueMatches() throws Exception {
|
||||
public void valueMatches() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
||||
HeaderAssertions assertions = headerAssertions(headers);
|
||||
@@ -122,14 +119,13 @@ public class HeaderAssertionsTests {
|
||||
catch (AssertionError error) {
|
||||
Throwable cause = error.getCause();
|
||||
assertNotNull(cause);
|
||||
assertEquals("Response header [Content-Type]='application/json;charset=UTF-8' " +
|
||||
"does not match '.*ISO-8859-1.*'", cause.getMessage());
|
||||
assertEquals("Response header 'Content-Type'=[application/json;charset=UTF-8] " +
|
||||
"does not match [.*ISO-8859-1.*]", cause.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cacheControl() throws Exception {
|
||||
|
||||
public void cacheControl() {
|
||||
CacheControl control = CacheControl.maxAge(1, TimeUnit.HOURS).noTransform();
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
@@ -148,6 +144,7 @@ public class HeaderAssertionsTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private HeaderAssertions headerAssertions(HttpHeaders responseHeaders) {
|
||||
MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, URI.create("/"));
|
||||
MockClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK);
|
||||
@@ -26,8 +26,8 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.mock.http.client.reactive.MockClientHttpRequest;
|
||||
import org.springframework.mock.http.client.reactive.MockClientHttpResponse;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link StatusAssertions}.
|
||||
@@ -38,8 +38,7 @@ import static org.mockito.Mockito.mock;
|
||||
public class StatusAssertionTests {
|
||||
|
||||
@Test
|
||||
public void isEqualTo() throws Exception {
|
||||
|
||||
public void isEqualTo() {
|
||||
StatusAssertions assertions = statusAssertions(HttpStatus.CONFLICT);
|
||||
|
||||
// Success
|
||||
@@ -64,8 +63,7 @@ public class StatusAssertionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reasonEquals() throws Exception {
|
||||
|
||||
public void reasonEquals() {
|
||||
StatusAssertions assertions = statusAssertions(HttpStatus.CONFLICT);
|
||||
|
||||
// Success
|
||||
@@ -81,7 +79,7 @@ public class StatusAssertionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusSerius1xx() throws Exception {
|
||||
public void statusSerius1xx() {
|
||||
StatusAssertions assertions = statusAssertions(HttpStatus.CONTINUE);
|
||||
|
||||
// Success
|
||||
@@ -97,7 +95,7 @@ public class StatusAssertionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusSerius2xx() throws Exception {
|
||||
public void statusSerius2xx() {
|
||||
StatusAssertions assertions = statusAssertions(HttpStatus.OK);
|
||||
|
||||
// Success
|
||||
@@ -113,7 +111,7 @@ public class StatusAssertionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusSerius3xx() throws Exception {
|
||||
public void statusSerius3xx() {
|
||||
StatusAssertions assertions = statusAssertions(HttpStatus.PERMANENT_REDIRECT);
|
||||
|
||||
// Success
|
||||
@@ -129,7 +127,7 @@ public class StatusAssertionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusSerius4xx() throws Exception {
|
||||
public void statusSerius4xx() {
|
||||
StatusAssertions assertions = statusAssertions(HttpStatus.BAD_REQUEST);
|
||||
|
||||
// Success
|
||||
@@ -145,7 +143,7 @@ public class StatusAssertionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusSerius5xx() throws Exception {
|
||||
public void statusSerius5xx() {
|
||||
StatusAssertions assertions = statusAssertions(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
|
||||
// Success
|
||||
|
||||
Reference in New Issue
Block a user