Update MockCookie#parse(String) validation to align with Javadoc

Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
This commit is contained in:
Tran Ngoc Nhan
2026-08-13 12:38:02 +02:00
committed by GitHub
parent 68e6acd37e
commit 8b894933ae
3 changed files with 11 additions and 3 deletions
@@ -132,7 +132,7 @@ public class MockCookie extends Cookie {
* @return the created cookie
*/
public static MockCookie parse(String setCookieHeader) {
Assert.notNull(setCookieHeader, "Set-Cookie header must not be null");
Assert.hasText(setCookieHeader, "Set-Cookie header must not be null or empty");
String[] cookieParts = setCookieHeader.split("\\s*=\\s*", 2);
Assert.isTrue(cookieParts.length == 2, () -> "Invalid Set-Cookie header '" + setCookieHeader + "'");
@@ -118,7 +118,15 @@ class MockCookieTests {
void parseNullHeader() {
assertThatIllegalArgumentException()
.isThrownBy(() -> MockCookie.parse(null))
.withMessageContaining("Set-Cookie header must not be null");
.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");
}
@Test
@@ -132,7 +132,7 @@ public class MockCookie extends Cookie {
* @return the created cookie
*/
public static MockCookie parse(String setCookieHeader) {
Assert.notNull(setCookieHeader, "Set-Cookie header must not be null");
Assert.hasText(setCookieHeader, "Set-Cookie header must not be null or empty");
String[] cookieParts = setCookieHeader.split("\\s*=\\s*", 2);
Assert.isTrue(cookieParts.length == 2, () -> "Invalid Set-Cookie header '" + setCookieHeader + "'");