1 package org.jacorb.test.notification; 2 3 23 24 import java.lang.reflect.Method ; 25 import java.util.Collections ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 29 import junit.framework.Test; 30 import junit.framework.TestCase; 31 import junit.framework.TestSuite; 32 33 import org.jacorb.notification.util.CollectionsWrapper; 34 35 38 39 public class CollectionsWrapperTest extends TestCase 40 { 41 public void _testTime() throws Exception 42 { 43 List [] list = new List [1000]; 44 45 for (int x = 0; x < list.length; ++x) 46 { 47 list[x] = Collections.singletonList("testling"); 48 } 49 50 Method method = Collections .class.getMethod("singletonList", new Class [] { Object .class }); 51 52 for (int x = 0; x < list.length; ++x) 53 { 54 list[x] = (List ) method.invoke(null, new Object [] { "testling" }); 55 } 56 } 57 58 public void testCollectionsWrapper() throws Exception 59 { 60 String o = "testling"; 61 62 List list = CollectionsWrapper.singletonList(o); 63 64 assertTrue(list.size() == 1); 65 66 assertEquals(o, list.get(0)); 67 68 Iterator i = list.iterator(); 69 70 while (i.hasNext()) 71 { 72 assertEquals(o, i.next()); 73 } 74 } 75 76 public void testModificationsFail() throws Exception 77 { 78 String o = "testling"; 79 80 List list = CollectionsWrapper.singletonList(o); 81 82 try 83 { 84 list.add("another"); 85 fail(); 86 } catch (UnsupportedOperationException e) 87 { 88 } 90 91 try { 92 list.remove(0); 93 fail(); 94 } catch (UnsupportedOperationException e) 95 { 96 } 98 } 99 100 public CollectionsWrapperTest(String name) 101 { 102 super(name); 103 } 104 105 public static Test suite() 106 { 107 TestSuite suite = new TestSuite(CollectionsWrapperTest.class); 108 109 return suite; 110 } 111 } | Popular Tags |