KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > configuration > TestPropertyConverter


1 package org.apache.commons.configuration;
2
3 import java.util.List JavaDoc;
4 import java.util.Iterator JavaDoc;
5
6 import junit.framework.TestCase;
7
8 /**
9  * @author Emmanuel Bourg
10  * @version $Revision: 155408 $, $Date: 2005-02-26 13:56:39 +0100 (Sa, 26 Feb 2005) $
11  */

12 public class TestPropertyConverter extends TestCase
13 {
14     public void testSplit()
15     {
16         String JavaDoc s = "abc, xyz , 123";
17         List JavaDoc list = PropertyConverter.split(s, ',');
18
19         assertEquals("size", 3, list.size());
20         assertEquals("1st token for '" + s + "'", "abc", list.get(0));
21         assertEquals("2nd token for '" + s + "'", "xyz", list.get(1));
22         assertEquals("3rd token for '" + s + "'", "123", list.get(2));
23     }
24
25     public void testSplitWithEscapedSeparator()
26     {
27         String JavaDoc s = "abc\\,xyz, 123";
28         List JavaDoc list = PropertyConverter.split(s, ',');
29
30         assertEquals("size", 2, list.size());
31         assertEquals("1st token for '" + s + "'", "abc,xyz", list.get(0));
32         assertEquals("2nd token for '" + s + "'", "123", list.get(1));
33     }
34
35     public void testSplitEmptyValues()
36     {
37         String JavaDoc s = ",,";
38         List JavaDoc list = PropertyConverter.split(s, ',');
39
40         assertEquals("size", 3, list.size());
41         assertEquals("1st token for '" + s + "'", "", list.get(0));
42         assertEquals("2nd token for '" + s + "'", "", list.get(1));
43         assertEquals("3rd token for '" + s + "'", "", list.get(2));
44     }
45
46     public void testSplitWithEndingSlash()
47     {
48         String JavaDoc s = "abc, xyz\\";
49         List JavaDoc list = PropertyConverter.split(s, ',');
50
51         assertEquals("size", 2, list.size());
52         assertEquals("1st token for '" + s + "'", "abc", list.get(0));
53         assertEquals("2nd token for '" + s + "'", "xyz\\", list.get(1));
54     }
55
56     public void testSplitNull()
57     {
58         List JavaDoc list = PropertyConverter.split(null, ',');
59         assertNotNull(list);
60         assertTrue(list.isEmpty());
61     }
62
63     public void testToIterator()
64     {
65         int[] array = new int[]{1, 2, 3};
66
67         Iterator JavaDoc it = PropertyConverter.toIterator(array, ',');
68
69         assertEquals("1st element", new Integer JavaDoc(1), it.next());
70         assertEquals("2nd element", new Integer JavaDoc(2), it.next());
71         assertEquals("3rd element", new Integer JavaDoc(3), it.next());
72     }
73
74 }
75
Popular Tags