1 package org.apache.commons.configuration; 2 3 import java.util.List ; 4 import java.util.Iterator ; 5 6 import junit.framework.TestCase; 7 8 12 public class TestPropertyConverter extends TestCase 13 { 14 public void testSplit() 15 { 16 String s = "abc, xyz , 123"; 17 List 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 s = "abc\\,xyz, 123"; 28 List 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 s = ",,"; 38 List 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 s = "abc, xyz\\"; 49 List 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 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 it = PropertyConverter.toIterator(array, ','); 68 69 assertEquals("1st element", new Integer (1), it.next()); 70 assertEquals("2nd element", new Integer (2), it.next()); 71 assertEquals("3rd element", new Integer (3), it.next()); 72 } 73 74 } 75 | Popular Tags |