Author: mheath
Date: Tue Mar 4 15:34:04 2008
New Revision: 633705
URL: http://svn.apache.org/viewvc?rev=633705&view=rev
Log:
Added Cookie copy constructor and test.
Added:
mina/asyncweb/trunk/common/src/test/java/org/apache/asyncweb/common/DefaultCookieTest.java
(with props)
Modified:
mina/asyncweb/trunk/common/src/main/java/org/apache/asyncweb/common/DefaultCookie.java
Modified:
mina/asyncweb/trunk/common/src/main/java/org/apache/asyncweb/common/DefaultCookie.java
URL:
http://svn.apache.org/viewvc/mina/asyncweb/trunk/common/src/main/java/org/apache/asyncweb/common/DefaultCookie.java?rev=633705&r1=633704&r2=633705&view=diff
==============================================================================
---
mina/asyncweb/trunk/common/src/main/java/org/apache/asyncweb/common/DefaultCookie.java
(original)
+++
mina/asyncweb/trunk/common/src/main/java/org/apache/asyncweb/common/DefaultCookie.java
Tue Mar 4 15:34:04 2008
@@ -69,14 +69,26 @@
* @param value the default value of the new cookie
*/
public DefaultCookie(String name, String value) {
- if (name == null) {
- throw new IllegalArgumentException("name can NOT be null");
- }
- if (value == null) {
- throw new IllegalArgumentException("name can NOT be null");
- }
- this.name = name;
+ this(name);
this.value = value;
+ }
+
+ /**
+ * Creates a new cookie based on the values of the specified
<tt>Cookie</tt>.
+ *
+ * @param cookie the <tt>Cookie</tt> object from which the new
+ * instance of <tt>DefaultCookie</tt> will copy its values
+ */
+ public DefaultCookie(Cookie cookie) {
+ this(cookie.getName());
+ this.comment = cookie.getComment();
+ this.createdDate = cookie.getCreatedDate();
+ this.domain = cookie.getDomain();
+ this.maxAge = cookie.getMaxAge();
+ this.path = cookie.getPath();
+ this.secure = cookie.isSecure();
+ this.value = cookie.getValue();
+ this.version = cookie.getVersion();
}
public String getComment() {
Added:
mina/asyncweb/trunk/common/src/test/java/org/apache/asyncweb/common/DefaultCookieTest.java
URL:
http://svn.apache.org/viewvc/mina/asyncweb/trunk/common/src/test/java/org/apache/asyncweb/common/DefaultCookieTest.java?rev=633705&view=auto
==============================================================================
---
mina/asyncweb/trunk/common/src/test/java/org/apache/asyncweb/common/DefaultCookieTest.java
(added)
+++
mina/asyncweb/trunk/common/src/test/java/org/apache/asyncweb/common/DefaultCookieTest.java
Tue Mar 4 15:34:04 2008
@@ -0,0 +1,72 @@
+package org.apache.asyncweb.common;
+
+import junit.framework.TestCase;
+
+public class DefaultCookieTest extends TestCase {
+
+ public void testCopyConstructor() throws Exception {
+ // Cookie values
+ final String name = "cookieName";
+ final String value = "The cookie value goes here";
+ final int version = -489243132;
+ final String domain = "mina.apache.org";
+ final String path = "/cookie/path";
+ final boolean secure = true;
+ final int maxAge = 324987;
+ final String comment = "This is the cookie comment";
+ final long createdDate = 437874235475L;
+
+ // Create an instance of Cookie
+ Cookie cookie = new Cookie() {
+ public int getVersion() {
+ return version;
+ }
+ public String getName() {
+ return name;
+ }
+ public String getValue() {
+ return value;
+ }
+ public String getDomain() {
+ return domain;
+ }
+ public String getPath() {
+ return path;
+ }
+ public boolean isSecure() {
+ return secure;
+ }
+ public int getMaxAge() {
+ return maxAge;
+ }
+ public String getComment() {
+ return comment;
+ }
+ public long getCreatedDate() {
+ return createdDate;
+ }
+ public long getExpirationDate() {
+ // This should be a calculated field so we'll just return 0
+ return 0;
+ }
+ public int compareTo(Cookie o) {
+ return -1;
+ }
+ };
+
+ // Invoke copy constructor
+ Cookie copy = new DefaultCookie(cookie);
+
+ // Ensure all fields were copied successfully
+ assertEquals(name, copy.getName());
+ assertEquals(value, copy.getValue());
+ assertEquals(version, copy.getVersion());
+ assertEquals(domain, copy.getDomain());
+ assertEquals(path, copy.getPath());
+ assertEquals(secure, copy.isSecure());
+ assertEquals(maxAge, copy.getMaxAge());
+ assertEquals(comment, copy.getComment());
+ assertEquals(createdDate, copy.getCreatedDate());
+ }
+
+}
Propchange:
mina/asyncweb/trunk/common/src/test/java/org/apache/asyncweb/common/DefaultCookieTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain