package xstream.test; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.StreamException; import com.thoughtworks.xstream.io.xml.StaxDriver; import com.thoughtworks.xstream.io.xml.StaxWriter; public class StaxDriverTest { private static class MyStaxDriver extends StaxDriver { public boolean createStaxWriter1Called = false; public boolean createStaxWriter2Called = false; public StaxWriter createStaxWriter(XMLStreamWriter out) throws StreamException { createStaxWriter1Called = true; try { return super.createStaxWriter(out); } catch ( XMLStreamException e) { throw new StreamException(e); } } public StaxWriter createStaxWriter(XMLStreamWriter out, boolean writeStartEndDocument) throws StreamException { createStaxWriter2Called = true; try { return super.createStaxWriter(out, writeStartEndDocument); } catch ( XMLStreamException e) { throw new StreamException(e); } } } public StaxDriverTest() { } public static void main(String[] args) { MyStaxDriver driver = new MyStaxDriver(); XStream xstream = new XStream(driver); xstream.toXML(new StaxDriverTest(), System.out); if ( driver.createStaxWriter1Called || driver.createStaxWriter2Called ) System.out.println("OK"); else { System.out.println("Fail"); throw new RuntimeException("test failed"); } } }