1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.beanutils.converters;
19
20 import junit.framework.TestSuite;
21
22 import org.apache.commons.beanutils.Converter;
23
24
25 /***
26 * Test Case for the LongConverter class.
27 *
28 * @author Rodney Waldhoff
29 * @version $Revision: 471348 $ $Date: 2006-11-05 02:59:26 +0000 (Sun, 05 Nov 2006) $
30 */
31
32 public class LongConverterTestCase extends NumberConverterTestBase {
33
34 private Converter converter = null;
35
36
37
38 public LongConverterTestCase(String name) {
39 super(name);
40 }
41
42
43
44 public void setUp() throws Exception {
45 converter = makeConverter();
46 numbers[0] = new Long("-12");
47 numbers[1] = new Long("13");
48 numbers[2] = new Long("-22");
49 numbers[3] = new Long("23");
50 }
51
52 public static TestSuite suite() {
53 return new TestSuite(LongConverterTestCase.class);
54 }
55
56 public void tearDown() throws Exception {
57 converter = null;
58 }
59
60
61
62 protected NumberConverter makeConverter() {
63 return new LongConverter();
64 }
65
66 protected NumberConverter makeConverter(Object defaultValue) {
67 return new LongConverter(defaultValue);
68 }
69
70 protected Class getExpectedType() {
71 return Long.class;
72 }
73
74
75
76 public void testSimpleConversion() throws Exception {
77 String[] message= {
78 "from String",
79 "from String",
80 "from String",
81 "from String",
82 "from String",
83 "from String",
84 "from String",
85 "from Byte",
86 "from Short",
87 "from Integer",
88 "from Long",
89 "from Float",
90 "from Double"
91 };
92
93 Object[] input = {
94 String.valueOf(Long.MIN_VALUE),
95 "-17",
96 "-1",
97 "0",
98 "1",
99 "17",
100 String.valueOf(Long.MAX_VALUE),
101 new Byte((byte)7),
102 new Short((short)8),
103 new Integer(9),
104 new Long(10),
105 new Float(11.1),
106 new Double(12.2)
107 };
108
109 Long[] expected = {
110 new Long(Long.MIN_VALUE),
111 new Long(-17),
112 new Long(-1),
113 new Long(0),
114 new Long(1),
115 new Long(17),
116 new Long(Long.MAX_VALUE),
117 new Long(7),
118 new Long(8),
119 new Long(9),
120 new Long(10),
121 new Long(11),
122 new Long(12)
123 };
124
125 for(int i=0;i<expected.length;i++) {
126 assertEquals(message[i] + " to Long",expected[i],converter.convert(Long.class,input[i]));
127 assertEquals(message[i] + " to long",expected[i],converter.convert(Long.TYPE,input[i]));
128 assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i]));
129 }
130 }
131
132 }
133