Skip to content

Commit

Permalink
Make Cookie serializable
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Tolfsen <ato@mozilla.com>
  • Loading branch information
eoff authored and andreastt committed Apr 12, 2014
1 parent 78e4e90 commit 9936a72
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
5 changes: 4 additions & 1 deletion java/client/src/org/openqa/selenium/Cookie.java
Expand Up @@ -16,10 +16,13 @@

package org.openqa.selenium;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Cookie {
public class Cookie implements Serializable {
private static final long serialVersionUID = 4115876353625612383L;

private final String name;
private final String value;
private final String path;
Expand Down
30 changes: 26 additions & 4 deletions java/client/test/org/openqa/selenium/CookieTest.java
Expand Up @@ -16,14 +16,21 @@

package org.openqa.selenium;

import org.junit.Test;

import java.util.Date;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Date;

public class CookieTest {

@Test
Expand Down Expand Up @@ -76,4 +83,19 @@ public void testHttpOnlyDefaultsToFalse() {
Cookie cookie = new Cookie("name", "value");
assertFalse(cookie.isHttpOnly());
}

@Test
public void testCookieSerializes() throws IOException, ClassNotFoundException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
Cookie cookieToSerialize = new Cookie("Fish", "cod", "", "", null, false);

objectOutputStream.writeObject(cookieToSerialize);
byte[] serializedCookie = byteArrayOutputStream.toByteArray();

ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(serializedCookie);
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
Cookie deserializedCookie = (Cookie) objectInputStream.readObject();
assertThat(cookieToSerialize, equalTo(deserializedCookie));
}
}

0 comments on commit 9936a72

Please sign in to comment.