01: /*
02: * Copyright (C) 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 06. November 2007 by Joerg Schaible
10: */
11: package com.thoughtworks.acceptance;
12:
13: import com.thoughtworks.xstream.XStream;
14: import com.thoughtworks.xstream.converters.basic.BooleanConverter;
15: import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;
16: import com.thoughtworks.xstream.converters.reflection.ReflectionConverter;
17:
18: /**
19: * @author Jörg Schaible
20: */
21: public class LocalConverterTest extends AbstractAcceptanceTest {
22:
23: public static class MultiBoolean {
24: private boolean bool;
25: private boolean speech;
26: private boolean bit;
27:
28: private MultiBoolean() {
29: this (false, false, false);
30: }
31:
32: public MultiBoolean(boolean bool, boolean speech, boolean bit) {
33: this .bool = bool;
34: this .speech = speech;
35: this .bit = bit;
36: }
37:
38: }
39:
40: protected void setUp() throws Exception {
41: super .setUp();
42: xstream.alias("mbool", MultiBoolean.class);
43: xstream.registerConverter(new ReflectionConverter(xstream
44: .getMapper(), new PureJavaReflectionProvider()),
45: XStream.PRIORITY_VERY_LOW);
46: }
47:
48: public void testCanBeAppliedToIndividualFields() {
49: MultiBoolean multiBool = new MultiBoolean(true, true, true);
50: String xml = "" + "<mbool>\n" + " <bool>true</bool>\n"
51: + " <speech>yes</speech>\n" + " <bit>1</bit>\n"
52: + "</mbool>";
53:
54: xstream.registerLocalConverter(MultiBoolean.class, "speech",
55: BooleanConverter.YES_NO);
56: xstream.registerLocalConverter(MultiBoolean.class, "bit",
57: BooleanConverter.BINARY);
58: assertBothWays(multiBool, xml);
59: }
60: }
|