/*
 * Copyright (C) 2006 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 04. June 2006 by Joe Walnes
 */
package com.thoughtworks.xstream.io.copy;

import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.io.xml.AbstractXMLReaderTest;
import com.thoughtworks.xstream.io.xml.CompactWriter;
import com.thoughtworks.xstream.io.xml.XppReader;

import java.io.StringReader;
import java.io.StringWriter;

public class HierarchicalStreamCopierTest extends AbstractXMLReaderTest {

    private HierarchicalStreamCopier copier = new HierarchicalStreamCopier();

    // This test leverages the existing (comprehensive) tests for the XML readers
    // and adds an additional stage of copying in.

    // factory method - overriding base class.
    protected HierarchicalStreamReader createReader(String xml) throws Exception {
        HierarchicalStreamReader sourceReader = new XppReader(new StringReader(xml));

        StringWriter buffer = new StringWriter();
        HierarchicalStreamWriter destinationWriter = new CompactWriter(buffer);

        copier.copy(sourceReader, destinationWriter);

        return new XppReader(new StringReader(buffer.toString()));
    }

    public void testSkipsValueIfEmpty() {
        String input = "<root><empty1/><empty2></empty2><not-empty>blah</not-empty></root>";
        String expected = "<root><empty1/><empty2/><not-empty>blah</not-empty></root>";
        HierarchicalStreamReader sourceReader = new XppReader(new StringReader(input));

        StringWriter buffer = new StringWriter();
        HierarchicalStreamWriter destinationWriter = new CompactWriter(buffer);

        copier.copy(sourceReader, destinationWriter);

        assertEquals(expected, buffer.toString());
    }

}

@@ -57,16 +57,22 @@
 06, 2007
+, 2011
  XStream
@@ -665,16 +665,121 @@
 pReader;
+%0Aimport com.thoughtworks.xstream.io.xml.xppdom.XppFactory;%0A%0Aimport org.xmlpull.v1.XmlPullParserException;
 %0A%0Aimport
@@ -1303,32 +1303,45 @@
 = new XppReader(
+%0A            
 new StringReader
@@ -1345,16 +1345,50 @@
 der(xml)
+, XppFactory.createDefaultParser()
 );%0A%0A    
@@ -1633,16 +1633,50 @@
 tring())
+, XppFactory.createDefaultParser()
 );%0A    %7D
@@ -1716,16 +1716,46 @@
 fEmpty()
+ throws XmlPullParserException
  %7B%0A     
@@ -1984,32 +1984,45 @@
 = new XppReader(
+%0A            
 new StringReader
@@ -2028,16 +2028,50 @@
 r(input)
+, XppFactory.createDefaultParser()
 );%0A%0A    

Replace deprecated stuff.