001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.tests.shared;
034:
035: import com.flexive.shared.FxLanguage;
036: import com.flexive.shared.value.FxDate;
037: import com.flexive.shared.value.FxDouble;
038: import com.flexive.shared.value.FxFloat;
039: import com.flexive.shared.value.FxString;
040: import com.flexive.shared.value.renderer.FxValueRenderer;
041: import com.flexive.shared.value.renderer.FxValueRendererFactory;
042: import org.testng.annotations.Test;
043:
044: import java.io.IOException;
045: import java.io.StringWriter;
046: import java.io.Writer;
047: import java.util.Date;
048:
049: /**
050: * FxValueRenderer tests.
051: *
052: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
053: * @version $Rev: 181 $
054: */
055: @Test(groups="shared")
056: public class FxValueRendererTest {
057: private static final FxValueRenderer FORMAT_EN = FxValueRendererFactory
058: .getInstance(new FxLanguage("en"));
059: private static final FxValueRenderer FORMAT_DE = FxValueRendererFactory
060: .getInstance(new FxLanguage("de"));
061:
062: @Test
063: public void dateFormatTest() {
064: FxDate date = new FxDate(new Date(0));
065: String englishDate = FORMAT_EN.format(date);
066: String germanDate = FORMAT_DE.format(date);
067: assert !englishDate.equals(germanDate);
068: }
069:
070: @Test
071: public void floatFormatTest() {
072: FxFloat value = new FxFloat(1234.56f);
073: assert "1,234.56".equals(FORMAT_EN.format(value));
074: assert "1.234,56".equals(FORMAT_DE.format(value));
075: }
076:
077: @Test
078: public void doubleFormatTest() {
079: FxDouble value = new FxDouble(1234.56);
080: assert "1,234.56".equals(FORMAT_EN.format(value));
081: assert "1.234,56".equals(FORMAT_DE.format(value));
082: }
083:
084: @Test
085: public void stringFormatTest() {
086: FxString value = new FxString(true, "default");
087: value.setTranslation(FxLanguage.ENGLISH, "english");
088: value.setTranslation(FxLanguage.GERMAN, "deutsch");
089: assert "english".equals(FORMAT_EN.format(value)) : "Expected english translation, got: "
090: + FORMAT_EN.format(value);
091: assert "deutsch".equals(FORMAT_DE.format(value)) : "Expected german translation, got: "
092: + FORMAT_DE.format(value);
093: }
094:
095: @Test
096: public void renderFormatTest() throws IOException {
097: Writer de = new StringWriter();
098: Writer en = new StringWriter();
099: FxDouble value = new FxDouble(1234.56);
100: FORMAT_EN.render(en, value);
101: FORMAT_DE.render(de, value);
102: assert "1,234.56".equals(en.toString()) : "Expected 1,234.56, got: "
103: + en;
104: assert "1.234,56".equals(de.toString()) : "Expected 1.234,56, got: "
105: + de;
106: }
107:
108: @Test
109: public void renderEmptyTest() {
110: final FxString empty = new FxString(false, "");
111: assert FORMAT_EN.format(empty).equals("") : "Empty string translation should be empty";
112: assert FORMAT_DE.format(empty).equals("") : "Empty string translation should be empty";
113: assert empty.toString().equals("") : "Empty string translation should be empty";
114: }
115: }
|