Introduce not-null precondition for MockCookie parsing

This commit is contained in:
Sam Brannen 2018-10-02 13:07:20 +02:00
parent 77205ca165
commit e63bffcfa0
2 changed files with 9 additions and 1 deletions

View File

@ -70,10 +70,11 @@ public class MockCookie extends Cookie {
/**
* Factory method that parses the value of a "Set-Cookie" header.
* @param setCookieHeader the "Set-Cookie" value
* @param setCookieHeader the "Set-Cookie" value; never {@code null} or empty
* @return the created cookie
*/
public static MockCookie parse(String setCookieHeader) {
Assert.notNull(setCookieHeader, "Set-Cookie header must not be null");
String[] cookieParts = setCookieHeader.split("\\s*=\\s*", 2);
Assert.isTrue(cookieParts.length == 2, () -> "Invalid Set-Cookie header '" + setCookieHeader + "'");

View File

@ -80,6 +80,13 @@ public class MockCookieTests {
assertEquals("Lax", cookie.getSameSite());
}
@Test
public void parseNullHeader() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("Set-Cookie header must not be null");
MockCookie.parse(null);
}
@Test
public void parseInvalidHeader() {
exception.expect(IllegalArgumentException.class);