Skip to content

Commit a3c9e8d

Browse files
committed
Polish contribution
See gh-23769
1 parent 3814f12 commit a3c9e8d

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

spring-test/src/main/java/org/springframework/mock/web/MockCookie.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class MockCookie extends Cookie {
4646

4747

4848
/**
49-
* Constructor with the cookie name and value.
49+
* Construct a new {@link MockCookie} with the supplied name and value.
5050
* @param name the name
5151
* @param value the value
5252
* @see Cookie#Cookie(String, String)
@@ -56,33 +56,37 @@ public MockCookie(String name, String value) {
5656
}
5757

5858
/**
59-
* Add the "Expires" attribute to the cookie.
59+
* Set the "Expires" attribute for this cookie.
60+
* @since 5.1.11
6061
*/
6162
public void setExpires(@Nullable ZonedDateTime expires) {
6263
this.expires = expires;
6364
}
6465

6566
/**
66-
* Return the "Expires" attribute, or {@code null} if not set.
67+
* Get the "Expires" attribute for this cookie.
68+
* @since 5.1.11
69+
* @return the "Expires" attribute for this cookie, or {@code null} if not set
6770
*/
6871
@Nullable
6972
public ZonedDateTime getExpires() {
7073
return this.expires;
7174
}
7275

7376
/**
74-
* Add the "SameSite" attribute to the cookie.
77+
* Set the "SameSite" attribute for this cookie.
7578
* <p>This limits the scope of the cookie such that it will only be attached
76-
* to same site requests if {@code "Strict"} or cross-site requests if
77-
* {@code "Lax"}.
79+
* to same-site requests if the supplied value is {@code "Strict"} or cross-site
80+
* requests if the supplied value is {@code "Lax"}.
7881
* @see <a href="https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis#section-4.1.2.7">RFC6265 bis</a>
7982
*/
8083
public void setSameSite(@Nullable String sameSite) {
8184
this.sameSite = sameSite;
8285
}
8386

8487
/**
85-
* Return the "SameSite" attribute, or {@code null} if not set.
88+
* Get the "SameSite" attribute for this cookie.
89+
* @return the "SameSite" attribute for this cookie, or {@code null} if not set
8690
*/
8791
@Nullable
8892
public String getSameSite() {
@@ -91,7 +95,7 @@ public String getSameSite() {
9195

9296

9397
/**
94-
* Factory method that parses the value of a "Set-Cookie" header.
98+
* Factory method that parses the value of the supplied "Set-Cookie" header.
9599
* @param setCookieHeader the "Set-Cookie" value; never {@code null} or empty
96100
* @return the created cookie
97101
*/

spring-test/src/test/java/org/springframework/mock/web/MockHttpServletResponseTests.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,18 @@ public void setCookieHeader() {
339339
assertPrimarySessionCookie("999");
340340
}
341341

342+
/**
343+
* @since 5.1.11
344+
*/
345+
@Test
346+
public void setCookieHeaderWithExpiresAttribute() {
347+
String cookieValue = "SESSION=123; Path=/; Max-Age=100; Expires=Tue, 8 Oct 2019 19:50:00 GMT; Secure; " +
348+
"HttpOnly; SameSite=Lax";
349+
response.setHeader(HttpHeaders.SET_COOKIE, cookieValue);
350+
assertNumCookies(1);
351+
assertEquals(cookieValue, response.getHeader(HttpHeaders.SET_COOKIE));
352+
}
353+
342354
@Test
343355
public void addCookieHeader() {
344356
response.addHeader(HttpHeaders.SET_COOKIE, "SESSION=123; Path=/; Secure; HttpOnly; SameSite=Lax");
@@ -352,8 +364,11 @@ public void addCookieHeader() {
352364
assertCookieValues("123", "999");
353365
}
354366

367+
/**
368+
* @since 5.1.11
369+
*/
355370
@Test
356-
public void addCookieHeaderWithExpires() {
371+
public void addCookieHeaderWithExpiresAttribute() {
357372
String cookieValue = "SESSION=123; Path=/; Max-Age=100; Expires=Tue, 8 Oct 2019 19:50:00 GMT; Secure; " +
358373
"HttpOnly; SameSite=Lax";
359374
response.addHeader(HttpHeaders.SET_COOKIE, cookieValue);

spring-web/src/test/java/org/springframework/mock/web/test/MockCookie.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class MockCookie extends Cookie {
4646

4747

4848
/**
49-
* Constructor with the cookie name and value.
49+
* Construct a new {@link MockCookie} with the supplied name and value.
5050
* @param name the name
5151
* @param value the value
5252
* @see Cookie#Cookie(String, String)
@@ -56,33 +56,37 @@ public MockCookie(String name, String value) {
5656
}
5757

5858
/**
59-
* Add the "Expires" attribute to the cookie.
59+
* Set the "Expires" attribute for this cookie.
60+
* @since 5.1.11
6061
*/
6162
public void setExpires(@Nullable ZonedDateTime expires) {
6263
this.expires = expires;
6364
}
6465

6566
/**
66-
* Return the "Expires" attribute, or {@code null} if not set.
67+
* Get the "Expires" attribute for this cookie.
68+
* @since 5.1.11
69+
* @return the "Expires" attribute for this cookie, or {@code null} if not set
6770
*/
6871
@Nullable
6972
public ZonedDateTime getExpires() {
7073
return this.expires;
7174
}
7275

7376
/**
74-
* Add the "SameSite" attribute to the cookie.
77+
* Set the "SameSite" attribute for this cookie.
7578
* <p>This limits the scope of the cookie such that it will only be attached
76-
* to same site requests if {@code "Strict"} or cross-site requests if
77-
* {@code "Lax"}.
79+
* to same-site requests if the supplied value is {@code "Strict"} or cross-site
80+
* requests if the supplied value is {@code "Lax"}.
7881
* @see <a href="https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis#section-4.1.2.7">RFC6265 bis</a>
7982
*/
8083
public void setSameSite(@Nullable String sameSite) {
8184
this.sameSite = sameSite;
8285
}
8386

8487
/**
85-
* Return the "SameSite" attribute, or {@code null} if not set.
88+
* Get the "SameSite" attribute for this cookie.
89+
* @return the "SameSite" attribute for this cookie, or {@code null} if not set
8690
*/
8791
@Nullable
8892
public String getSameSite() {
@@ -91,7 +95,7 @@ public String getSameSite() {
9195

9296

9397
/**
94-
* Factory method that parses the value of a "Set-Cookie" header.
98+
* Factory method that parses the value of the supplied "Set-Cookie" header.
9599
* @param setCookieHeader the "Set-Cookie" value; never {@code null} or empty
96100
* @return the created cookie
97101
*/

0 commit comments

Comments
 (0)