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.ConversionException;
23 import org.apache.commons.beanutils.Converter;
24
25
26
27
28
29
30 public class CharacterConverterTestCase extends TestCase {
31
32
33
34
35
36 public CharacterConverterTestCase(final String name) {
37 super(name);
38 }
39
40
41
42
43
44
45
46 public static TestSuite suite() {
47 return new TestSuite(CharacterConverterTestCase.class);
48 }
49
50
51 @Override
52 public void setUp() throws Exception {
53 }
54
55
56 @Override
57 public void tearDown() throws Exception {
58 }
59
60
61
62
63
64
65
66 public void testConvertToString() {
67
68 final Converter converter = new CharacterConverter();
69
70 assertEquals("Character Test", "N", converter.convert(String.class, new Character('N')));
71 assertEquals("String Test", "F", converter.convert(String.class, "FOO"));
72 assertEquals("Integer Test", "3", converter.convert(String.class, new Integer(321)));
73 assertEquals("Null Test", null, converter.convert(String.class, null));
74 }
75
76
77
78
79 public void testConvertToCharacter() {
80 final Converter converter = new CharacterConverter();
81 assertEquals("Character Test", new Character('N'), converter.convert(Character.class, new Character('N')));
82 assertEquals("String Test", new Character('F'), converter.convert(Character.class, "FOO"));
83 assertEquals("Integer Test", new Character('3'), converter.convert(Character.class, new Integer(321)));
84 }
85
86
87
88
89 public void testConvertToChar() {
90 final Converter converter = new CharacterConverter();
91 assertEquals("Wrong result", new Character('F'), converter.convert(Character.TYPE, "FOO"));
92 }
93
94
95
96
97
98 public void testConvertToCharacterNullNoDefault() {
99 final Converter converter = new CharacterConverter();
100 try {
101 converter.convert(Character.class, null);
102 fail("Expected a ConversionException for null value");
103 } catch (final Exception e) {
104
105 }
106 }
107
108
109
110
111 public void testDefault() {
112 final Converter converter = new CharacterConverter("C");
113 assertEquals("Default Test", new Character('C'), converter.convert(Character.class, null));
114 }
115
116
117
118
119 public void testConvertToUnsupportedType() {
120 final Converter converter = new CharacterConverter();
121 try {
122 converter.convert(Integer.class, "Test");
123 fail("Could convert to unsupported type!");
124 } catch (final ConversionException cex) {
125
126 }
127 }
128 }