Skip to content

Update MockCookie#parse(String) validation - #37134

Merged
sbrannen merged 2 commits into
spring-projects:mainfrom
ngocnhan-tran1996:update-mock-cookie
Aug 13, 2026
Merged

Update MockCookie#parse(String) validation#37134
sbrannen merged 2 commits into
spring-projects:mainfrom
ngocnhan-tran1996:update-mock-cookie

Conversation

@ngocnhan-tran1996

Copy link
Copy Markdown
Contributor

* Factory method that parses the value of the supplied "Set-Cookie" header.
* @param setCookieHeader the "Set-Cookie" value; never {@code null} or empty
* @return the created cookie

Based on the Javadoc, I think it should throw Set-Cookie header must not be null or empty instead of Invalid Set-Cookie header '' when setCookieHeader is empty.

Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 13, 2026
@sbrannen sbrannen self-assigned this Aug 13, 2026
@sbrannen sbrannen added in: test Issues in the test module type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 13, 2026
@sbrannen sbrannen added this to the 7.1.0-M2 milestone Aug 13, 2026

@sbrannen sbrannen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! 👍

I've requested a minor change to the test.

Also, please update the duplicate variant of this class: spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockCookie.java

Thanks

Comment on lines +124 to +131
@Test
void parseEmptyHeader() {
assertThatIllegalArgumentException()
.isThrownBy(() -> MockCookie.parse(""))
.withMessageContaining("Set-Cookie header must not be null or empty");
assertThatIllegalArgumentException()
.isThrownBy(() -> MockCookie.parse(" "))
.withMessageContaining("Set-Cookie header must not be null or empty");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Test
void parseEmptyHeader() {
assertThatIllegalArgumentException()
.isThrownBy(() -> MockCookie.parse(""))
.withMessageContaining("Set-Cookie header must not be null or empty");
assertThatIllegalArgumentException()
.isThrownBy(() -> MockCookie.parse(" "))
.withMessageContaining("Set-Cookie header must not be null or empty");
@ParameterizedTest
@ValueSource(strings = {"", " "})
void parseEmptyHeader(String header) {
assertThatIllegalArgumentException()
.isThrownBy(() -> MockCookie.parse(header))
.withMessageContaining("Set-Cookie header must not be null or empty");
}

A @ParameterizedTest would be better here.

@sbrannen sbrannen added the status: waiting-for-feedback We need additional information before we can continue label Aug 13, 2026
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
@sbrannen sbrannen removed the status: waiting-for-feedback We need additional information before we can continue label Aug 13, 2026

@sbrannen sbrannen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the requested changes.

Looks good now.

@sbrannen
sbrannen merged commit 8b89493 into spring-projects:main Aug 13, 2026
2 checks passed
@sbrannen sbrannen modified the milestones: 7.1.0-M2, 7.1.0-M1 Aug 13, 2026
sbrannen added a commit that referenced this pull request Aug 13, 2026
@sbrannen

Copy link
Copy Markdown
Member

This has been merged into main in 8b89493 and slightly revised in 27a85be (since I realized after the merge that we can actually combine the "null" and "empty" tests into a single test method).

Thanks

@ngocnhan-tran1996
ngocnhan-tran1996 deleted the update-mock-cookie branch August 13, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: test Issues in the test module type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants