KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > util > misc > SetUtilTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.management.util.misc;
24
25 import java.util.Set JavaDoc;
26
27 import com.sun.appserv.management.util.misc.SetUtil;
28
29 public final class SetUtilTest extends junit.framework.TestCase
30 {
31         public
32     SetUtilTest()
33     {
34     }
35     
36     
37     private static final String JavaDoc S1 = "hello";
38     private static final String JavaDoc S2 = "there";
39     private static final String JavaDoc S3 = "how";
40     private static final String JavaDoc S4 = "are";
41     
42         public void
43     testMultiNew()
44     {
45         Set JavaDoc<String JavaDoc> s;
46         
47         s = SetUtil.newSingletonSet( S1 );
48         assertEquals( S1, s.iterator().next() );
49         
50         s = SetUtil.newSet( S1, S2 );
51         assert(s.contains( S1 ) );
52         assert(s.contains( S2 ) );
53         
54         s = SetUtil.newSet( S1, S2, S3 );
55         assert(s.contains( S1 ) );
56         assert(s.contains( S2 ) );
57         assert(s.contains( S3 ) );
58         
59         s = SetUtil.newSet( S1, S2, S3, S4 );
60         assert(s.contains( S1 ) );
61         assert(s.contains( S2 ) );
62         assert(s.contains( S3 ) );
63         assert(s.contains( S4 ) );
64         
65         final Set JavaDoc<String JavaDoc> strings = s;
66         final Set JavaDoc<Integer JavaDoc> integers = SetUtil.newSingletonSet( new Integer JavaDoc(3) );
67         
68         final Set JavaDoc<?> both = SetUtil.newSet( strings, integers );
69     }
70     
71
72         public void
73     testCopy()
74     {
75         final Set JavaDoc<String JavaDoc> s = SetUtil.newSingletonSet( S1 );
76         final Set JavaDoc<String JavaDoc> sCopy = SetUtil.copySet( s );
77         assertEquals( s, sCopy );
78         assertEquals( sCopy, s );
79         assertEquals( S1, SetUtil.getSingleton( s ) );
80         assertEquals( S1, SetUtil.getSingleton( sCopy ) );
81     }
82     
83       public void
84     testGetSingleton()
85     {
86         final Set JavaDoc<String JavaDoc> s = SetUtil.newSingletonSet( S1 );
87         
88         assertEquals( S1, SetUtil.getSingleton( s ) );
89         
90         s.add( S2 );
91         try
92         {
93             SetUtil.getSingleton( s );
94             fail( "expecting exception" );
95         }
96         catch (IllegalArgumentException JavaDoc e)
97         {
98         }
99     }
100     
101     
102 }
103
104
105
106
107
108
109
Popular Tags