Skip to content

Commit e17ca9a

Browse files
committed
Implement toString() in MockCookie
1 parent 8776139 commit e17ca9a

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
2222

2323
import javax.servlet.http.Cookie;
2424

25+
import org.springframework.core.style.ToStringCreator;
2526
import org.springframework.lang.Nullable;
2627
import org.springframework.util.Assert;
2728
import org.springframework.util.StringUtils;
@@ -152,4 +153,22 @@ private static String extractAttributeValue(String attribute, String header) {
152153
return nameAndValue[1];
153154
}
154155

156+
@Override
157+
public String toString() {
158+
return new ToStringCreator(this)
159+
.append("name", getName())
160+
.append("value", getValue())
161+
.append("Path", getPath())
162+
.append("Domain", getDomain())
163+
.append("Version", getVersion())
164+
.append("Comment", getComment())
165+
.append("Secure", getSecure())
166+
.append("HttpOnly", isHttpOnly())
167+
.append("SameSite", this.sameSite)
168+
.append("Max-Age", getMaxAge())
169+
.append("Expires", (this.expires != null ?
170+
DateTimeFormatter.RFC_1123_DATE_TIME.format(this.expires) : null))
171+
.toString();
172+
}
173+
155174
}

0 commit comments

Comments
 (0)