01: /*
02: * Copyright (C) 2006, 2007 XStream Committers.
03: * All rights reserved.
04: *
05: * The software in this package is published under the terms of the BSD
06: * style license a copy of which has been included with this distribution in
07: * the LICENSE.txt file.
08: *
09: * Created on 27. September 2007 by Joerg Schaible
10: */
11: package com.thoughtworks.acceptance;
12:
13: import com.thoughtworks.acceptance.someobjects.Z;
14: import com.thoughtworks.xstream.alias.ClassMapper;
15: import com.thoughtworks.xstream.converters.basic.AbstractBasicConverter;
16:
17: /**
18: * Test XStream 1.1 compatibility.
19: *
20: * @author Jörg Schaible
21: */
22: public class XStream11CompatibilityTest extends AbstractAcceptanceTest {
23: public static class ZConverter extends AbstractBasicConverter {
24:
25: public boolean canConvert(Class type) {
26: return type.equals(Z.class);
27: }
28:
29: protected Object fromString(String str) {
30: return new Z("z");
31: }
32:
33: }
34:
35: public void testUnmarshalsObjectFromXmlWithCustomDefaultConverterBasedOnAbstractBasicConverter() {
36:
37: xstream.registerConverter(new ZConverter(), -20);
38: xstream.alias("z", Z.class);
39:
40: String xml = "<z>" + " <any-old-suff/>" + "</z>";
41:
42: Z z = (Z) xstream.fromXML(xml);
43:
44: assertEquals("z", z.field);
45: }
46:
47: public void testClassMapperCompatibility() {
48: ClassMapper mapper = xstream.getClassMapper();
49: assertEquals("string", mapper.serializedClass(String.class));
50: }
51: }
|