Fix NewCookie to throw correct exception, add tests
svn path=/trunk/; revision=491
diff --git a/src/jsr311-api/src/javax/ws/rs/core/NewCookie.java b/src/jsr311-api/src/javax/ws/rs/core/NewCookie.java
index 83ede1e..2cd4fd7 100644
--- a/src/jsr311-api/src/javax/ws/rs/core/NewCookie.java
+++ b/src/jsr311-api/src/javax/ws/rs/core/NewCookie.java
@@ -93,7 +93,11 @@
* @throws IllegalArgumentException if cookie is null
*/
public NewCookie(Cookie cookie) {
- super(cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getDomain(), cookie.getVersion());
+ super(cookie==null ? null : cookie.getName(),
+ cookie==null ? null : cookie.getValue(),
+ cookie==null ? null : cookie.getPath(),
+ cookie==null ? null : cookie.getDomain(),
+ cookie==null ? Cookie.DEFAULT_VERSION : cookie.getVersion());
}
/**
@@ -105,7 +109,10 @@
* @throws IllegalArgumentException if cookie is null
*/
public NewCookie(Cookie cookie, String comment, int maxAge, boolean secure) {
- this(cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getDomain(), cookie.getVersion(), comment, maxAge, secure);
+ this(cookie);
+ this.comment = comment;
+ this.maxAge = maxAge;
+ this.secure = secure;
}
/**
diff --git a/src/jsr311-api/test/javax/ws/rs/core/NewCookieTest.java b/src/jsr311-api/test/javax/ws/rs/core/NewCookieTest.java
new file mode 100644
index 0000000..48567d5
--- /dev/null
+++ b/src/jsr311-api/test/javax/ws/rs/core/NewCookieTest.java
@@ -0,0 +1,56 @@
+/*
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * http://www.opensource.org/licenses/cddl1.php
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package javax.ws.rs.core;
+
+import javax.ws.rs.ext.RuntimeDelegate;
+import junit.framework.TestCase;
+
+public class NewCookieTest extends TestCase {
+
+ public NewCookieTest(String testName) {
+ super(testName);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ RuntimeDelegate.setInstance(new RuntimeDelegateStub());
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ RuntimeDelegate.setInstance(null);
+ }
+
+ /**
+ * Test of valueOf method, of class NewCookie.
+ */
+ public void testCtor() {
+ System.out.println("ctor");
+ Cookie c = new Cookie("name","value");
+ NewCookie nc = new NewCookie(c);
+ assertEquals(nc.getName(), c.getName());
+ try {
+ nc = new NewCookie(null);
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ }
+ try {
+ nc = new NewCookie(null, "comment", 120, true);
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+}