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