KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > service > cmr > repository > datatype > DefaultTypeConverterTest


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.service.cmr.repository.datatype;
18
19 import java.math.BigDecimal JavaDoc;
20 import java.math.BigInteger JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.Date JavaDoc;
23
24 import junit.framework.TestCase;
25
26 import org.alfresco.util.ISO8601DateFormat;
27
28 public class DefaultTypeConverterTest extends TestCase
29 {
30
31     public DefaultTypeConverterTest()
32     {
33         super();
34     }
35
36     public DefaultTypeConverterTest(String JavaDoc arg0)
37     {
38         super(arg0);
39     }
40
41     public void testPrimitives()
42     {
43         assertEquals(Boolean.valueOf(false), DefaultTypeConverter.INSTANCE.convert(Boolean JavaDoc.class, false));
44         assertEquals(Boolean.valueOf(true), DefaultTypeConverter.INSTANCE.convert(Boolean JavaDoc.class, true));
45         assertEquals(Character.valueOf('a'), DefaultTypeConverter.INSTANCE.convert(Character JavaDoc.class, 'a'));
46         assertEquals(Byte.valueOf("3"), DefaultTypeConverter.INSTANCE.convert(Byte JavaDoc.class, (byte) 3));
47         assertEquals(Short.valueOf("4"), DefaultTypeConverter.INSTANCE.convert(Short JavaDoc.class, (short) 4));
48         assertEquals(Integer.valueOf("5"), DefaultTypeConverter.INSTANCE.convert(Integer JavaDoc.class, (int) 5));
49         assertEquals(Long.valueOf("6"), DefaultTypeConverter.INSTANCE.convert(Long JavaDoc.class, (long) 6));
50         assertEquals(Float.valueOf("7.1"), DefaultTypeConverter.INSTANCE.convert(Float JavaDoc.class, (float) 7.1));
51         assertEquals(Double.valueOf("123.123"), DefaultTypeConverter.INSTANCE.convert(Double JavaDoc.class, (double) 123.123));
52     }
53
54     public void testNoConversion()
55     {
56         assertEquals(Boolean.valueOf(false), DefaultTypeConverter.INSTANCE.convert(Boolean JavaDoc.class, Boolean.valueOf(false)));
57         assertEquals(Boolean.valueOf(true), DefaultTypeConverter.INSTANCE.convert(Boolean JavaDoc.class, Boolean.valueOf(true)));
58         assertEquals(Character.valueOf('w'), DefaultTypeConverter.INSTANCE.convert(Character JavaDoc.class, Character.valueOf('w')));
59         assertEquals(Byte.valueOf("3"), DefaultTypeConverter.INSTANCE.convert(Byte JavaDoc.class, Byte.valueOf("3")));
60         assertEquals(Short.valueOf("4"), DefaultTypeConverter.INSTANCE.convert(Short JavaDoc.class, Short.valueOf("4")));
61         assertEquals(Integer.valueOf("5"), DefaultTypeConverter.INSTANCE.convert(Integer JavaDoc.class, Integer.valueOf("5")));
62         assertEquals(Long.valueOf("6"), DefaultTypeConverter.INSTANCE.convert(Long JavaDoc.class, Long.valueOf("6")));
63         assertEquals(Float.valueOf("7.1"), DefaultTypeConverter.INSTANCE.convert(Float JavaDoc.class, Float.valueOf("7.1")));
64         assertEquals(Double.valueOf("123.123"), DefaultTypeConverter.INSTANCE.convert(Double JavaDoc.class, Double.valueOf("123.123")));
65         assertEquals(Double.valueOf("123.123"), DefaultTypeConverter.INSTANCE.convert(Double JavaDoc.class, Double.valueOf("123.123")));
66         assertEquals(new BigInteger JavaDoc("1234567890123456789"), DefaultTypeConverter.INSTANCE.convert(BigInteger JavaDoc.class, new BigInteger JavaDoc("1234567890123456789")));
67         assertEquals(new BigDecimal JavaDoc("12345678901234567890.12345678901234567890"), DefaultTypeConverter.INSTANCE.convert(BigDecimal JavaDoc.class, new BigDecimal JavaDoc("12345678901234567890.12345678901234567890")));
68         Date JavaDoc date = new Date JavaDoc();
69         assertEquals(date, DefaultTypeConverter.INSTANCE.convert(Date JavaDoc.class, date));
70         assertEquals(new Duration("P25D"), DefaultTypeConverter.INSTANCE.convert(Duration.class, new Duration("P25D")));
71         assertEquals("woof", DefaultTypeConverter.INSTANCE.convert(String JavaDoc.class, "woof"));
72     }
73
74     public void testToString()
75     {
76         assertEquals("true", DefaultTypeConverter.INSTANCE.convert(String JavaDoc.class, new Boolean JavaDoc(true)));
77         assertEquals("false", DefaultTypeConverter.INSTANCE.convert(String JavaDoc.class, new Boolean JavaDoc(false)));
78         assertEquals("v", DefaultTypeConverter.INSTANCE.convert(String JavaDoc.class, Character.valueOf('v')));
79         assertEquals("3", DefaultTypeConverter.INSTANCE.convert(String JavaDoc.class, Byte.valueOf("3")));
80         assertEquals("4", DefaultTypeConverter.INSTANCE.convert(String JavaDoc.class, Short.valueOf("4")));
81         assertEquals("5", DefaultTypeConverter.INSTANCE.convert(String JavaDoc.class, Integer.valueOf("5")));
82         assertEquals("6", DefaultTypeConverter.INSTANCE.convert(String JavaDoc.class, Long.valueOf("6")));
83         assertEquals("7.1", DefaultTypeConverter.INSTANCE.convert(String JavaDoc.class, Float.valueOf("7.1")));
84         assertEquals("123.123", DefaultTypeConverter.INSTANCE.convert(String JavaDoc.class, Double.valueOf("123.123")));
85         assertEquals("1234567890123456789", DefaultTypeConverter.INSTANCE.convert(String JavaDoc.class, new BigInteger JavaDoc("1234567890123456789")));
86         assertEquals("12345678901234567890.12345678901234567890", DefaultTypeConverter.INSTANCE.convert(String JavaDoc.class, new BigDecimal JavaDoc("12345678901234567890.12345678901234567890")));
87         Date JavaDoc date = new Date JavaDoc();
88         assertEquals(ISO8601DateFormat.format(date), DefaultTypeConverter.INSTANCE.convert(String JavaDoc.class, date));
89         assertEquals("P0Y25D", DefaultTypeConverter.INSTANCE.convert(String JavaDoc.class, new Duration("P0Y25D")));
90         assertEquals("woof", DefaultTypeConverter.INSTANCE.convert(String JavaDoc.class, "woof"));
91     }
92
93     public void testFromString()
94     {
95         assertEquals(Boolean.valueOf(true), DefaultTypeConverter.INSTANCE.convert(Boolean JavaDoc.class, "True"));
96         assertEquals(Boolean.valueOf(false), DefaultTypeConverter.INSTANCE.convert(Boolean JavaDoc.class, "woof"));
97         assertEquals(Character.valueOf('w'), DefaultTypeConverter.INSTANCE.convert(Character JavaDoc.class, "w"));
98         assertEquals(Byte.valueOf("3"), DefaultTypeConverter.INSTANCE.convert(Byte JavaDoc.class, "3"));
99         assertEquals(Short.valueOf("4"), DefaultTypeConverter.INSTANCE.convert(Short JavaDoc.class, "4"));
100         assertEquals(Integer.valueOf("5"), DefaultTypeConverter.INSTANCE.convert(Integer JavaDoc.class, "5"));
101         assertEquals(Long.valueOf("6"), DefaultTypeConverter.INSTANCE.convert(Long JavaDoc.class, "6"));
102         assertEquals(Float.valueOf("7.1"), DefaultTypeConverter.INSTANCE.convert(Float JavaDoc.class, "7.1"));
103         assertEquals(Double.valueOf("123.123"), DefaultTypeConverter.INSTANCE.convert(Double JavaDoc.class, "123.123"));
104         assertEquals(new BigInteger JavaDoc("1234567890123456789"), DefaultTypeConverter.INSTANCE.convert(BigInteger JavaDoc.class, "1234567890123456789"));
105         assertEquals(new BigDecimal JavaDoc("12345678901234567890.12345678901234567890"), DefaultTypeConverter.INSTANCE.convert(BigDecimal JavaDoc.class, "12345678901234567890.12345678901234567890"));
106         assertEquals("2004-03-12T00:00:00.000Z", ISO8601DateFormat.format(DefaultTypeConverter.INSTANCE.convert(Date JavaDoc.class, "2004-03-12T00:00:00.000Z")));
107         assertEquals(new Duration("P25D"), DefaultTypeConverter.INSTANCE.convert(Duration.class, "P25D"));
108         assertEquals("woof", DefaultTypeConverter.INSTANCE.convert(String JavaDoc.class, "woof"));
109     }
110
111     public void testPrimativeAccessors()
112     {
113         assertEquals(false, DefaultTypeConverter.INSTANCE.convert(Boolean JavaDoc.class, false).booleanValue());
114         assertEquals(true, DefaultTypeConverter.INSTANCE.convert(Boolean JavaDoc.class, true).booleanValue());
115         assertEquals('a', DefaultTypeConverter.INSTANCE.convert(Character JavaDoc.class, 'a').charValue());
116         assertEquals((byte) 3, DefaultTypeConverter.INSTANCE.convert(Byte JavaDoc.class, (byte) 3).byteValue());
117         assertEquals((short) 4, DefaultTypeConverter.INSTANCE.convert(Short JavaDoc.class, (short) 4).shortValue());
118         assertEquals((int) 5, DefaultTypeConverter.INSTANCE.convert(Integer JavaDoc.class, (int) 5).intValue());
119         assertEquals((long) 6, DefaultTypeConverter.INSTANCE.convert(Long JavaDoc.class, (long) 6).longValue());
120         assertEquals((float) 7.1, DefaultTypeConverter.INSTANCE.convert(Float JavaDoc.class, (float) 7.1).floatValue());
121         assertEquals((double) 123.123, DefaultTypeConverter.INSTANCE.convert(Double JavaDoc.class, (double) 123.123).doubleValue());
122     }
123     
124     public void testInterConversions()
125     {
126         assertEquals(Byte.valueOf("1"), DefaultTypeConverter.INSTANCE.convert(Byte JavaDoc.class, Byte.valueOf("1")));
127         assertEquals(Short.valueOf("2"), DefaultTypeConverter.INSTANCE.convert(Short JavaDoc.class, Byte.valueOf("2")));
128         assertEquals(Integer.valueOf("3"), DefaultTypeConverter.INSTANCE.convert(Integer JavaDoc.class, Byte.valueOf("3")));
129         assertEquals(Long.valueOf("4"), DefaultTypeConverter.INSTANCE.convert(Long JavaDoc.class, Byte.valueOf("4")));
130         assertEquals(Float.valueOf("5"), DefaultTypeConverter.INSTANCE.convert(Float JavaDoc.class, Byte.valueOf("5")));
131         assertEquals(Double.valueOf("6"), DefaultTypeConverter.INSTANCE.convert(Double JavaDoc.class, Byte.valueOf("6")));
132         assertEquals(new BigInteger JavaDoc("7"), DefaultTypeConverter.INSTANCE.convert(BigInteger JavaDoc.class, Byte.valueOf("7")));
133         assertEquals(new BigDecimal JavaDoc("8"), DefaultTypeConverter.INSTANCE.convert(BigDecimal JavaDoc.class, Byte.valueOf("8")));
134         
135         assertEquals(Byte.valueOf("1"), DefaultTypeConverter.INSTANCE.convert(Byte JavaDoc.class, Short.valueOf("1")));
136         assertEquals(Short.valueOf("2"), DefaultTypeConverter.INSTANCE.convert(Short JavaDoc.class, Short.valueOf("2")));
137         assertEquals(Integer.valueOf("3"), DefaultTypeConverter.INSTANCE.convert(Integer JavaDoc.class, Short.valueOf("3")));
138         assertEquals(Long.valueOf("4"), DefaultTypeConverter.INSTANCE.convert(Long JavaDoc.class, Short.valueOf("4")));
139         assertEquals(Float.valueOf("5"), DefaultTypeConverter.INSTANCE.convert(Float JavaDoc.class, Short.valueOf("5")));
140         assertEquals(Double.valueOf("6"), DefaultTypeConverter.INSTANCE.convert(Double JavaDoc.class, Short.valueOf("6")));
141         assertEquals(new BigInteger JavaDoc("7"), DefaultTypeConverter.INSTANCE.convert(BigInteger JavaDoc.class, Short.valueOf("7")));
142         assertEquals(new BigDecimal JavaDoc("8"), DefaultTypeConverter.INSTANCE.convert(BigDecimal JavaDoc.class, Short.valueOf("8")));
143         
144         assertEquals(Byte.valueOf("1"), DefaultTypeConverter.INSTANCE.convert(Byte JavaDoc.class, Integer.valueOf("1")));
145         assertEquals(Short.valueOf("2"), DefaultTypeConverter.INSTANCE.convert(Short JavaDoc.class, Integer.valueOf("2")));
146         assertEquals(Integer.valueOf("3"), DefaultTypeConverter.INSTANCE.convert(Integer JavaDoc.class, Integer.valueOf("3")));
147         assertEquals(Long.valueOf("4"), DefaultTypeConverter.INSTANCE.convert(Long JavaDoc.class, Integer.valueOf("4")));
148         assertEquals(Float.valueOf("5"), DefaultTypeConverter.INSTANCE.convert(Float JavaDoc.class, Integer.valueOf("5")));
149         assertEquals(Double.valueOf("6"), DefaultTypeConverter.INSTANCE.convert(Double JavaDoc.class, Integer.valueOf("6")));
150         assertEquals(new BigInteger JavaDoc("7"), DefaultTypeConverter.INSTANCE.convert(BigInteger JavaDoc.class, Integer.valueOf("7")));
151         assertEquals(new BigDecimal JavaDoc("8"), DefaultTypeConverter.INSTANCE.convert(BigDecimal JavaDoc.class, Integer.valueOf("8")));
152         
153         assertEquals(Byte.valueOf("1"), DefaultTypeConverter.INSTANCE.convert(Byte JavaDoc.class, Long.valueOf("1")));
154         assertEquals(Short.valueOf("2"), DefaultTypeConverter.INSTANCE.convert(Short JavaDoc.class, Long.valueOf("2")));
155         assertEquals(Integer.valueOf("3"), DefaultTypeConverter.INSTANCE.convert(Integer JavaDoc.class, Long.valueOf("3")));
156         assertEquals(Long.valueOf("4"), DefaultTypeConverter.INSTANCE.convert(Long JavaDoc.class, Long.valueOf("4")));
157         assertEquals(Float.valueOf("5"), DefaultTypeConverter.INSTANCE.convert(Float JavaDoc.class, Long.valueOf("5")));
158         assertEquals(Double.valueOf("6"), DefaultTypeConverter.INSTANCE.convert(Double JavaDoc.class, Long.valueOf("6")));
159         assertEquals(new BigInteger JavaDoc("7"), DefaultTypeConverter.INSTANCE.convert(BigInteger JavaDoc.class, Long.valueOf("7")));
160         assertEquals(new BigDecimal JavaDoc("8"), DefaultTypeConverter.INSTANCE.convert(BigDecimal JavaDoc.class, Long.valueOf("8")));
161         
162         assertEquals(Byte.valueOf("1"), DefaultTypeConverter.INSTANCE.convert(Byte JavaDoc.class, Float.valueOf("1")));
163         assertEquals(Short.valueOf("2"), DefaultTypeConverter.INSTANCE.convert(Short JavaDoc.class, Float.valueOf("2")));
164         assertEquals(Integer.valueOf("3"), DefaultTypeConverter.INSTANCE.convert(Integer JavaDoc.class, Float.valueOf("3")));
165         assertEquals(Long.valueOf("4"), DefaultTypeConverter.INSTANCE.convert(Long JavaDoc.class, Float.valueOf("4")));
166         assertEquals(Float.valueOf("5"), DefaultTypeConverter.INSTANCE.convert(Float JavaDoc.class, Float.valueOf("5")));
167         assertEquals(Double.valueOf("6"), DefaultTypeConverter.INSTANCE.convert(Double JavaDoc.class, Float.valueOf("6")));
168         assertEquals(new BigInteger JavaDoc("7"), DefaultTypeConverter.INSTANCE.convert(BigInteger JavaDoc.class, Float.valueOf("7")));
169         assertEquals(new BigDecimal JavaDoc("8"), DefaultTypeConverter.INSTANCE.convert(BigDecimal JavaDoc.class, Float.valueOf("8")));
170         
171         assertEquals(Byte.valueOf("1"), DefaultTypeConverter.INSTANCE.convert(Byte JavaDoc.class, Double.valueOf("1")));
172         assertEquals(Short.valueOf("2"), DefaultTypeConverter.INSTANCE.convert(Short JavaDoc.class, Double.valueOf("2")));
173         assertEquals(Integer.valueOf("3"), DefaultTypeConverter.INSTANCE.convert(Integer JavaDoc.class, Double.valueOf("3")));
174         assertEquals(Long.valueOf("4"), DefaultTypeConverter.INSTANCE.convert(Long JavaDoc.class, Double.valueOf("4")));
175         assertEquals(Float.valueOf("5"), DefaultTypeConverter.INSTANCE.convert(Float JavaDoc.class, Double.valueOf("5")));
176         assertEquals(Double.valueOf("6"), DefaultTypeConverter.INSTANCE.convert(Double JavaDoc.class, Double.valueOf("6")));
177         assertEquals(new BigInteger JavaDoc("7"), DefaultTypeConverter.INSTANCE.convert(BigInteger JavaDoc.class, Double.valueOf("7")));
178         assertEquals(new BigDecimal JavaDoc("8"), DefaultTypeConverter.INSTANCE.convert(BigDecimal JavaDoc.class, Double.valueOf("8")));
179         
180         assertEquals(Byte.valueOf("1"), DefaultTypeConverter.INSTANCE.convert(Byte JavaDoc.class, new BigInteger JavaDoc("1")));
181         assertEquals(Short.valueOf("2"), DefaultTypeConverter.INSTANCE.convert(Short JavaDoc.class, new BigInteger JavaDoc("2")));
182         assertEquals(Integer.valueOf("3"), DefaultTypeConverter.INSTANCE.convert(Integer JavaDoc.class, new BigInteger JavaDoc("3")));
183         assertEquals(Long.valueOf("4"), DefaultTypeConverter.INSTANCE.convert(Long JavaDoc.class, new BigInteger JavaDoc("4")));
184         assertEquals(Float.valueOf("5"), DefaultTypeConverter.INSTANCE.convert(Float JavaDoc.class, new BigInteger JavaDoc("5")));
185         assertEquals(Double.valueOf("6"), DefaultTypeConverter.INSTANCE.convert(Double JavaDoc.class, new BigInteger JavaDoc("6")));
186         assertEquals(new BigInteger JavaDoc("7"), DefaultTypeConverter.INSTANCE.convert(BigInteger JavaDoc.class, new BigInteger JavaDoc("7")));
187         assertEquals(new BigDecimal JavaDoc("8"), DefaultTypeConverter.INSTANCE.convert(BigDecimal JavaDoc.class, new BigInteger JavaDoc("8")));
188         
189         assertEquals(Byte.valueOf("1"), DefaultTypeConverter.INSTANCE.convert(Byte JavaDoc.class, new BigDecimal JavaDoc("1")));
190         assertEquals(Short.valueOf("2"), DefaultTypeConverter.INSTANCE.convert(Short JavaDoc.class, new BigDecimal JavaDoc("2")));
191         assertEquals(Integer.valueOf("3"), DefaultTypeConverter.INSTANCE.convert(Integer JavaDoc.class, new BigDecimal JavaDoc("3")));
192         assertEquals(Long.valueOf("4"), DefaultTypeConverter.INSTANCE.convert(Long JavaDoc.class, new BigDecimal JavaDoc("4")));
193         assertEquals(Float.valueOf("5"), DefaultTypeConverter.INSTANCE.convert(Float JavaDoc.class, new BigDecimal JavaDoc("5")));
194         assertEquals(Double.valueOf("6"), DefaultTypeConverter.INSTANCE.convert(Double JavaDoc.class, new BigDecimal JavaDoc("6")));
195         assertEquals(new BigInteger JavaDoc("7"), DefaultTypeConverter.INSTANCE.convert(BigInteger JavaDoc.class, new BigDecimal JavaDoc("7")));
196         assertEquals(new BigDecimal JavaDoc("8"), DefaultTypeConverter.INSTANCE.convert(BigDecimal JavaDoc.class, new BigDecimal JavaDoc("8")));
197     }
198     
199     public void testDate()
200     {
201         Date JavaDoc date = new Date JavaDoc(101);
202         
203         assertEquals(Byte.valueOf("101"), DefaultTypeConverter.INSTANCE.convert(Byte JavaDoc.class, date));
204         assertEquals(Short.valueOf("101"), DefaultTypeConverter.INSTANCE.convert(Short JavaDoc.class, date));
205         assertEquals(Integer.valueOf("101"), DefaultTypeConverter.INSTANCE.convert(Integer JavaDoc.class, date));
206         assertEquals(Long.valueOf("101"), DefaultTypeConverter.INSTANCE.convert(Long JavaDoc.class, date));
207         assertEquals(Float.valueOf("101"), DefaultTypeConverter.INSTANCE.convert(Float JavaDoc.class, date));
208         assertEquals(Double.valueOf("101"), DefaultTypeConverter.INSTANCE.convert(Double JavaDoc.class, date));
209         assertEquals(new BigInteger JavaDoc("101"), DefaultTypeConverter.INSTANCE.convert(BigInteger JavaDoc.class, date));
210         assertEquals(new BigDecimal JavaDoc("101"), DefaultTypeConverter.INSTANCE.convert(BigDecimal JavaDoc.class, date));
211         
212         assertEquals(date, DefaultTypeConverter.INSTANCE.convert(Date JavaDoc.class, (byte)101));
213         assertEquals(date, DefaultTypeConverter.INSTANCE.convert(Date JavaDoc.class, (short)101));
214         assertEquals(date, DefaultTypeConverter.INSTANCE.convert(Date JavaDoc.class, (int)101));
215         assertEquals(date, DefaultTypeConverter.INSTANCE.convert(Date JavaDoc.class, (long)101));
216         assertEquals(date, DefaultTypeConverter.INSTANCE.convert(Date JavaDoc.class, (float)101));
217         assertEquals(date, DefaultTypeConverter.INSTANCE.convert(Date JavaDoc.class, (double)101));
218         
219         assertEquals(date, DefaultTypeConverter.INSTANCE.convert(Date JavaDoc.class, new BigInteger JavaDoc("101")));
220         assertEquals(date, DefaultTypeConverter.INSTANCE.convert(Date JavaDoc.class, (Object JavaDoc)(new BigDecimal JavaDoc("101"))));
221         
222         assertEquals(101, DefaultTypeConverter.INSTANCE.intValue(date));
223     }
224     
225     public void testMultiValue()
226     {
227         ArrayList JavaDoc<Object JavaDoc> list = makeList();
228         
229         assertEquals(true, DefaultTypeConverter.INSTANCE.isMultiValued(list));
230         assertEquals(14, DefaultTypeConverter.INSTANCE.size(list));
231         
232         for(String JavaDoc stringValue: DefaultTypeConverter.INSTANCE.getCollection(String JavaDoc.class, list))
233         {
234             System.out.println("Value is "+stringValue);
235         }
236         
237     }
238
239     private ArrayList JavaDoc<Object JavaDoc> makeList()
240     {
241         ArrayList JavaDoc<Object JavaDoc> list = new ArrayList JavaDoc<Object JavaDoc>();
242         list.add(Boolean.valueOf(true));
243         list.add(Boolean.valueOf(false));
244         list.add(Character.valueOf('q'));
245         list.add(Byte.valueOf("1"));
246         list.add(Short.valueOf("2"));
247         list.add(Integer.valueOf("3"));
248         list.add(Long.valueOf("4"));
249         list.add(Float.valueOf("5"));
250         list.add(Double.valueOf("6"));
251         list.add(new BigInteger JavaDoc("7"));
252         list.add(new BigDecimal JavaDoc("8"));
253         list.add(new Date JavaDoc());
254         list.add(new Duration("P5Y0M"));
255         list.add("Hello mum");
256         return list;
257     }
258     
259     public void testSingleValuseAsMultiValue()
260     {
261         Integer JavaDoc integer = Integer.valueOf(43);
262         
263         assertEquals(false, DefaultTypeConverter.INSTANCE.isMultiValued(integer));
264         assertEquals(1, DefaultTypeConverter.INSTANCE.size(integer));
265         
266         for(String JavaDoc stringValue: DefaultTypeConverter.INSTANCE.getCollection(String JavaDoc.class, integer))
267         {
268             System.out.println("Value is "+stringValue);
269         }
270         
271     }
272     
273     public void testNullAndEmpty()
274     {
275         assertNull(DefaultTypeConverter.INSTANCE.convert(Boolean JavaDoc.class, null));
276         ArrayList JavaDoc<Object JavaDoc> list = new ArrayList JavaDoc<Object JavaDoc>();
277         assertNotNull(DefaultTypeConverter.INSTANCE.convert(Boolean JavaDoc.class, list));
278         list.add(null);
279         assertNotNull(DefaultTypeConverter.INSTANCE.convert(Boolean JavaDoc.class, list));
280         
281     }
282 }
283
Popular Tags