/* * 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 19. October 2006 by Joerg Schaible */ package com.thoughtworks.acceptance; import com.thoughtworks.xstream.converters.basic.BooleanConverter; import java.util.List; import java.util.ArrayList; /** * @author David Blevins */ public class BooleanFieldsTest extends AbstractAcceptanceTest { public static class Musican { public String name; public String genre; public boolean alive; public Musican() { // for JDK 1.3 } public Musican(String name, String genre, boolean alive) { this.name = name; this.genre = genre; this.alive = alive; } } public void testTrueFalseValues() { List jazzIcons = new ArrayList(); jazzIcons.add(new Musican("Miles Davis", "jazz", false)); jazzIcons.add(new Musican("Wynton Marsalis", "jazz", true)); xstream.alias("musician", Musican.class); String expectedXml = "\n" + " \n" + " Miles Davis\n" + " jazz\n" + " false\n" + " \n" + " \n" + " Wynton Marsalis\n" + " jazz\n" + " true\n" + " \n" + ""; assertBothWays(jazzIcons, expectedXml); } public void testYesNoValues() { List jazzIcons = new ArrayList(); jazzIcons.add(new Musican("Miles Davis", "jazz", false)); jazzIcons.add(new Musican("Wynton Marsalis", "jazz", true)); xstream.alias("musician", Musican.class); xstream.registerConverter(BooleanConverter.YES_NO); String expectedXml = "\n" + " \n" + " Miles Davis\n" + " jazz\n" + " no\n" + " \n" + " \n" + " Wynton Marsalis\n" + " jazz\n" + " yes\n" + " \n" + ""; assertBothWays(jazzIcons, expectedXml); } public void testBinaryValues() { List jazzIcons = new ArrayList(); jazzIcons.add(new Musican("Miles Davis", "jazz", false)); jazzIcons.add(new Musican("Wynton Marsalis", "jazz", true)); xstream.alias("musician", Musican.class); xstream.registerConverter(BooleanConverter.BINARY); String expectedXml = "\n" + " \n" + " Miles Davis\n" + " jazz\n" + " 0\n" + " \n" + " \n" + " Wynton Marsalis\n" + " jazz\n" + " 1\n" + " \n" + ""; assertBothWays(jazzIcons, expectedXml); } }