/*
 * Copyright (C) 2004, 2005 Joe Walnes.
 * Copyright (C) 2006, 2007 XStream Committers.
 * All rights reserved.
 *
 * The software in this package is published under the terms of the BSD
 * style license a copy of which has been included with this distribution in
 * the LICENSE.txt file.
 * 
 * Created on 30. May 2004 by Joe Walnes
 */
package com.thoughtworks.acceptance;

import com.thoughtworks.acceptance.objects.StatusEnum;

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

/**
 * @author Chris Kelly
 * @author Joe Walnes
 */ 
public class ReadResolveTest extends AbstractAcceptanceTest {

    public void testReadResolveWithDefaultSerialization() throws IOException, ClassNotFoundException {
        StatusEnum status = StatusEnum.STARTED;

        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        ObjectOutputStream os = new ObjectOutputStream(bout);
        os.writeObject(status);

        byte[] bArray = bout.toByteArray();
        StatusEnum rStatus = null;
        ObjectInputStream in = null;

        ByteArrayInputStream bin = new ByteArrayInputStream(bArray);
        in = new ObjectInputStream(bin);
        rStatus = (StatusEnum) in.readObject();
        assertNotNull(rStatus);

        assertSame(status, rStatus);
    }

    public void testReadResolveWithXStream() {
        StatusEnum status = StatusEnum.STARTED;

        String xml = xstream.toXML(status);
        StatusEnum rStatus = (StatusEnum) xstream.fromXML(xml);

        assertSame(status, rStatus);
    }
}

@@ -63,16 +63,22 @@
 06, 2007
+, 2014
  XStream
@@ -90,16 +90,16 @@
 itters.%0A
-
  * All r
@@ -605,16 +605,45 @@
 tStream;
+%0Aimport java.io.Serializable;
 %0A%0A/**%0A *
@@ -1619,24 +1619,24 @@
 mXML(xml);%0A%0A
-
         asse
@@ -1666,10 +1666,960 @@
 ;%0A    %7D%0A
+    %0A    public static class ResolveToNull implements Serializable %7B%0A        private String name;%0A        public ResolveToNull(String name) %7B%0A            this.name = name;%0A        %7D%0A        private Object readResolve() %7B%0A            return null;%0A        %7D%0A    %7D%0A    %0A    public void testResolveToNull() throws IOException, ClassNotFoundException %7B%0A        ResolveToNull obj = new ResolveToNull(%22test%22);%0A        %0A        ByteArrayOutputStream bout = new ByteArrayOutputStream();%0A        ObjectOutputStream os = new ObjectOutputStream(bout);%0A        os.writeObject(obj);%0A        %0A        byte%5B%5D bArray = bout.toByteArray();%0A        ObjectInputStream in = null;%0A        ByteArrayInputStream bin = new ByteArrayInputStream(bArray);%0A        in = new ObjectInputStream(bin);%0A        assertNull(in.readObject());%0A        %0A        xstream.alias(%22toNull%22, ResolveToNull.class);%0A        assertNull(xstream.fromXML(%22%3CtoNull%3E%3Cname%3Etest%3C/name%3E%3C/toNull%3E%22));%0A    %7D%0A
 %7D%0A

Test resolve to null (invalidates XSTR-764).