KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > CollectionsWrapperTest


1 package org.jacorb.test.notification;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1999-2003 Gerald Brose
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  */

23
24 import java.lang.reflect.Method JavaDoc;
25 import java.util.Collections JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
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 /**
36  * @author Alphonse Bendt
37  */

38
39 public class CollectionsWrapperTest extends TestCase
40 {
41     public void _testTime() throws Exception JavaDoc
42     {
43         List JavaDoc[] list = new List JavaDoc[1000];
44
45         for (int x = 0; x < list.length; ++x)
46         {
47             list[x] = Collections.singletonList("testling");
48         }
49
50         Method JavaDoc method = Collections JavaDoc.class.getMethod("singletonList", new Class JavaDoc[] { Object JavaDoc.class });
51
52         for (int x = 0; x < list.length; ++x)
53         {
54             list[x] = (List JavaDoc) method.invoke(null, new Object JavaDoc[] { "testling" });
55         }
56     }
57
58     public void testCollectionsWrapper() throws Exception JavaDoc
59     {
60         String JavaDoc o = "testling";
61
62         List JavaDoc list = CollectionsWrapper.singletonList(o);
63
64         assertTrue(list.size() == 1);
65
66         assertEquals(o, list.get(0));
67
68         Iterator JavaDoc i = list.iterator();
69
70         while (i.hasNext())
71         {
72             assertEquals(o, i.next());
73         }
74     }
75
76     public void testModificationsFail() throws Exception JavaDoc
77     {
78         String JavaDoc o = "testling";
79
80         List JavaDoc list = CollectionsWrapper.singletonList(o);
81         
82         try
83         {
84             list.add("another");
85             fail();
86         } catch (UnsupportedOperationException JavaDoc e)
87         {
88             // expected
89
}
90         
91         try {
92             list.remove(0);
93             fail();
94         } catch (UnsupportedOperationException JavaDoc e)
95         {
96             // expected
97
}
98     }
99
100     public CollectionsWrapperTest(String JavaDoc 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