1 23 package com.sun.enterprise.management.util.misc; 24 25 import java.util.Set ; 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 S1 = "hello"; 38 private static final String S2 = "there"; 39 private static final String S3 = "how"; 40 private static final String S4 = "are"; 41 42 public void 43 testMultiNew() 44 { 45 Set <String > 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 <String > strings = s; 66 final Set <Integer > integers = SetUtil.newSingletonSet( new Integer (3) ); 67 68 final Set <?> both = SetUtil.newSet( strings, integers ); 69 } 70 71 72 public void 73 testCopy() 74 { 75 final Set <String > s = SetUtil.newSingletonSet( S1 ); 76 final Set <String > 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 <String > 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 e) 97 { 98 } 99 } 100 101 102 } 103 104 105 106 107 108 109 | Popular Tags |