001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package org.apache.commons.configuration;
019    
020    import static org.junit.Assert.assertEquals;
021    import static org.junit.Assert.assertFalse;
022    import static org.junit.Assert.assertNotNull;
023    import static org.junit.Assert.assertNull;
024    import static org.junit.Assert.assertTrue;
025    import static org.junit.Assert.fail;
026    
027    import java.awt.Color;
028    import java.math.BigDecimal;
029    import java.math.BigInteger;
030    import java.net.InetAddress;
031    import java.net.URL;
032    import java.text.DateFormat;
033    import java.text.SimpleDateFormat;
034    import java.util.ArrayList;
035    import java.util.Calendar;
036    import java.util.Date;
037    import java.util.Iterator;
038    import java.util.List;
039    import java.util.Locale;
040    import java.util.NoSuchElementException;
041    
042    import junitx.framework.ArrayAssert;
043    import junitx.framework.ListAssert;
044    
045    import org.junit.Before;
046    import org.junit.Test;
047    
048    /**
049     * @author Emmanuel Bourg
050     * @version $Id: TestDataConfiguration.java 1301990 2012-03-17 20:10:46Z oheger $
051     */
052    public class TestDataConfiguration
053    {
054        private DataConfiguration conf;
055    
056        @Before
057        public void setUp() throws Exception
058        {
059            conf = new DataConfiguration(new BaseConfiguration());
060    
061            // empty value
062            conf.addProperty("empty", "");
063    
064            // lists of boolean
065            conf.addProperty("boolean.list1", "true");
066            conf.addProperty("boolean.list1", "false");
067            conf.addProperty("boolean.list2", "true, false");
068            conf.addProperty("boolean.list3", Boolean.TRUE);
069            conf.addProperty("boolean.list3", Boolean.FALSE);
070            conf.addPropertyDirect("boolean.list4", new Boolean[] { Boolean.TRUE, Boolean.FALSE });
071            conf.addPropertyDirect("boolean.list5", new boolean[] { true, false });
072            List<Object> booleans = new ArrayList<Object>();
073            booleans.add(Boolean.TRUE);
074            booleans.add(Boolean.FALSE);
075            conf.addProperty("boolean.list6", booleans);
076            conf.addProperty("boolean.string", "true");
077            conf.addProperty("boolean.object", Boolean.TRUE);
078            conf.addProperty("boolean.list.interpolated", "${boolean.string},false");
079    
080            // lists of bytes
081            conf.addProperty("byte.list1", "1");
082            conf.addProperty("byte.list1", "2");
083            conf.addProperty("byte.list2", "1, 2");
084            conf.addProperty("byte.list3", new Byte("1"));
085            conf.addProperty("byte.list3", new Byte("2"));
086            conf.addPropertyDirect("byte.list4", new Byte[] { new Byte("1"), new Byte("2") });
087            conf.addPropertyDirect("byte.list5", new byte[] { 1, 2 });
088            List<Object> bytes = new ArrayList<Object>();
089            bytes.add(new Byte("1"));
090            bytes.add(new Byte("2"));
091            conf.addProperty("byte.list6", bytes);
092            conf.addProperty("byte.string", "1");
093            conf.addProperty("byte.object", new Byte("1"));
094            conf.addProperty("byte.list.interpolated", "${byte.string},2");
095    
096            // lists of shorts
097            conf.addProperty("short.list1", "1");
098            conf.addProperty("short.list1", "2");
099            conf.addProperty("short.list2", "1, 2");
100            conf.addProperty("short.list3", new Short("1"));
101            conf.addProperty("short.list3", new Short("2"));
102            conf.addPropertyDirect("short.list4", new Short[] { new Short("1"), new Short("2") });
103            conf.addPropertyDirect("short.list5", new short[] { 1, 2 });
104            List<Object> shorts = new ArrayList<Object>();
105            shorts.add(new Short("1"));
106            shorts.add(new Short("2"));
107            conf.addProperty("short.list6", shorts);
108            conf.addProperty("short.string", "1");
109            conf.addProperty("short.object", new Short("1"));
110            conf.addProperty("short.list.interpolated", "${short.string},2");
111    
112            // lists of integers
113            conf.addProperty("integer.list1", "1");
114            conf.addProperty("integer.list1", "2");
115            conf.addProperty("integer.list2", "1, 2");
116            conf.addProperty("integer.list3", new Integer("1"));
117            conf.addProperty("integer.list3", new Integer("2"));
118            conf.addPropertyDirect("integer.list4", new Integer[] { new Integer("1"), new Integer("2") });
119            conf.addPropertyDirect("integer.list5", new int[] { 1, 2 });
120            List<Object> integers = new ArrayList<Object>();
121            integers.add(new Integer("1"));
122            integers.add(new Integer("2"));
123            conf.addProperty("integer.list6", integers);
124            conf.addProperty("integer.string", "1");
125            conf.addProperty("integer.object", new Integer("1"));
126            conf.addProperty("integer.list.interpolated", "${integer.string},2");
127    
128            // lists of longs
129            conf.addProperty("long.list1", "1");
130            conf.addProperty("long.list1", "2");
131            conf.addProperty("long.list2", "1, 2");
132            conf.addProperty("long.list3", new Long("1"));
133            conf.addProperty("long.list3", new Long("2"));
134            conf.addPropertyDirect("long.list4", new Long[] { new Long("1"), new Long("2") });
135            conf.addPropertyDirect("long.list5", new long[] { 1, 2 });
136            List<Object> longs = new ArrayList<Object>();
137            longs.add(new Long("1"));
138            longs.add(new Long("2"));
139            conf.addProperty("long.list6", longs);
140            conf.addProperty("long.string", "1");
141            conf.addProperty("long.object", new Long("1"));
142            conf.addProperty("long.list.interpolated", "${long.string},2");
143    
144            // lists of floats
145            conf.addProperty("float.list1", "1");
146            conf.addProperty("float.list1", "2");
147            conf.addProperty("float.list2", "1, 2");
148            conf.addProperty("float.list3", new Float("1"));
149            conf.addProperty("float.list3", new Float("2"));
150            conf.addPropertyDirect("float.list4", new Float[] { new Float("1"), new Float("2") });
151            conf.addPropertyDirect("float.list5", new float[] { 1, 2 });
152            List<Object> floats = new ArrayList<Object>();
153            floats.add(new Float("1"));
154            floats.add(new Float("2"));
155            conf.addProperty("float.list6", floats);
156            conf.addProperty("float.string", "1");
157            conf.addProperty("float.object", new Float("1"));
158            conf.addProperty("float.list.interpolated", "${float.string},2");
159    
160            // lists of doubles
161            conf.addProperty("double.list1", "1");
162            conf.addProperty("double.list1", "2");
163            conf.addProperty("double.list2", "1, 2");
164            conf.addProperty("double.list3", new Double("1"));
165            conf.addProperty("double.list3", new Double("2"));
166            conf.addPropertyDirect("double.list4", new Double[] { new Double("1"), new Double("2") });
167            conf.addPropertyDirect("double.list5", new double[] { 1, 2 });
168            List<Object> doubles = new ArrayList<Object>();
169            doubles.add(new Double("1"));
170            doubles.add(new Double("2"));
171            conf.addProperty("double.list6", doubles);
172            conf.addProperty("double.string", "1");
173            conf.addProperty("double.object", new Double("1"));
174            conf.addProperty("double.list.interpolated", "${double.string},2");
175    
176            // lists of big integers
177            conf.addProperty("biginteger.list1", "1");
178            conf.addProperty("biginteger.list1", "2");
179            conf.addProperty("biginteger.list2", "1, 2");
180            conf.addProperty("biginteger.list3", new BigInteger("1"));
181            conf.addProperty("biginteger.list3", new BigInteger("2"));
182            conf.addPropertyDirect("biginteger.list4", new BigInteger[] { new BigInteger("1"), new BigInteger("2") });
183            List<Object> bigintegers = new ArrayList<Object>();
184            bigintegers.add(new BigInteger("1"));
185            bigintegers.add(new BigInteger("2"));
186            conf.addProperty("biginteger.list6", bigintegers);
187            conf.addProperty("biginteger.string", "1");
188            conf.addProperty("biginteger.object", new BigInteger("1"));
189            conf.addProperty("biginteger.list.interpolated", "${biginteger.string},2");
190    
191            // lists of big decimals
192            conf.addProperty("bigdecimal.list1", "1");
193            conf.addProperty("bigdecimal.list1", "2");
194            conf.addProperty("bigdecimal.list2", "1, 2");
195            conf.addProperty("bigdecimal.list3", new BigDecimal("1"));
196            conf.addProperty("bigdecimal.list3", new BigDecimal("2"));
197            conf.addPropertyDirect("bigdecimal.list4", new BigDecimal[] { new BigDecimal("1"), new BigDecimal("2") });
198            List<Object> bigdecimals = new ArrayList<Object>();
199            bigdecimals.add(new BigDecimal("1"));
200            bigdecimals.add(new BigDecimal("2"));
201            conf.addProperty("bigdecimal.list6", bigdecimals);
202            conf.addProperty("bigdecimal.string", "1");
203            conf.addProperty("bigdecimal.object", new BigDecimal("1"));
204            conf.addProperty("bigdecimal.list.interpolated", "${bigdecimal.string},2");
205    
206            // URLs
207            String url1 = "http://jakarta.apache.org";
208            String url2 = "http://www.apache.org";
209            conf.addProperty("url.string", url1);
210            conf.addProperty("url.string.interpolated", "${url.string}");
211            conf.addProperty("url.object", new URL(url1));
212            conf.addProperty("url.list1", url1);
213            conf.addProperty("url.list1", url2);
214            conf.addProperty("url.list2", url1 + ", " + url2);
215            conf.addProperty("url.list3", new URL(url1));
216            conf.addProperty("url.list3", new URL(url2));
217            conf.addPropertyDirect("url.list4", new URL[] { new URL(url1), new URL(url2) });
218            List<Object> urls = new ArrayList<Object>();
219            urls.add(new URL(url1));
220            urls.add(new URL(url2));
221            conf.addProperty("url.list6", urls);
222            conf.addProperty("url.list.interpolated", "${url.string}," + url2);
223    
224            // Locales
225            conf.addProperty("locale.string", "fr");
226            conf.addProperty("locale.string.interpolated", "${locale.string}");
227            conf.addProperty("locale.object", Locale.FRENCH);
228            conf.addProperty("locale.list1", "fr");
229            conf.addProperty("locale.list1", "de");
230            conf.addProperty("locale.list2", "fr, de");
231            conf.addProperty("locale.list3", Locale.FRENCH);
232            conf.addProperty("locale.list3", Locale.GERMAN);
233            conf.addPropertyDirect("locale.list4", new Locale[] { Locale.FRENCH, Locale.GERMAN });
234            List<Object> locales = new ArrayList<Object>();
235            locales.add(Locale.FRENCH);
236            locales.add(Locale.GERMAN);
237            conf.addProperty("locale.list6", locales);
238            conf.addProperty("locale.list.interpolated", "${locale.string},de");
239    
240            // Colors
241            String color1 = "FF0000";
242            String color2 = "0000FF";
243            conf.addProperty("color.string", color1);
244            conf.addProperty("color.string.interpolated", "${color.string}");
245            conf.addProperty("color.object", Color.red);
246            conf.addProperty("color.list1", color1);
247            conf.addProperty("color.list1", color2);
248            conf.addProperty("color.list2", color1 + ", " + color2);
249            conf.addProperty("color.list3", Color.red);
250            conf.addProperty("color.list3", Color.blue);
251            conf.addPropertyDirect("color.list4", new Color[] { Color.red, Color.blue });
252            List<Object> colors = new ArrayList<Object>();
253            colors.add(Color.red);
254            colors.add(Color.blue);
255            conf.addProperty("color.list6", colors);
256            conf.addProperty("color.list.interpolated", "${color.string}," + color2);
257    
258            // Dates & Calendars
259            String pattern = "yyyy-MM-dd";
260            DateFormat format = new SimpleDateFormat(pattern);
261            conf.setProperty(DataConfiguration.DATE_FORMAT_KEY, pattern);
262    
263            Date date1 = format.parse("2004-01-01");
264            Date date2 = format.parse("2004-12-31");
265            Calendar calendar1 = Calendar.getInstance();
266            calendar1.setTime(date1);
267            Calendar calendar2 = Calendar.getInstance();
268            calendar2.setTime(date2);
269    
270            conf.addProperty("date.string", "2004-01-01");
271            conf.addProperty("date.string.interpolated", "${date.string}");
272            conf.addProperty("date.object", date1);
273            conf.addProperty("date.list1", "2004-01-01");
274            conf.addProperty("date.list1", "2004-12-31");
275            conf.addProperty("date.list2", "2004-01-01, 2004-12-31");
276            conf.addProperty("date.list3", date1);
277            conf.addProperty("date.list3", date2);
278            conf.addPropertyDirect("date.list4", new Date[] { date1, date2 });
279            conf.addPropertyDirect("date.list5", new Calendar[] { calendar1, calendar2 });
280            List<Object> dates = new ArrayList<Object>();
281            dates.add(date1);
282            dates.add(date2);
283            conf.addProperty("date.list6", dates);
284            conf.addProperty("date.list.interpolated", "${date.string},2004-12-31");
285            conf.addPropertyDirect("date.list7", new String[] { "2004-01-01", "2004-12-31" });
286    
287            conf.addProperty("calendar.string", "2004-01-01");
288            conf.addProperty("calendar.string.interpolated", "${calendar.string}");
289            conf.addProperty("calendar.object", calendar1);
290            conf.addProperty("calendar.list1", "2004-01-01");
291            conf.addProperty("calendar.list1", "2004-12-31");
292            conf.addProperty("calendar.list2", "2004-01-01, 2004-12-31");
293            conf.addProperty("calendar.list3", calendar1);
294            conf.addProperty("calendar.list3", calendar2);
295            conf.addPropertyDirect("calendar.list4", new Calendar[] { calendar1, calendar2 });
296            conf.addPropertyDirect("calendar.list5", new Date[] { date1, date2 });
297            List<Object> calendars = new ArrayList<Object>();
298            calendars.add(date1);
299            calendars.add(date2);
300            conf.addProperty("calendar.list6", calendars);
301            conf.addProperty("calendar.list.interpolated", "${calendar.string},2004-12-31");
302            conf.addPropertyDirect("calendar.list7", new String[] { "2004-01-01", "2004-12-31" });
303    
304            // host address
305            conf.addProperty("ip.string", "127.0.0.1");
306            conf.addProperty("ip.string.interpolated", "${ip.string}");
307            conf.addProperty("ip.object", InetAddress.getByName("127.0.0.1"));
308    
309            // email address
310            conf.addProperty("email.string", "ebourg@apache.org");
311            conf.addProperty("email.string.interpolated", "${email.string}");
312            conf.addProperty("email.object", createInternetAddress("ebourg@apache.org"));
313        }
314    
315        @Test
316        public void testGetConfiguration()
317        {
318            Configuration baseconf = new BaseConfiguration();
319            DataConfiguration conf = new DataConfiguration(baseconf);
320    
321            assertEquals("base configuration", baseconf, conf.getConfiguration());
322        }
323    
324        @Test
325        public void testIsEmpty()
326        {
327            Configuration baseconf = new BaseConfiguration();
328            DataConfiguration conf = new DataConfiguration(baseconf);
329    
330            assertTrue("not empty", conf.isEmpty());
331    
332            baseconf.setProperty("foo", "bar");
333    
334            assertFalse("empty", conf.isEmpty());
335        }
336    
337        @Test
338        public void testContainsKey()
339        {
340            Configuration baseconf = new BaseConfiguration();
341            DataConfiguration conf = new DataConfiguration(baseconf);
342    
343            assertFalse(conf.containsKey("foo"));
344    
345            baseconf.setProperty("foo", "bar");
346    
347            assertTrue(conf.containsKey("foo"));
348        }
349    
350        @Test
351        public void testGetKeys()
352        {
353            Configuration baseconf = new BaseConfiguration();
354            DataConfiguration conf = new DataConfiguration(baseconf);
355    
356            baseconf.setProperty("foo", "bar");
357    
358            Iterator<String> it = conf.getKeys();
359            assertTrue("the iterator is empty", it.hasNext());
360            assertEquals("unique key", "foo", it.next());
361            assertFalse("the iterator is not exhausted", it.hasNext());
362        }
363    
364        @Test(expected = ConversionException.class)
365        public void testGetInvalidType()
366        {
367            conf.get(Boolean.class, "url.object", null);
368        }
369    
370        @Test
371        public void testGetUnknown()
372        {
373            assertNull("non null object for a missing key", conf.get(Object.class, "unknownkey"));
374        }
375    
376        @Test(expected = NoSuchElementException.class)
377        public void testGetUnknownException()
378        {
379            conf.setThrowExceptionOnMissing(true);
380            conf.get(Object.class, "unknownkey");
381        }
382    
383        @Test(expected = IllegalArgumentException.class)
384        public void testGetArrayInvalidDefaultType()
385        {
386            conf.getArray(Boolean.class, "unknownkey", new URL[] {});
387        }
388    
389        @Test(expected = ConversionException.class)
390        public void testGetPrimitiveArrayInvalidType()
391        {
392            conf.getArray(Boolean.TYPE, "calendar.list4");
393        }
394    
395        @Test
396        public void testGetBooleanArray()
397        {
398            // missing list
399            boolean[] defaultValue = new boolean[] { false, true };
400            ArrayAssert.assertEquals(defaultValue, conf.getBooleanArray("boolean.list", defaultValue));
401    
402            boolean[] expected = new boolean[] { true, false };
403    
404            // list of strings
405            ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list1"));
406    
407            // list of strings, comma separated
408            ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list2"));
409    
410            // list of Boolean objects
411            ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list3"));
412    
413            // array of Boolean objects
414            ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list4"));
415    
416            // array of boolean primitives
417            ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list5"));
418    
419            // list of Boolean objects
420            ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list6"));
421    
422            // list of interpolated values
423            ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list.interpolated"));
424    
425            // single boolean values
426            ArrayAssert.assertEquals(new boolean[] { true }, conf.getBooleanArray("boolean.string"));
427            ArrayAssert.assertEquals(new boolean[] { true }, conf.getBooleanArray("boolean.object"));
428    
429            // empty array
430            ArrayAssert.assertEquals(new boolean[] { }, conf.getBooleanArray("empty"));
431        }
432    
433        @Test
434        public void testGetBooleanList()
435        {
436            // missing list
437            ListAssert.assertEquals(null, conf.getBooleanList("boolean.list", null));
438    
439            List<Object> expected = new ArrayList<Object>();
440            expected.add(Boolean.TRUE);
441            expected.add(Boolean.FALSE);
442    
443            // list of strings
444            ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list1"));
445    
446            // list of strings, comma separated
447            ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list2"));
448    
449            // list of Boolean objects
450            ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list3"));
451    
452            // array of Boolean objects
453            ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list4"));
454    
455            // array of boolean primitives
456            ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list5"));
457    
458            // list of Boolean objects
459            ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list6"));
460    
461            // list of interpolated values
462            ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list.interpolated"));
463    
464            // single boolean values
465            expected = new ArrayList<Object>();
466            expected.add(Boolean.TRUE);
467            ListAssert.assertEquals(expected, conf.getBooleanList("boolean.string"));
468            ListAssert.assertEquals(expected, conf.getBooleanList("boolean.object"));
469    
470            // empty list
471            ListAssert.assertEquals(new ArrayList<Object>(), conf.getBooleanList("empty"));
472        }
473    
474        @Test
475        public void testGetByteArray()
476        {
477            // missing list
478            byte[] defaultValue = new byte[] { 1, 2};
479            ArrayAssert.assertEquals(defaultValue, conf.getByteArray("byte.list", defaultValue));
480    
481            byte[] expected = new byte[] { 1, 2 };
482    
483            // list of strings
484            ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list1"));
485    
486            // list of strings, comma separated
487            ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list2"));
488    
489            // list of Byte objects
490            ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list3"));
491    
492            // array of Byte objects
493            ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list4"));
494    
495            // array of byte primitives
496            ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list5"));
497    
498            // list of Byte objects
499            ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list6"));
500    
501            // list of interpolated values
502            ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list.interpolated"));
503    
504            // single byte values
505            ArrayAssert.assertEquals(new byte[] { 1 }, conf.getByteArray("byte.string"));
506            ArrayAssert.assertEquals(new byte[] { 1 }, conf.getByteArray("byte.object"));
507    
508            // empty array
509            ArrayAssert.assertEquals(new byte[] { }, conf.getByteArray("empty"));
510        }
511    
512        @Test
513        public void testGetByteList()
514        {
515            // missing list
516            ListAssert.assertEquals(null, conf.getByteList("byte.list", null));
517    
518            List<Object> expected = new ArrayList<Object>();
519            expected.add(new Byte("1"));
520            expected.add(new Byte("2"));
521    
522            // list of strings
523            ListAssert.assertEquals(expected, conf.getByteList("byte.list1"));
524    
525            // list of strings, comma separated
526            ListAssert.assertEquals(expected, conf.getByteList("byte.list2"));
527    
528            // list of Byte objects
529            ListAssert.assertEquals(expected, conf.getByteList("byte.list3"));
530    
531            // array of Byte objects
532            ListAssert.assertEquals(expected, conf.getByteList("byte.list4"));
533    
534            // array of byte primitives
535            ListAssert.assertEquals(expected, conf.getByteList("byte.list5"));
536    
537            // list of Byte objects
538            ListAssert.assertEquals(expected, conf.getByteList("byte.list6"));
539    
540            // list of interpolated values
541            ListAssert.assertEquals(expected, conf.getByteList("byte.list.interpolated"));
542    
543            // single byte values
544            expected = new ArrayList<Object>();
545            expected.add(new Byte("1"));
546            ListAssert.assertEquals(expected, conf.getByteList("byte.string"));
547            ListAssert.assertEquals(expected, conf.getByteList("byte.object"));
548    
549            // empty list
550            ListAssert.assertEquals(new ArrayList<Object>(), conf.getByteList("empty"));
551        }
552    
553        @Test
554        public void testGetShortArray()
555        {
556            // missing list
557            short[] defaultValue = new short[] { 2, 1};
558            ArrayAssert.assertEquals(defaultValue, conf.getShortArray("short.list", defaultValue));
559    
560            short[] expected = new short[] { 1, 2 };
561    
562            // list of strings
563            ArrayAssert.assertEquals(expected, conf.getShortArray("short.list1"));
564    
565            // list of strings, comma separated
566            ArrayAssert.assertEquals(expected, conf.getShortArray("short.list2"));
567    
568            // list of Byte objects
569            ArrayAssert.assertEquals(expected, conf.getShortArray("short.list3"));
570    
571            // array of Byte objects
572            ArrayAssert.assertEquals(expected, conf.getShortArray("short.list4"));
573    
574            // array of byte primitives
575            ArrayAssert.assertEquals(expected, conf.getShortArray("short.list5"));
576    
577            // list of Byte objects
578            ArrayAssert.assertEquals(expected, conf.getShortArray("short.list6"));
579    
580            // list of interpolated values
581            ArrayAssert.assertEquals(expected, conf.getShortArray("short.list.interpolated"));
582    
583            // single byte values
584            ArrayAssert.assertEquals(new short[] { 1 }, conf.getShortArray("short.string"));
585            ArrayAssert.assertEquals(new short[] { 1 }, conf.getShortArray("short.object"));
586    
587            // empty array
588            ArrayAssert.assertEquals(new short[] { }, conf.getShortArray("empty"));
589        }
590    
591        @Test
592        public void testGetShortList()
593        {
594            // missing list
595            ListAssert.assertEquals(null, conf.getShortList("short.list", null));
596    
597            List<Object> expected = new ArrayList<Object>();
598            expected.add(new Short("1"));
599            expected.add(new Short("2"));
600    
601            // list of strings
602            ListAssert.assertEquals(expected, conf.getShortList("short.list1"));
603    
604            // list of strings, comma separated
605            ListAssert.assertEquals(expected, conf.getShortList("short.list2"));
606    
607            // list of Short objects
608            ListAssert.assertEquals(expected, conf.getShortList("short.list3"));
609    
610            // array of Short objects
611            ListAssert.assertEquals(expected, conf.getShortList("short.list4"));
612    
613            // array of short primitives
614            ListAssert.assertEquals(expected, conf.getShortList("short.list5"));
615    
616            // list of Short objects
617            ListAssert.assertEquals(expected, conf.getShortList("short.list6"));
618    
619            // list of interpolated values
620            ListAssert.assertEquals(expected, conf.getShortList("short.list.interpolated"));
621    
622            // single short values
623            expected = new ArrayList<Object>();
624            expected.add(new Short("1"));
625            ListAssert.assertEquals(expected, conf.getShortList("short.string"));
626            ListAssert.assertEquals(expected, conf.getShortList("short.object"));
627    
628            // empty list
629            ListAssert.assertEquals(new ArrayList<Object>(), conf.getShortList("empty"));
630        }
631    
632        @Test
633        public void testGetIntegerArray()
634        {
635            // missing list
636            int[] defaultValue = new int[] { 2, 1};
637            ArrayAssert.assertEquals(defaultValue, conf.getIntArray("integer.list", defaultValue));
638    
639            int[] expected = new int[] { 1, 2 };
640    
641            // list of strings
642            ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list1"));
643    
644            // list of strings, comma separated
645            ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list2"));
646    
647            // list of Integer objects
648            ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list3"));
649    
650            // array of Integer objects
651            ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list4"));
652    
653            // array of int primitives
654            ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list5"));
655    
656            // list of Integer objects
657            ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list6"));
658    
659            // list of interpolated values
660            ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list.interpolated"));
661    
662            // single int values
663            ArrayAssert.assertEquals(new int[] { 1 }, conf.getIntArray("integer.string"));
664            ArrayAssert.assertEquals(new int[] { 1 }, conf.getIntArray("integer.object"));
665    
666            // empty array
667            ArrayAssert.assertEquals(new int[] { }, conf.getIntArray("empty"));
668        }
669    
670        @Test
671        public void testGetIntegerList()
672        {
673            // missing list
674            ListAssert.assertEquals(null, conf.getIntegerList("integer.list", null));
675    
676            List<Object> expected = new ArrayList<Object>();
677            expected.add(new Integer("1"));
678            expected.add(new Integer("2"));
679    
680            // list of strings
681            ListAssert.assertEquals(expected, conf.getIntegerList("integer.list1"));
682    
683            // list of strings, comma separated
684            ListAssert.assertEquals(expected, conf.getIntegerList("integer.list2"));
685    
686            // list of Integer objects
687            ListAssert.assertEquals(expected, conf.getIntegerList("integer.list3"));
688    
689            // array of Integer objects
690            ListAssert.assertEquals(expected, conf.getIntegerList("integer.list4"));
691    
692            // array of int primitives
693            ListAssert.assertEquals(expected, conf.getIntegerList("integer.list5"));
694    
695            // list of Integer objects
696            ListAssert.assertEquals(expected, conf.getIntegerList("integer.list6"));
697    
698            // list of interpolated values
699            ListAssert.assertEquals(expected, conf.getIntegerList("integer.list.interpolated"));
700    
701            // single int values
702            expected = new ArrayList<Object>();
703            expected.add(new Integer("1"));
704            ListAssert.assertEquals(expected, conf.getIntegerList("integer.string"));
705            ListAssert.assertEquals(expected, conf.getIntegerList("integer.object"));
706    
707            // empty list
708            ListAssert.assertEquals(new ArrayList<Object>(), conf.getIntegerList("empty"));
709        }
710    
711        @Test
712        public void testGetLongArray()
713        {
714            // missing list
715            long[] defaultValue = new long[] { 2, 1};
716            ArrayAssert.assertEquals(defaultValue, conf.getLongArray("long.list", defaultValue));
717    
718            long[] expected = new long[] { 1, 2 };
719    
720            // list of strings
721            ArrayAssert.assertEquals(expected, conf.getLongArray("long.list1"));
722    
723            // list of strings, comma separated
724            ArrayAssert.assertEquals(expected, conf.getLongArray("long.list2"));
725    
726            // list of Long objects
727            ArrayAssert.assertEquals(expected, conf.getLongArray("long.list3"));
728    
729            // array of Long objects
730            ArrayAssert.assertEquals(expected, conf.getLongArray("long.list4"));
731    
732            // array of long primitives
733            ArrayAssert.assertEquals(expected, conf.getLongArray("long.list5"));
734    
735            // list of Long objects
736            ArrayAssert.assertEquals(expected, conf.getLongArray("long.list6"));
737    
738            // list of interpolated values
739            ArrayAssert.assertEquals(expected, conf.getLongArray("long.list.interpolated"));
740    
741            // single long values
742            ArrayAssert.assertEquals(new long[] { 1 }, conf.getLongArray("long.string"));
743            ArrayAssert.assertEquals(new long[] { 1 }, conf.getLongArray("long.object"));
744    
745            // empty array
746            ArrayAssert.assertEquals(new long[] { }, conf.getLongArray("empty"));
747        }
748    
749        @Test
750        public void testGetLongList()
751        {
752            // missing list
753            ListAssert.assertEquals(null, conf.getLongList("long.list", null));
754    
755            List<Object> expected = new ArrayList<Object>();
756            expected.add(new Long("1"));
757            expected.add(new Long("2"));
758    
759            // list of strings
760            ListAssert.assertEquals(expected, conf.getLongList("long.list1"));
761    
762            // list of strings, comma separated
763            ListAssert.assertEquals(expected, conf.getLongList("long.list2"));
764    
765            // list of Long objects
766            ListAssert.assertEquals(expected, conf.getLongList("long.list3"));
767    
768            // array of Long objects
769            ListAssert.assertEquals(expected, conf.getLongList("long.list4"));
770    
771            // array of long primitives
772            ListAssert.assertEquals(expected, conf.getLongList("long.list5"));
773    
774            // list of Long objects
775            ListAssert.assertEquals(expected, conf.getLongList("long.list6"));
776    
777            // list of interpolated values
778            ListAssert.assertEquals(expected, conf.getLongList("long.list.interpolated"));
779    
780            // single long values
781            expected = new ArrayList<Object>();
782            expected.add(new Long("1"));
783            ListAssert.assertEquals(expected, conf.getLongList("long.string"));
784            ListAssert.assertEquals(expected, conf.getLongList("long.object"));
785    
786            // empty list
787            ListAssert.assertEquals(new ArrayList<Object>(), conf.getLongList("empty"));
788        }
789    
790        @Test
791        public void testGetFloatArray()
792        {
793            // missing list
794            float[] defaultValue = new float[] { 2, 1};
795            ArrayAssert.assertEquals(defaultValue, conf.getFloatArray("float.list", defaultValue), 0);
796    
797            float[] expected = new float[] { 1, 2 };
798    
799            // list of strings
800            ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list1"), 0);
801    
802            // list of strings, comma separated
803            ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list2"), 0);
804    
805            // list of Float objects
806            ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list3"), 0);
807    
808            // array of Float objects
809            ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list4"), 0);
810    
811            // array of float primitives
812            ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list5"), 0);
813    
814            // list of Float objects
815            ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list6"), 0);
816    
817            // list of interpolated values
818            ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list.interpolated"), 0);
819    
820            // single float values
821            ArrayAssert.assertEquals(new float[] { 1 }, conf.getFloatArray("float.string"), 0);
822            ArrayAssert.assertEquals(new float[] { 1 }, conf.getFloatArray("float.object"), 0);
823    
824            // empty array
825            ArrayAssert.assertEquals(new float[] { }, conf.getFloatArray("empty"), 0);
826        }
827    
828        @Test
829        public void testGetFloatList()
830        {
831            // missing list
832            ListAssert.assertEquals(null, conf.getFloatList("float.list", null));
833    
834            List<Object> expected = new ArrayList<Object>();
835            expected.add(new Float("1"));
836            expected.add(new Float("2"));
837    
838            // list of strings
839            ListAssert.assertEquals(expected, conf.getFloatList("float.list1"));
840    
841            // list of strings, comma separated
842            ListAssert.assertEquals(expected, conf.getFloatList("float.list2"));
843    
844            // list of Float objects
845            ListAssert.assertEquals(expected, conf.getFloatList("float.list3"));
846    
847            // array of Float objects
848            ListAssert.assertEquals(expected, conf.getFloatList("float.list4"));
849    
850            // array of float primitives
851            ListAssert.assertEquals(expected, conf.getFloatList("float.list5"));
852    
853            // list of Float objects
854            ListAssert.assertEquals(expected, conf.getFloatList("float.list6"));
855    
856            // list of interpolated values
857            ListAssert.assertEquals(expected, conf.getFloatList("float.list.interpolated"));
858    
859            // single float values
860            expected = new ArrayList<Object>();
861            expected.add(new Float("1"));
862            ListAssert.assertEquals(expected, conf.getFloatList("float.string"));
863            ListAssert.assertEquals(expected, conf.getFloatList("float.object"));
864    
865            // empty list
866            ListAssert.assertEquals(new ArrayList<Object>(), conf.getFloatList("empty"));
867        }
868    
869        @Test
870        public void testGetDoubleArray()
871        {
872            // missing list
873            double[] defaultValue = new double[] { 2, 1 };
874            ArrayAssert.assertEquals(defaultValue, conf.getDoubleArray("double.list", defaultValue), 0);
875    
876            double[] expected = new double[] { 1, 2 };
877    
878            // list of strings
879            ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list1"), 0);
880    
881            // list of strings, comma separated
882            ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list2"), 0);
883    
884            // list of Double objects
885            ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list3"), 0);
886    
887            // array of Double objects
888            ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list4"), 0);
889    
890            // array of double primitives
891            ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list5"), 0);
892    
893            // list of Double objects
894            ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list6"), 0);
895    
896            // list of interpolated values
897            ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list.interpolated"), 0);
898    
899            // single double values
900            ArrayAssert.assertEquals(new double[] { 1 }, conf.getDoubleArray("double.string"), 0);
901            ArrayAssert.assertEquals(new double[] { 1 }, conf.getDoubleArray("double.object"), 0);
902    
903            // empty array
904            ArrayAssert.assertEquals(new double[] { }, conf.getDoubleArray("empty"), 0);
905        }
906    
907        @Test
908        public void testGetDoubleList()
909        {
910            // missing list
911            ListAssert.assertEquals(null, conf.getDoubleList("double.list", null));
912    
913            List<Object> expected = new ArrayList<Object>();
914            expected.add(new Double("1"));
915            expected.add(new Double("2"));
916    
917            // list of strings
918            ListAssert.assertEquals(expected, conf.getDoubleList("double.list1"));
919    
920            // list of strings, comma separated
921            ListAssert.assertEquals(expected, conf.getDoubleList("double.list2"));
922    
923            // list of Double objects
924            ListAssert.assertEquals(expected, conf.getDoubleList("double.list3"));
925    
926            // array of Double objects
927            ListAssert.assertEquals(expected, conf.getDoubleList("double.list4"));
928    
929            // array of double primitives
930            ListAssert.assertEquals(expected, conf.getDoubleList("double.list5"));
931    
932            // list of Double objects
933            ListAssert.assertEquals(expected, conf.getDoubleList("double.list6"));
934    
935            // list of interpolated values
936            ListAssert.assertEquals(expected, conf.getDoubleList("double.list.interpolated"));
937    
938            // single double values
939            expected = new ArrayList<Object>();
940            expected.add(new Double("1"));
941            ListAssert.assertEquals(expected, conf.getDoubleList("double.string"));
942            ListAssert.assertEquals(expected, conf.getDoubleList("double.object"));
943    
944            // empty list
945            ListAssert.assertEquals(new ArrayList<Object>(), conf.getDoubleList("empty"));
946        }
947    
948        @Test
949        public void testGetBigIntegerArray()
950        {
951            // missing list
952            BigInteger[] defaultValue = new BigInteger[] { new BigInteger("2"), new BigInteger("1") };
953            ArrayAssert.assertEquals(defaultValue, conf.getBigIntegerArray("biginteger.list", defaultValue));
954    
955            BigInteger[] expected = new BigInteger[] { new BigInteger("1"), new BigInteger("2") };
956    
957            // list of strings
958            ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list1"));
959    
960            // list of strings, comma separated
961            ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list2"));
962    
963            // list of BigInteger objects
964            ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list3"));
965    
966            // array of BigInteger objects
967            ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list4"));
968    
969            // list of BigInteger objects
970            ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list6"));
971    
972            // list of interpolated values
973            ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list.interpolated"));
974    
975            // single BigInteger values
976            ArrayAssert.assertEquals(new BigInteger[] { new BigInteger("1") }, conf.getBigIntegerArray("biginteger.string"));
977            ArrayAssert.assertEquals(new BigInteger[] { new BigInteger("1") }, conf.getBigIntegerArray("biginteger.object"));
978    
979            // empty array
980            ArrayAssert.assertEquals(new BigInteger[] { }, conf.getBigIntegerArray("empty"));
981        }
982    
983        @Test
984        public void testGetBigIntegerList()
985        {
986            // missing list
987            ListAssert.assertEquals(null, conf.getBigIntegerList("biginteger.list", null));
988    
989            List<Object> expected = new ArrayList<Object>();
990            expected.add(new BigInteger("1"));
991            expected.add(new BigInteger("2"));
992    
993            // list of strings
994            ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list1"));
995    
996            // list of strings, comma separated
997            ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list2"));
998    
999            // list of BigInteger objects
1000            ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list3"));
1001    
1002            // array of BigInteger objects
1003            ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list4"));
1004    
1005            // list of BigInteger objects
1006            ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list6"));
1007    
1008            // list of interpolated values
1009            ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list.interpolated"));
1010    
1011            // single BigInteger values
1012            expected = new ArrayList<Object>();
1013            expected.add(new BigInteger("1"));
1014            ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.string"));
1015            ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.object"));
1016    
1017            // empty list
1018            ListAssert.assertEquals(new ArrayList<Object>(), conf.getBigIntegerList("empty"));
1019        }
1020    
1021        @Test
1022        public void testGetBigDecimalArray()
1023        {
1024            // missing list
1025            BigDecimal[] defaultValue = new BigDecimal[] { new BigDecimal("2"), new BigDecimal("1") };
1026            ArrayAssert.assertEquals(defaultValue, conf.getBigDecimalArray("bigdecimal.list", defaultValue));
1027    
1028            BigDecimal[] expected = new BigDecimal[] { new BigDecimal("1"), new BigDecimal("2") };
1029    
1030            // list of strings
1031            ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list1"));
1032    
1033            // list of strings, comma separated
1034            ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list2"));
1035    
1036            // list of BigDecimal objects
1037            ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list3"));
1038    
1039            // array of BigDecimal objects
1040            ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list4"));
1041    
1042            // list of BigDecimal objects
1043            ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list6"));
1044    
1045            // list of interpolated values
1046            ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list.interpolated"));
1047    
1048            // single BigDecimal values
1049            ArrayAssert.assertEquals(new BigDecimal[] { new BigDecimal("1") }, conf.getBigDecimalArray("bigdecimal.string"));
1050            ArrayAssert.assertEquals(new BigDecimal[] { new BigDecimal("1") }, conf.getBigDecimalArray("bigdecimal.object"));
1051    
1052            // empty array
1053            ArrayAssert.assertEquals(new BigDecimal[] { }, conf.getBigDecimalArray("empty"));
1054        }
1055    
1056        @Test
1057        public void testGetBigDecimalList()
1058        {
1059            // missing list
1060            ListAssert.assertEquals(null, conf.getBigDecimalList("bigdecimal.list", null));
1061    
1062            List<Object> expected = new ArrayList<Object>();
1063            expected.add(new BigDecimal("1"));
1064            expected.add(new BigDecimal("2"));
1065    
1066            // list of strings
1067            ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list1"));
1068    
1069            // list of strings, comma separated
1070            ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list2"));
1071    
1072            // list of BigDecimal objects
1073            ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list3"));
1074    
1075            // array of BigDecimal objects
1076            ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list4"));
1077    
1078            // list of BigDecimal objects
1079            ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list6"));
1080    
1081            // list of interpolated values
1082            ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list.interpolated"));
1083    
1084            // single BigDecimal values
1085            expected = new ArrayList<Object>();
1086            expected.add(new BigDecimal("1"));
1087            ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.string"));
1088            ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.object"));
1089    
1090            // empty list
1091            ListAssert.assertEquals(new ArrayList<Object>(), conf.getBigDecimalList("empty"));
1092        }
1093    
1094        @Test
1095        public void testGetURL() throws Exception
1096        {
1097            // missing URL
1098            URL defaultValue = new URL("http://www.google.com");
1099            assertEquals(defaultValue, conf.getURL("url", defaultValue));
1100    
1101            URL expected = new URL("http://jakarta.apache.org");
1102    
1103            // URL string
1104            assertEquals(expected, conf.getURL("url.string"));
1105    
1106            // URL object
1107            assertEquals(expected, conf.getURL("url.object"));
1108    
1109            // interpolated value
1110            assertEquals(expected, conf.getURL("url.string.interpolated"));
1111        }
1112    
1113        @Test
1114        public void testGetURLArray() throws Exception
1115        {
1116            // missing list
1117            URL[] defaultValue = new URL[] { new URL("http://www.apache.org"), new URL("http://jakarta.apache.org") };
1118            ArrayAssert.assertEquals(defaultValue, conf.getURLArray("url.list", defaultValue));
1119    
1120            URL[] expected = new URL[] { new URL("http://jakarta.apache.org"), new URL("http://www.apache.org") };
1121    
1122            // list of strings
1123            ArrayAssert.assertEquals(expected, conf.getURLArray("url.list1"));
1124    
1125            // list of strings, comma separated
1126            ArrayAssert.assertEquals(expected, conf.getURLArray("url.list2"));
1127    
1128            // list of URL objects
1129            ArrayAssert.assertEquals(expected, conf.getURLArray("url.list3"));
1130    
1131            // array of URL objects
1132            ArrayAssert.assertEquals(expected, conf.getURLArray("url.list4"));
1133    
1134            // list of URL objects
1135            ArrayAssert.assertEquals(expected, conf.getURLArray("url.list6"));
1136    
1137            // list of interpolated values
1138            ArrayAssert.assertEquals(expected, conf.getURLArray("url.list.interpolated"));
1139    
1140            // single URL values
1141            ArrayAssert.assertEquals(new URL[] { new URL("http://jakarta.apache.org") }, conf.getURLArray("url.string"));
1142            ArrayAssert.assertEquals(new URL[] { new URL("http://jakarta.apache.org") }, conf.getURLArray("url.object"));
1143    
1144            // empty array
1145            ArrayAssert.assertEquals(new URL[] { }, conf.getURLArray("empty"));
1146        }
1147    
1148        @Test
1149        public void testGetURLList() throws Exception
1150        {
1151            // missing list
1152            ListAssert.assertEquals(null, conf.getURLList("url.list", null));
1153    
1154            List<Object> expected = new ArrayList<Object>();
1155            expected.add(new URL("http://jakarta.apache.org"));
1156            expected.add(new URL("http://www.apache.org"));
1157    
1158            // list of strings
1159            ListAssert.assertEquals(expected, conf.getURLList("url.list1"));
1160    
1161            // list of strings, comma separated
1162            ListAssert.assertEquals(expected, conf.getURLList("url.list2"));
1163    
1164            // list of URL objects
1165            ListAssert.assertEquals(expected, conf.getURLList("url.list3"));
1166    
1167            // array of URL objects
1168            ListAssert.assertEquals(expected, conf.getURLList("url.list4"));
1169    
1170            // list of URL objects
1171            ListAssert.assertEquals(expected, conf.getURLList("url.list6"));
1172    
1173            // list of interpolated values
1174            ListAssert.assertEquals(expected, conf.getURLList("url.list.interpolated"));
1175    
1176            // single URL values
1177            expected = new ArrayList<Object>();
1178            expected.add(new URL("http://jakarta.apache.org"));
1179            ListAssert.assertEquals(expected, conf.getURLList("url.string"));
1180            ListAssert.assertEquals(expected, conf.getURLList("url.object"));
1181    
1182            // empty list
1183            ListAssert.assertEquals(new ArrayList<Object>(), conf.getURLList("empty"));
1184        }
1185    
1186        @Test
1187        public void testGetLocale()
1188        {
1189            // language
1190            conf.setProperty("locale", "fr");
1191            assertEquals("language", new Locale("fr", ""), conf.getLocale("locale"));
1192    
1193            // language + variant
1194            conf.setProperty("locale", "fr__POSIX");
1195            assertEquals("language + variant", new Locale("fr", "", "POSIX"), conf.getLocale("locale"));
1196    
1197            // country
1198            conf.setProperty("locale", "_FR");
1199            assertEquals("country", new Locale("", "FR"), conf.getLocale("locale"));
1200    
1201            // country + variant
1202            conf.setProperty("locale", "_FR_WIN");
1203            assertEquals("country + variant", new Locale("", "FR", "WIN"), conf.getLocale("locale"));
1204    
1205            // language + country
1206            conf.setProperty("locale", "fr_FR");
1207            assertEquals("language + country", new Locale("fr", "FR"), conf.getLocale("locale"));
1208    
1209            // language + country + variant
1210            conf.setProperty("locale", "fr_FR_MAC");
1211            assertEquals("language + country + variant", new Locale("fr", "FR", "MAC"), conf.getLocale("locale"));
1212    
1213            // default value
1214            conf.setProperty("locale", "fr");
1215            assertEquals("Existing key with default value", Locale.FRENCH, conf.getLocale("locale", Locale.GERMAN));
1216            assertEquals("Missing key with default value", Locale.GERMAN, conf.getLocale("localeNotInConfig", Locale.GERMAN));
1217    
1218            // interpolated value
1219            assertEquals(Locale.FRENCH, conf.getLocale("locale.string.interpolated"));
1220        }
1221    
1222        @Test
1223        public void testGetLocaleArray() throws Exception
1224        {
1225            // missing list
1226            Locale[] defaultValue = new Locale[] { Locale.GERMAN, Locale.FRENCH };
1227            ArrayAssert.assertEquals(defaultValue, conf.getLocaleArray("locale.list", defaultValue));
1228    
1229            Locale[] expected = new Locale[] { Locale.FRENCH, Locale.GERMAN };
1230    
1231            // list of strings
1232            ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list1"));
1233    
1234            // list of strings, comma separated
1235            ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list2"));
1236    
1237            // list of Locale objects
1238            ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list3"));
1239    
1240            // array of Locale objects
1241            ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list4"));
1242    
1243            // list of Locale objects
1244            ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list6"));
1245    
1246            // list of interpolated values
1247            ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list.interpolated"));
1248    
1249            // single Locale values
1250            ArrayAssert.assertEquals(new Locale[] { Locale.FRENCH }, conf.getLocaleArray("locale.string"));
1251            ArrayAssert.assertEquals(new Locale[] { Locale.FRENCH }, conf.getLocaleArray("locale.object"));
1252    
1253            // empty array
1254            ArrayAssert.assertEquals(new Locale[] { }, conf.getLocaleArray("empty"));
1255        }
1256    
1257        @Test
1258        public void testGetLocaleList() throws Exception
1259        {
1260            // missing list
1261            ListAssert.assertEquals(null, conf.getLocaleList("locale.list", null));
1262    
1263            List<Object> expected = new ArrayList<Object>();
1264            expected.add(Locale.FRENCH);
1265            expected.add(Locale.GERMAN);
1266    
1267            // list of strings
1268            ListAssert.assertEquals(expected, conf.getLocaleList("locale.list1"));
1269    
1270            // list of strings, comma separated
1271            ListAssert.assertEquals(expected, conf.getLocaleList("locale.list2"));
1272    
1273            // list of Locale objects
1274            ListAssert.assertEquals(expected, conf.getLocaleList("locale.list3"));
1275    
1276            // array of Locale objects
1277            ListAssert.assertEquals(expected, conf.getLocaleList("locale.list4"));
1278    
1279            // list of Locale objects
1280            ListAssert.assertEquals(expected, conf.getLocaleList("locale.list6"));
1281    
1282            // list of interpolated values
1283            ListAssert.assertEquals(expected, conf.getLocaleList("locale.list.interpolated"));
1284    
1285            // single Locale values
1286            expected = new ArrayList<Object>();
1287            expected.add(Locale.FRENCH);
1288            ListAssert.assertEquals(expected, conf.getLocaleList("locale.string"));
1289            ListAssert.assertEquals(expected, conf.getLocaleList("locale.object"));
1290    
1291            // empty list
1292            ListAssert.assertEquals(new ArrayList<Object>(), conf.getLocaleList("empty"));
1293        }
1294    
1295        @Test
1296        public void testGetColor()
1297        {
1298            // RRGGBB
1299            conf.setProperty("color", "FF0000");
1300            assertEquals("color", Color.red, conf.getColor("color"));
1301    
1302            // #RRGGBB
1303            conf.setProperty("color", "#00FF00");
1304            assertEquals("color", Color.green, conf.getColor("color"));
1305    
1306            // #RRGGBBAA
1307            conf.setProperty("color", "#01030507");
1308            Color color = conf.getColor("color");
1309            assertNotNull("null color", color);
1310            assertEquals("red",   1, color.getRed());
1311            assertEquals("green", 3, color.getGreen());
1312            assertEquals("blue",  5, color.getBlue());
1313            assertEquals("alpha", 7, color.getAlpha());
1314    
1315            // interpolated value
1316            assertEquals(Color.red, conf.getColor("color.string.interpolated"));
1317    
1318            // default value
1319            assertEquals(Color.cyan, conf.getColor("unknownkey", Color.cyan));
1320        }
1321    
1322        @Test
1323        public void testGetColorArray() throws Exception
1324        {
1325            // missing list
1326            Color[] defaultValue = new Color[] { Color.red, Color.blue };
1327            ArrayAssert.assertEquals(defaultValue, conf.getColorArray("color.list", defaultValue));
1328    
1329            Color[] expected = new Color[] { Color.red, Color.blue };
1330    
1331            // list of strings
1332            ArrayAssert.assertEquals(expected, conf.getColorArray("color.list1"));
1333    
1334            // list of strings, comma separated
1335            ArrayAssert.assertEquals(expected, conf.getColorArray("color.list2"));
1336    
1337            // list of Color objects
1338            ArrayAssert.assertEquals(expected, conf.getColorArray("color.list3"));
1339    
1340            // array of Color objects
1341            ArrayAssert.assertEquals(expected, conf.getColorArray("color.list4"));
1342    
1343            // list of Color objects
1344            ArrayAssert.assertEquals(expected, conf.getColorArray("color.list6"));
1345    
1346            // list of interpolated values
1347            ArrayAssert.assertEquals(expected, conf.getColorArray("color.list.interpolated"));
1348    
1349            // single Color values
1350            ArrayAssert.assertEquals(new Color[] { Color.red }, conf.getColorArray("color.string"));
1351            ArrayAssert.assertEquals(new Color[] { Color.red }, conf.getColorArray("color.object"));
1352    
1353            // empty array
1354            ArrayAssert.assertEquals(new Color[] { }, conf.getColorArray("empty"));
1355        }
1356    
1357        @Test
1358        public void testGetColorList() throws Exception
1359        {
1360            // missing list
1361            ListAssert.assertEquals(null, conf.getColorList("color.list", null));
1362    
1363            List<Object> expected = new ArrayList<Object>();
1364            expected.add(Color.red);
1365            expected.add(Color.blue);
1366    
1367            // list of strings
1368            ListAssert.assertEquals(expected, conf.getColorList("color.list1"));
1369    
1370            // list of strings, comma separated
1371            ListAssert.assertEquals(expected, conf.getColorList("color.list2"));
1372    
1373            // list of Color objects
1374            ListAssert.assertEquals(expected, conf.getColorList("color.list3"));
1375    
1376            // array of Color objects
1377            ListAssert.assertEquals(expected, conf.getColorList("color.list4"));
1378    
1379            // list of Color objects
1380            ListAssert.assertEquals(expected, conf.getColorList("color.list6"));
1381    
1382            // list of interpolated values
1383            ListAssert.assertEquals(expected, conf.getColorList("color.list.interpolated"));
1384    
1385            // single Color values
1386            expected = new ArrayList<Object>();
1387            expected.add(Color.red);
1388            ListAssert.assertEquals(expected, conf.getColorList("color.string"));
1389            ListAssert.assertEquals(expected, conf.getColorList("color.object"));
1390    
1391            // empty list
1392            ListAssert.assertEquals(new ArrayList<Object>(), conf.getColorList("empty"));
1393        }
1394    
1395        @Test
1396        public void testGetDate() throws Exception
1397        {
1398            DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
1399    
1400            // missing Date
1401            Date defaultValue = new Date();
1402            assertEquals(defaultValue, conf.getDate("date", defaultValue));
1403            assertNull("non null object for a missing key", conf.getDate("unknownkey", "yyyy-MM-dd"));
1404    
1405            conf.setThrowExceptionOnMissing(true);
1406    
1407            try
1408            {
1409                conf.getDate("unknownkey", "yyyy-MM-dd");
1410                fail("NoSuchElementException should be thrown for missing properties");
1411            }
1412            catch (NoSuchElementException e)
1413            {
1414                // expected
1415            }
1416    
1417            Date expected = format.parse("2004-01-01");
1418    
1419            // Date string
1420            assertEquals(expected, conf.getDate("date.string"));
1421            assertEquals(expected, conf.getDate("date.string", "yyyy-MM-dd"));
1422    
1423            // Date object
1424            assertEquals(expected, conf.getDate("date.object"));
1425    
1426            // Calendar object
1427            assertEquals(expected, conf.getDate("calendar.object"));
1428    
1429            // interpolated value
1430            assertEquals(expected, conf.getDate("date.string.interpolated"));
1431        }
1432    
1433        @Test
1434        public void testGetDateArray() throws Exception
1435        {
1436            DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
1437            Date date1 = format.parse("2004-01-01");
1438            Date date2 = format.parse("2004-12-31");
1439    
1440            // missing list
1441            Date[] defaultValue = new Date[] { date2, date1 };
1442            ArrayAssert.assertEquals(defaultValue, conf.getDateArray("date.list", defaultValue));
1443    
1444            Date[] expected = new Date[] { date1, date2 };
1445    
1446            // list of strings
1447            ArrayAssert.assertEquals(expected, conf.getDateArray("date.list1"));
1448    
1449            // list of strings, comma separated
1450            ArrayAssert.assertEquals(expected, conf.getDateArray("date.list2"));
1451    
1452            // list of Date objects
1453            ArrayAssert.assertEquals(expected, conf.getDateArray("date.list3"));
1454    
1455            // array of Date objects
1456            ArrayAssert.assertEquals(expected, conf.getDateArray("date.list4"));
1457    
1458            // list of Calendar objects
1459            ArrayAssert.assertEquals(expected, conf.getDateArray("date.list5"));
1460    
1461            // list of Date objects
1462            ArrayAssert.assertEquals(expected, conf.getDateArray("date.list6"));
1463    
1464            // list of interpolated values
1465            ArrayAssert.assertEquals(expected, conf.getDateArray("date.list.interpolated"));
1466    
1467            // single Date values
1468            ArrayAssert.assertEquals(new Date[] { date1 }, conf.getDateArray("date.string"));
1469            ArrayAssert.assertEquals(new Date[] { date1 }, conf.getDateArray("date.object"));
1470    
1471            // empty array
1472            ArrayAssert.assertEquals(new Date[] { }, conf.getDateArray("empty"));
1473        }
1474    
1475        @Test
1476        public void testGetDateArrayWithFormat() throws Exception
1477        {
1478            DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
1479            Date date1 = format.parse("01/01/2004");
1480            Date date2 = format.parse("12/31/2004");
1481            Date[] expected = new Date[] { date1, date2 };
1482    
1483            conf.addProperty("date.format", "01/01/2004");
1484            conf.addProperty("date.format", "12/31/2004");
1485            ArrayAssert.assertEquals("Wrong dates with format", expected, conf.getDateArray("date.format", "MM/dd/yyyy"));
1486        }
1487    
1488        @Test
1489        public void testGetDateList() throws Exception
1490        {
1491            DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
1492            Date date1 = format.parse("2004-01-01");
1493            Date date2 = format.parse("2004-12-31");
1494    
1495            // missing list
1496            List<Date> nullList = null;
1497            ListAssert.assertEquals(null, conf.getDateList("date.list", nullList));
1498    
1499            List<Object> expected = new ArrayList<Object>();
1500            expected.add(date1);
1501            expected.add(date2);
1502    
1503            // list of strings
1504            ListAssert.assertEquals(expected, conf.getDateList("date.list1"));
1505            ListAssert.assertEquals(expected, conf.getList(Date.class, "date.list1"));
1506    
1507            // list of strings, comma separated
1508            ListAssert.assertEquals(expected, conf.getDateList("date.list2"));
1509    
1510            // list of Date objects
1511            ListAssert.assertEquals(expected, conf.getDateList("date.list3"));
1512    
1513            // array of Date objects
1514            ListAssert.assertEquals(expected, conf.getDateList("date.list4"));
1515    
1516            // list of Calendar objects
1517            ListAssert.assertEquals(expected, conf.getDateList("date.list5"));
1518    
1519            // list of Date objects
1520            ListAssert.assertEquals(expected, conf.getDateList("date.list6"));
1521    
1522            // array of strings
1523            ListAssert.assertEquals(expected, conf.getList(Date.class, "date.list7"));
1524    
1525            // list of interpolated values
1526            ListAssert.assertEquals(expected, conf.getDateList("date.list.interpolated"));
1527    
1528            // single Date values
1529            expected = new ArrayList<Object>();
1530            expected.add(date1);
1531            ListAssert.assertEquals(expected, conf.getDateList("date.string"));
1532            ListAssert.assertEquals(expected, conf.getDateList("date.object"));
1533    
1534            // empty list
1535            ListAssert.assertEquals(new ArrayList<Object>(), conf.getDateList("empty"));
1536        }
1537    
1538        @Test
1539        public void testGetCalendar() throws Exception
1540        {
1541            DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
1542    
1543            // missing Date
1544            Calendar defaultValue = Calendar.getInstance();
1545            defaultValue.setTime(new Date());
1546            assertEquals(defaultValue, conf.getCalendar("calendar", defaultValue));
1547            assertNull("non null object for a missing key", conf.getCalendar("unknownkey", "yyyy-MM-dd"));
1548    
1549            conf.setThrowExceptionOnMissing(true);
1550    
1551            try
1552            {
1553                conf.getCalendar("unknownkey", "yyyy-MM-dd");
1554                fail("NoSuchElementException should be thrown for missing properties");
1555            }
1556            catch (NoSuchElementException e)
1557            {
1558                // expected
1559            }
1560    
1561            Calendar expected = Calendar.getInstance();
1562            expected.setTime(format.parse("2004-01-01"));
1563    
1564            // Calendar string
1565            assertEquals(expected, conf.getCalendar("calendar.string"));
1566            assertEquals(expected, conf.getCalendar("calendar.string",  "yyyy-MM-dd"));
1567    
1568            // Calendar object
1569            assertEquals(expected, conf.getCalendar("calendar.object"));
1570    
1571            // Date object
1572            assertEquals(expected, conf.getCalendar("date.object"));
1573    
1574            // interpolated value
1575            assertEquals(expected, conf.getCalendar("calendar.string.interpolated"));
1576        }
1577    
1578        @Test
1579        public void testGetCalendarArray() throws Exception
1580        {
1581            DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
1582            Date date1 = format.parse("2004-01-01");
1583            Date date2 = format.parse("2004-12-31");
1584            Calendar calendar1 = Calendar.getInstance();
1585            calendar1.setTime(date1);
1586            Calendar calendar2 = Calendar.getInstance();
1587            calendar2.setTime(date2);
1588    
1589            // missing list
1590            Calendar[] defaultValue = new Calendar[] { calendar2, calendar1 };
1591            ArrayAssert.assertEquals(defaultValue, conf.getCalendarArray("calendar.list", defaultValue));
1592    
1593            Calendar[] expected = new Calendar[] { calendar1, calendar2 };
1594    
1595            // list of strings
1596            ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list1"));
1597    
1598            // list of strings, comma separated
1599            ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list2"));
1600    
1601            // list of Calendar objects
1602            ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list3"));
1603    
1604            // array of Calendar objects
1605            ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list4"));
1606    
1607            // list of Date objects
1608            ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list5"));
1609    
1610            // list of Calendar objects
1611            ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list6"));
1612    
1613            // list of interpolated values
1614            ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list.interpolated"));
1615    
1616            // single Calendar values
1617            ArrayAssert.assertEquals(new Calendar[] { calendar1 }, conf.getCalendarArray("calendar.string"));
1618            ArrayAssert.assertEquals(new Calendar[] { calendar1 }, conf.getCalendarArray("calendar.object"));
1619    
1620            // empty array
1621            ArrayAssert.assertEquals(new Calendar[] { }, conf.getCalendarArray("empty"));
1622        }
1623    
1624        @Test
1625        public void testGetCalendarArrayWithFormat() throws Exception
1626        {
1627            DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
1628            Date date1 = format.parse("01/01/2004");
1629            Date date2 = format.parse("12/31/2004");
1630    
1631            Calendar calendar1 = Calendar.getInstance();
1632            calendar1.setTime(date1);
1633            Calendar calendar2 = Calendar.getInstance();
1634            calendar2.setTime(date2);
1635            Calendar[] expected = new Calendar[] { calendar1, calendar2 };
1636    
1637            conf.addProperty("calendar.format", "01/01/2004");
1638            conf.addProperty("calendar.format", "12/31/2004");
1639            ArrayAssert.assertEquals("Wrong calendars with format", expected, conf.getCalendarArray("calendar.format", "MM/dd/yyyy"));
1640        }
1641    
1642        @Test
1643        public void testGetCalendarList() throws Exception
1644        {
1645            DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
1646            Date date1 = format.parse("2004-01-01");
1647            Date date2 = format.parse("2004-12-31");
1648            Calendar calendar1 = Calendar.getInstance();
1649            calendar1.setTime(date1);
1650            Calendar calendar2 = Calendar.getInstance();
1651            calendar2.setTime(date2);
1652    
1653            // missing list
1654            List<Calendar> nullList = null;
1655            ListAssert.assertEquals(null, conf.getCalendarList("calendar.list", nullList));
1656    
1657            List<Object> expected = new ArrayList<Object>();
1658            expected.add(calendar1);
1659            expected.add(calendar2);
1660    
1661            // list of strings
1662            ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list1"));
1663            ListAssert.assertEquals(expected, conf.getList(Calendar.class, "calendar.list1"));
1664    
1665            // list of strings, comma separated
1666            ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list2"));
1667    
1668            // list of Calendar objects
1669            ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list3"));
1670    
1671            // array of Calendar objects
1672            ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list4"));
1673    
1674            // list of Date objects
1675            ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list5"));
1676    
1677            // list of Calendar objects
1678            ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list6"));
1679    
1680            // array of strings
1681            ListAssert.assertEquals(expected, conf.getList(Calendar.class, "calendar.list7"));
1682    
1683            // list of interpolated values
1684            ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list.interpolated"));
1685    
1686            // single Calendar values
1687            expected = new ArrayList<Object>();
1688            expected.add(calendar1);
1689            ListAssert.assertEquals(expected, conf.getCalendarList("date.string"));
1690            ListAssert.assertEquals(expected, conf.getCalendarList("date.object"));
1691    
1692            // empty list
1693            ListAssert.assertEquals(new ArrayList<Object>(), conf.getCalendarList("empty"));
1694        }
1695    
1696        @Test
1697        public void testGetInetAddress() throws Exception
1698        {
1699            InetAddress expected = InetAddress.getByName("127.0.0.1");
1700    
1701            // address as string
1702            assertEquals(expected, conf.get(InetAddress.class, "ip.string"));
1703    
1704            // address object
1705            assertEquals(expected, conf.get(InetAddress.class, "ip.object"));
1706    
1707            // interpolated value
1708            assertEquals(expected, conf.get(InetAddress.class, "ip.string.interpolated"));
1709        }
1710    
1711        @Test(expected = ConversionException.class)
1712        public void testGetInetAddressInvalidType()
1713        {
1714            conf.setProperty("ip.unknownhost", "foo");
1715            conf.get(InetAddress.class, "ip.unknownhost");
1716        }
1717    
1718        @Test
1719        public void testGetInternetAddress() throws Exception
1720        {
1721            Object expected = createInternetAddress("ebourg@apache.org");
1722    
1723            // address as string
1724            assertEquals(expected, conf.get(expected.getClass(), "email.string"));
1725    
1726            // address object
1727            assertEquals(expected, conf.get(expected.getClass(), "email.object"));
1728    
1729            // interpolated value
1730            assertEquals(expected, conf.get(expected.getClass(), "email.string.interpolated"));
1731    
1732            conf.setProperty("email.invalid", "ebourg@apache@org");
1733            try
1734            {
1735                conf.get(expected.getClass(), "email.invalid");
1736                fail("ConversionException should be thrown for invalid emails");
1737            }
1738            catch (ConversionException e)
1739            {
1740                // expected
1741            }
1742        }
1743    
1744        @Test(expected = ConversionException.class)
1745        public void testGetInternetAddressInvalidType() throws Exception
1746        {
1747            Object expected = createInternetAddress("ebourg@apache.org");
1748            conf.setProperty("email.invalid", "ebourg@apache@org");
1749            conf.get(expected.getClass(), "email.invalid");
1750        }
1751    
1752        /**
1753         * Create an instance of InternetAddress. This trick is necessary to
1754         * compile and run the test with Java 1.3 and the javamail-1.4 which
1755         * is not compatible with Java 1.3
1756         */
1757        private Object createInternetAddress(String email) throws Exception
1758        {
1759            Class<?> cls = Class.forName("javax.mail.internet.InternetAddress");
1760            return cls.getConstructor(new Class[]{String.class}).newInstance(new Object[]{email});
1761        }
1762    
1763        @Test
1764        public void testConversionException() throws Exception
1765        {
1766            conf.addProperty("key1", new Object());
1767            conf.addProperty("key2", "xxxxxx");
1768    
1769            try
1770            {
1771                conf.getBooleanArray("key1");
1772                fail("getBooleanArray didn't throw a ConversionException");
1773            }
1774            catch (ConversionException e)
1775            {
1776                // expected
1777            }
1778    
1779            try
1780            {
1781                conf.getBooleanArray("key2");
1782                fail("getBooleanArray didn't throw a ConversionException");
1783            }
1784            catch (ConversionException e)
1785            {
1786                // expected
1787            }
1788    
1789            try
1790            {
1791                conf.getBooleanList("key1");
1792                fail("getBooleanList didn't throw a ConversionException");
1793            }
1794            catch (ConversionException e)
1795            {
1796                // expected
1797            }
1798    
1799            try
1800            {
1801                conf.getBooleanList("key2");
1802                fail("getBooleanList didn't throw a ConversionException");
1803            }
1804            catch (ConversionException e)
1805            {
1806                // expected
1807            }
1808    
1809            try
1810            {
1811                conf.getByteArray("key1");
1812                fail("getByteArray didn't throw a ConversionException");
1813            }
1814            catch (ConversionException e)
1815            {
1816                // expected
1817            }
1818    
1819            try
1820            {
1821                conf.getByteArray("key2");
1822                fail("getByteArray didn't throw a ConversionException");
1823            }
1824            catch (ConversionException e)
1825            {
1826                // expected
1827            }
1828    
1829            try
1830            {
1831                conf.getByteList("key1");
1832                fail("getByteList didn't throw a ConversionException");
1833            }
1834            catch (ConversionException e)
1835            {
1836                // expected
1837            }
1838    
1839            try
1840            {
1841                conf.getByteList("key2");
1842                fail("getByteList didn't throw a ConversionException");
1843            }
1844            catch (ConversionException e)
1845            {
1846                // expected
1847            }
1848    
1849            try
1850            {
1851                conf.getShortArray("key1");
1852                fail("getShortArray didn't throw a ConversionException");
1853            }
1854            catch (ConversionException e)
1855            {
1856                // expected
1857            }
1858    
1859            try
1860            {
1861                conf.getShortArray("key2");
1862                fail("getShortArray didn't throw a ConversionException");
1863            }
1864            catch (ConversionException e)
1865            {
1866                // expected
1867            }
1868    
1869            try
1870            {
1871                conf.getShortList("key1");
1872                fail("getShortList didn't throw a ConversionException");
1873            }
1874            catch (ConversionException e)
1875            {
1876                // expected
1877            }
1878    
1879            try
1880            {
1881                conf.getShortList("key2");
1882                fail("getShortList didn't throw a ConversionException");
1883            }
1884            catch (ConversionException e)
1885            {
1886                // expected
1887            }
1888    
1889            try
1890            {
1891                conf.getIntArray("key1");
1892                fail("getIntArray didn't throw a ConversionException");
1893            }
1894            catch (ConversionException e)
1895            {
1896                // expected
1897            }
1898    
1899            try
1900            {
1901                conf.getIntArray("key2");
1902                fail("getIntArray didn't throw a ConversionException");
1903            }
1904            catch (ConversionException e)
1905            {
1906                // expected
1907            }
1908    
1909            try
1910            {
1911                conf.getIntegerList("key1");
1912                fail("getIntegerList didn't throw a ConversionException");
1913            }
1914            catch (ConversionException e)
1915            {
1916                // expected
1917            }
1918    
1919            try
1920            {
1921                conf.getIntegerList("key2");
1922                fail("getIntegerList didn't throw a ConversionException");
1923            }
1924            catch (ConversionException e)
1925            {
1926                // expected
1927            }
1928    
1929            try
1930            {
1931                conf.getLongArray("key1");
1932                fail("getLongArray didn't throw a ConversionException");
1933            }
1934            catch (ConversionException e)
1935            {
1936                // expected
1937            }
1938    
1939            try
1940            {
1941                conf.getLongArray("key2");
1942                fail("getLongArray didn't throw a ConversionException");
1943            }
1944            catch (ConversionException e)
1945            {
1946                // expected
1947            }
1948    
1949            try
1950            {
1951                conf.getLongList("key1");
1952                fail("getLongList didn't throw a ConversionException");
1953            }
1954            catch (ConversionException e)
1955            {
1956                // expected
1957            }
1958    
1959            try
1960            {
1961                conf.getLongList("key2");
1962                fail("getLongList didn't throw a ConversionException");
1963            }
1964            catch (ConversionException e)
1965            {
1966                // expected
1967            }
1968    
1969            try
1970            {
1971                conf.getFloatArray("key1");
1972                fail("getFloatArray didn't throw a ConversionException");
1973            }
1974            catch (ConversionException e)
1975            {
1976                // expected
1977            }
1978    
1979            try
1980            {
1981                conf.getFloatArray("key2");
1982                fail("getFloatArray didn't throw a ConversionException");
1983            }
1984            catch (ConversionException e)
1985            {
1986                // expected
1987            }
1988    
1989            try
1990            {
1991                conf.getFloatList("key1");
1992                fail("getFloatList didn't throw a ConversionException");
1993            }
1994            catch (ConversionException e)
1995            {
1996                // expected
1997            }
1998    
1999            try
2000            {
2001                conf.getFloatList("key2");
2002                fail("getFloatList didn't throw a ConversionException");
2003            }
2004            catch (ConversionException e)
2005            {
2006                // expected
2007            }
2008    
2009            try
2010            {
2011                conf.getDoubleArray("key1");
2012                fail("getDoubleArray didn't throw a ConversionException");
2013            }
2014            catch (ConversionException e)
2015            {
2016                // expected
2017            }
2018    
2019            try
2020            {
2021                conf.getDoubleArray("key2");
2022                fail("getDoubleArray didn't throw a ConversionException");
2023            }
2024            catch (ConversionException e)
2025            {
2026                // expected
2027            }
2028    
2029            try
2030            {
2031                conf.getDoubleList("key1");
2032                fail("getDoubleList didn't throw a ConversionException");
2033            }
2034            catch (ConversionException e)
2035            {
2036                // expected
2037            }
2038    
2039            try
2040            {
2041                conf.getDoubleList("key2");
2042                fail("getDoubleList didn't throw a ConversionException");
2043            }
2044            catch (ConversionException e)
2045            {
2046                // expected
2047            }
2048    
2049            try
2050            {
2051                conf.getBigIntegerArray("key1");
2052                fail("getBigIntegerArray didn't throw a ConversionException");
2053            }
2054            catch (ConversionException e)
2055            {
2056                // expected
2057            }
2058    
2059            try
2060            {
2061                conf.getBigIntegerArray("key2");
2062                fail("getBigIntegerArray didn't throw a ConversionException");
2063            }
2064            catch (ConversionException e)
2065            {
2066                // expected
2067            }
2068    
2069            try
2070            {
2071                conf.getBigIntegerList("key1");
2072                fail("getBigIntegerList didn't throw a ConversionException");
2073            }
2074            catch (ConversionException e)
2075            {
2076                // expected
2077            }
2078    
2079            try
2080            {
2081                conf.getBigIntegerList("key2");
2082                fail("getBigIntegerList didn't throw a ConversionException");
2083            }
2084            catch (ConversionException e)
2085            {
2086                // expected
2087            }
2088    
2089            try
2090            {
2091                conf.getBigDecimalArray("key1");
2092                fail("getBigDecimalArray didn't throw a ConversionException");
2093            }
2094            catch (ConversionException e)
2095            {
2096                // expected
2097            }
2098    
2099            try
2100            {
2101                conf.getBigDecimalArray("key2");
2102                fail("getBigDecimalArray didn't throw a ConversionException");
2103            }
2104            catch (ConversionException e)
2105            {
2106                // expected
2107            }
2108    
2109            try
2110            {
2111                conf.getBigDecimalList("key1");
2112                fail("getBigDecimalList didn't throw a ConversionException");
2113            }
2114            catch (ConversionException e)
2115            {
2116                // expected
2117            }
2118    
2119            try
2120            {
2121                conf.getBigDecimalList("key2");
2122                fail("getBigDecimalList didn't throw a ConversionException");
2123            }
2124            catch (ConversionException e)
2125            {
2126                // expected
2127            }
2128    
2129            try
2130            {
2131                conf.getURLArray("key1");
2132                fail("getURLArray didn't throw a ConversionException");
2133            }
2134            catch (ConversionException e)
2135            {
2136                // expected
2137            }
2138    
2139            try
2140            {
2141                conf.getURLArray("key2");
2142                fail("getURLArray didn't throw a ConversionException");
2143            }
2144            catch (ConversionException e)
2145            {
2146                // expected
2147            }
2148    
2149            try
2150            {
2151                conf.getURLList("key1");
2152                fail("getURLList didn't throw a ConversionException");
2153            }
2154            catch (ConversionException e)
2155            {
2156                // expected
2157            }
2158    
2159            try
2160            {
2161                conf.getURLList("key2");
2162                fail("getURLList didn't throw a ConversionException");
2163            }
2164            catch (ConversionException e)
2165            {
2166                // expected
2167            }
2168    
2169            try
2170            {
2171                conf.getLocaleArray("key1");
2172                fail("getLocaleArray didn't throw a ConversionException");
2173            }
2174            catch (ConversionException e)
2175            {
2176                // expected
2177            }
2178    
2179            try
2180            {
2181                conf.getLocaleArray("key2");
2182                fail("getLocaleArray didn't throw a ConversionException");
2183            }
2184            catch (ConversionException e)
2185            {
2186                // expected
2187            }
2188    
2189            try
2190            {
2191                conf.getLocaleList("key1");
2192                fail("getLocaleList didn't throw a ConversionException");
2193            }
2194            catch (ConversionException e)
2195            {
2196                // expected
2197            }
2198    
2199            try
2200            {
2201                conf.getLocaleList("key2");
2202                fail("getLocaleList didn't throw a ConversionException");
2203            }
2204            catch (ConversionException e)
2205            {
2206                // expected
2207            }
2208    
2209            try
2210            {
2211                conf.getColorArray("key1");
2212                fail("getColorArray didn't throw a ConversionException");
2213            }
2214            catch (ConversionException e)
2215            {
2216                // expected
2217            }
2218    
2219            try
2220            {
2221                conf.getColorArray("key2");
2222                fail("getColorArray didn't throw a ConversionException");
2223            }
2224            catch (ConversionException e)
2225            {
2226                // expected
2227            }
2228    
2229            try
2230            {
2231                conf.getColorList("key1");
2232                fail("getColorList didn't throw a ConversionException");
2233            }
2234            catch (ConversionException e)
2235            {
2236                // expected
2237            }
2238    
2239            try
2240            {
2241                conf.getColorList("key2");
2242                fail("getColorList didn't throw a ConversionException");
2243            }
2244            catch (ConversionException e)
2245            {
2246                // expected
2247            }
2248    
2249            try
2250            {
2251                conf.getDateArray("key1");
2252                fail("getDateArray didn't throw a ConversionException");
2253            }
2254            catch (ConversionException e)
2255            {
2256                // expected
2257            }
2258    
2259            try
2260            {
2261                conf.getDate("key1", "yyyy-MM-dd");
2262                fail("getDate didn't throw a ConversionException");
2263            }
2264            catch (ConversionException e)
2265            {
2266                // expected
2267            }
2268    
2269            try
2270            {
2271                conf.getDate("key2", "yyyy-MM-dd");
2272                fail("getDate didn't throw a ConversionException");
2273            }
2274            catch (ConversionException e)
2275            {
2276                // expected
2277            }
2278    
2279            try
2280            {
2281                conf.getDateArray("key2");
2282                fail("getDateArray didn't throw a ConversionException");
2283            }
2284            catch (ConversionException e)
2285            {
2286                // expected
2287            }
2288    
2289            try
2290            {
2291                conf.getDateList("key1");
2292                fail("getDateList didn't throw a ConversionException");
2293            }
2294            catch (ConversionException e)
2295            {
2296                // expected
2297            }
2298    
2299            try
2300            {
2301                conf.getDateList("key2");
2302                fail("getDateList didn't throw a ConversionException");
2303            }
2304            catch (ConversionException e)
2305            {
2306                // expected
2307            }
2308    
2309            try
2310            {
2311                conf.getCalendar("key1", "yyyy-MM-dd");
2312                fail("getCalendar didn't throw a ConversionException");
2313            }
2314            catch (ConversionException e)
2315            {
2316                // expected
2317            }
2318    
2319            try
2320            {
2321                conf.getCalendar("key2","yyyy-MM-dd");
2322                fail("getCalendar didn't throw a ConversionException");
2323            }
2324            catch (ConversionException e)
2325            {
2326                // expected
2327            }
2328    
2329            try
2330            {
2331                conf.getCalendarArray("key1");
2332                fail("getCalendarArray didn't throw a ConversionException");
2333            }
2334            catch (ConversionException e)
2335            {
2336                // expected
2337            }
2338    
2339            try
2340            {
2341                conf.getCalendarArray("key2");
2342                fail("getCalendarArray didn't throw a ConversionException");
2343            }
2344            catch (ConversionException e)
2345            {
2346                // expected
2347            }
2348    
2349            try
2350            {
2351                conf.getCalendarList("key1");
2352                fail("getCalendarList didn't throw a ConversionException");
2353            }
2354            catch (ConversionException e)
2355            {
2356                // expected
2357            }
2358    
2359            try
2360            {
2361                conf.getCalendarList("key2");
2362                fail("getCalendarList didn't throw a ConversionException");
2363            }
2364            catch (ConversionException e)
2365            {
2366                // expected
2367            }
2368    
2369            try
2370            {
2371                conf.get(InetAddress.class, "key1");
2372                fail("getInetAddress didn't throw a ConversionException");
2373            }
2374            catch (ConversionException e)
2375            {
2376                // expected
2377            }
2378    
2379            try
2380            {
2381                conf.get(Class.forName("javax.mail.internet.InternetAddress"), "key1");
2382                fail("getInternetAddress didn't throw a ConversionException");
2383            }
2384            catch (ConversionException e)
2385            {
2386                // expected
2387            }
2388        }
2389    
2390        /**
2391         * Tests whether a string property can be obtained through get() if no type
2392         * conversion is required.
2393         */
2394        @Test
2395        public void testGetPropertyWithoutConversion()
2396        {
2397            String key = "test.str";
2398            String value = "someTestValue";
2399            conf.addProperty(key, value);
2400            assertEquals("Wrong result", value, conf.get(String.class, key));
2401        }
2402    }