001: /*
002: * Copyright (C) 2006, 2007 XStream Committers.
003: * All rights reserved.
004: *
005: * The software in this package is published under the terms of the BSD
006: * style license a copy of which has been included with this distribution in
007: * the LICENSE.txt file.
008: *
009: * Created on 19. October 2006 by Joerg Schaible
010: */
011: package com.thoughtworks.acceptance;
012:
013: import com.thoughtworks.xstream.converters.basic.BooleanConverter;
014:
015: import java.util.List;
016: import java.util.ArrayList;
017:
018: /**
019: * @author David Blevins
020: */
021: public class BooleanFieldsTest extends AbstractAcceptanceTest {
022:
023: public static class Musican {
024: public String name;
025: public String genre;
026: public boolean alive;
027:
028: public Musican() {
029: // for JDK 1.3
030: }
031:
032: public Musican(String name, String genre, boolean alive) {
033: this .name = name;
034: this .genre = genre;
035: this .alive = alive;
036: }
037: }
038:
039: public void testTrueFalseValues() {
040: List jazzIcons = new ArrayList();
041: jazzIcons.add(new Musican("Miles Davis", "jazz", false));
042: jazzIcons.add(new Musican("Wynton Marsalis", "jazz", true));
043:
044: xstream.alias("musician", Musican.class);
045:
046: String expectedXml = "<list>\n" + " <musician>\n"
047: + " <name>Miles Davis</name>\n"
048: + " <genre>jazz</genre>\n"
049: + " <alive>false</alive>\n" + " </musician>\n"
050: + " <musician>\n"
051: + " <name>Wynton Marsalis</name>\n"
052: + " <genre>jazz</genre>\n"
053: + " <alive>true</alive>\n" + " </musician>\n"
054: + "</list>";
055:
056: assertBothWays(jazzIcons, expectedXml);
057: }
058:
059: public void testYesNoValues() {
060: List jazzIcons = new ArrayList();
061: jazzIcons.add(new Musican("Miles Davis", "jazz", false));
062: jazzIcons.add(new Musican("Wynton Marsalis", "jazz", true));
063:
064: xstream.alias("musician", Musican.class);
065: xstream.registerConverter(BooleanConverter.YES_NO);
066:
067: String expectedXml = "<list>\n" + " <musician>\n"
068: + " <name>Miles Davis</name>\n"
069: + " <genre>jazz</genre>\n"
070: + " <alive>no</alive>\n" + " </musician>\n"
071: + " <musician>\n"
072: + " <name>Wynton Marsalis</name>\n"
073: + " <genre>jazz</genre>\n"
074: + " <alive>yes</alive>\n" + " </musician>\n"
075: + "</list>";
076:
077: assertBothWays(jazzIcons, expectedXml);
078: }
079:
080: public void testBinaryValues() {
081: List jazzIcons = new ArrayList();
082: jazzIcons.add(new Musican("Miles Davis", "jazz", false));
083: jazzIcons.add(new Musican("Wynton Marsalis", "jazz", true));
084:
085: xstream.alias("musician", Musican.class);
086: xstream.registerConverter(BooleanConverter.BINARY);
087:
088: String expectedXml = "<list>\n" + " <musician>\n"
089: + " <name>Miles Davis</name>\n"
090: + " <genre>jazz</genre>\n"
091: + " <alive>0</alive>\n" + " </musician>\n"
092: + " <musician>\n"
093: + " <name>Wynton Marsalis</name>\n"
094: + " <genre>jazz</genre>\n"
095: + " <alive>1</alive>\n" + " </musician>\n"
096: + "</list>";
097:
098: assertBothWays(jazzIcons, expectedXml);
099: }
100:
101: }
|