1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.beanutils.converters;
18
19 import junit.framework.TestCase;
20 import junit.framework.TestSuite;
21
22 import org.apache.commons.beanutils.Converter;
23
24 /***
25 * Test Case for the CharacterConverter class.
26 *
27 * @version $Revision: 471350 $ $Date: 2006-11-05 03:10:58 +0000 (Sun, 05 Nov 2006) $
28 */
29 public class CharacterConverterTestCase extends TestCase {
30
31 /***
32 * Construct a new Character Converter test case.
33 * @param name Test Name
34 */
35 public CharacterConverterTestCase(String name) {
36 super(name);
37 }
38
39
40
41 /***
42 * Create Test Suite
43 * @return test suite
44 */
45 public static TestSuite suite() {
46 return new TestSuite(CharacterConverterTestCase.class);
47 }
48
49 /*** Set Up */
50 public void setUp() throws Exception {
51 }
52
53 /*** Tear Down */
54 public void tearDown() throws Exception {
55 }
56
57
58
59
60 /***
61 * Test Conversion to String
62 */
63 public void testConvertToString() {
64
65 Converter converter = new CharacterConverter();
66
67 assertEquals("Character Test", "N", converter.convert(String.class, new Character('N')));
68 assertEquals("String Test", "F", converter.convert(String.class, "FOO"));
69 assertEquals("Integer Test", "3", converter.convert(String.class, new Integer(321)));
70 assertEquals("Null Test", null, converter.convert(String.class, null));
71 }
72
73 /***
74 * Test Conversion to Character
75 */
76 public void testConvertToCharacter() {
77 Converter converter = new CharacterConverter();
78 assertEquals("Character Test", new Character('N'), converter.convert(Character.class, new Character('N')));
79 assertEquals("String Test", new Character('F'), converter.convert(Character.class, "FOO"));
80 assertEquals("Integer Test", new Character('3'), converter.convert(Character.class, new Integer(321)));
81 try {
82 converter.convert(Character.class, null);
83 fail("Expected a ConversionException for null value");
84 } catch (Exception e) {
85
86 }
87 }
88
89 /***
90 * Test Conversion to Character (with default)
91 */
92 public void testDefault() {
93 Converter converter = new CharacterConverter("C");
94 assertEquals("Default Test", new Character('C'), converter.convert(Character.class, null));
95 }
96 }