Polish contribution

See gh-23769
This commit is contained in:
Sam Brannen
2019-10-29 13:27:39 +01:00
parent 9b2087618b
commit ce0b012f43
4 changed files with 48 additions and 25 deletions

View File

@@ -16,11 +16,11 @@
package org.springframework.mock.web;
import org.junit.jupiter.api.Test;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@@ -86,15 +86,15 @@ class MockCookieTests {
@Test
void parseNullHeader() {
assertThatIllegalArgumentException().isThrownBy(() ->
MockCookie.parse(null))
assertThatIllegalArgumentException()
.isThrownBy(() -> MockCookie.parse(null))
.withMessageContaining("Set-Cookie header must not be null");
}
@Test
void parseInvalidHeader() {
assertThatIllegalArgumentException().isThrownBy(() ->
MockCookie.parse("BOOM"))
assertThatIllegalArgumentException()
.isThrownBy(() -> MockCookie.parse("BOOM"))
.withMessageContaining("Invalid Set-Cookie header 'BOOM'");
}
@@ -102,8 +102,8 @@ class MockCookieTests {
void parseInvalidAttribute() {
String header = "SESSION=123; Path=";
assertThatIllegalArgumentException().isThrownBy(() ->
MockCookie.parse(header))
assertThatIllegalArgumentException()
.isThrownBy(() -> MockCookie.parse(header))
.withMessageContaining("No value in attribute 'Path' for Set-Cookie header '" + header + "'");
}

View File

@@ -350,6 +350,18 @@ class MockHttpServletResponseTests {
assertPrimarySessionCookie("999");
}
/**
* @since 5.1.11
*/
@Test
void setCookieHeaderWithExpiresAttribute() {
String cookieValue = "SESSION=123; Path=/; Max-Age=100; Expires=Tue, 8 Oct 2019 19:50:00 GMT; Secure; " +
"HttpOnly; SameSite=Lax";
response.setHeader(HttpHeaders.SET_COOKIE, cookieValue);
assertNumCookies(1);
assertThat(response.getHeader(HttpHeaders.SET_COOKIE)).isEqualTo(cookieValue);
}
@Test
void addCookieHeader() {
response.addHeader(HttpHeaders.SET_COOKIE, "SESSION=123; Path=/; Secure; HttpOnly; SameSite=Lax");
@@ -363,8 +375,11 @@ class MockHttpServletResponseTests {
assertCookieValues("123", "999");
}
/**
* @since 5.1.11
*/
@Test
void addCookieHeaderWithExpires() {
void addCookieHeaderWithExpiresAttribute() {
String cookieValue = "SESSION=123; Path=/; Max-Age=100; Expires=Tue, 8 Oct 2019 19:50:00 GMT; Secure; " +
"HttpOnly; SameSite=Lax";
response.addHeader(HttpHeaders.SET_COOKIE, cookieValue);