1 19 20 package org.openide.util; 21 22 import org.netbeans.junit.NbTestCase; 23 24 27 public class Union2Test extends NbTestCase { 28 29 public Union2Test(String name) { 30 super(name); 31 } 32 33 public void testUnions() throws Exception { 34 Union2<Integer ,String > union = Union2.createFirst(3); 35 assertEquals(3, union.first().intValue()); 36 try { 37 union.second(); 38 fail(); 39 } catch (IllegalArgumentException e) {} 40 assertTrue(union.hasFirst()); 41 assertFalse(union.hasSecond()); 42 assertEquals("3", union.toString()); 43 assertTrue(union.equals(Union2.createFirst(3))); 44 assertFalse(union.equals(Union2.createFirst(4))); 45 assertEquals(union.hashCode(), Union2.createFirst(3).hashCode()); 46 assertEquals(union, NbCollectionsTest.cloneBySerialization(union)); 47 assertEquals(union, union.clone()); 48 int i = union.clone().first(); 49 assertEquals(3, i); 50 union = Union2.createSecond("hello"); 52 try { 53 union.first(); 54 fail(); 55 } catch (IllegalArgumentException e) {} 56 assertEquals("hello", union.second()); 57 assertFalse(union.hasFirst()); 58 assertTrue(union.hasSecond()); 59 assertEquals("hello", union.toString()); 60 assertTrue(union.equals(Union2.createSecond("hello"))); 61 assertFalse(union.equals(Union2.createSecond("there"))); 62 assertEquals(union.hashCode(), Union2.createSecond("hello").hashCode()); 63 assertEquals(union, NbCollectionsTest.cloneBySerialization(union)); 64 assertEquals(union, union.clone()); 65 String s = union.clone().second(); 66 assertEquals("hello", s); 67 } 68 69 } 70 | Popular Tags |