001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.commons.beanutils.converters;
018:
019: import junit.framework.TestCase;
020: import junit.framework.TestSuite;
021:
022: import org.apache.commons.beanutils.Converter;
023:
024: /**
025: * Test Case for the CharacterConverter class.
026: *
027: * @version $Revision: 471350 $ $Date: 2006-11-05 03:10:58 +0000 (Sun, 05 Nov 2006) $
028: */
029: public class CharacterConverterTestCase extends TestCase {
030:
031: /**
032: * Construct a new Character Converter test case.
033: * @param name Test Name
034: */
035: public CharacterConverterTestCase(String name) {
036: super (name);
037: }
038:
039: // ------------------------------------------------------------------------
040:
041: /**
042: * Create Test Suite
043: * @return test suite
044: */
045: public static TestSuite suite() {
046: return new TestSuite(CharacterConverterTestCase.class);
047: }
048:
049: /** Set Up */
050: public void setUp() throws Exception {
051: }
052:
053: /** Tear Down */
054: public void tearDown() throws Exception {
055: }
056:
057: // ------------------------------------------------------------------------
058:
059: /**
060: * Test Conversion to String
061: */
062: public void testConvertToString() {
063:
064: Converter converter = new CharacterConverter();
065:
066: assertEquals("Character Test", "N", converter.convert(
067: String.class, new Character('N')));
068: assertEquals("String Test", "F", converter.convert(
069: String.class, "FOO"));
070: assertEquals("Integer Test", "3", converter.convert(
071: String.class, new Integer(321)));
072: assertEquals("Null Test", null, converter.convert(String.class,
073: null));
074: }
075:
076: /**
077: * Test Conversion to Character
078: */
079: public void testConvertToCharacter() {
080: Converter converter = new CharacterConverter();
081: assertEquals("Character Test", new Character('N'), converter
082: .convert(Character.class, new Character('N')));
083: assertEquals("String Test", new Character('F'), converter
084: .convert(Character.class, "FOO"));
085: assertEquals("Integer Test", new Character('3'), converter
086: .convert(Character.class, new Integer(321)));
087: try {
088: converter.convert(Character.class, null);
089: fail("Expected a ConversionException for null value");
090: } catch (Exception e) {
091: // expected result
092: }
093: }
094:
095: /**
096: * Test Conversion to Character (with default)
097: */
098: public void testDefault() {
099: Converter converter = new CharacterConverter("C");
100: assertEquals("Default Test", new Character('C'), converter
101: .convert(Character.class, null));
102: }
103: }
|