KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > util > Union2Test


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.openide.util;
21
22 import org.netbeans.junit.NbTestCase;
23
24 /**
25  * @author Jesse Glick
26  */

27 public class Union2Test extends NbTestCase {
28
29     public Union2Test(String JavaDoc name) {
30         super(name);
31     }
32
33     public void testUnions() throws Exception JavaDoc {
34         Union2<Integer JavaDoc,String JavaDoc> union = Union2.createFirst(3);
35         assertEquals(3, union.first().intValue());
36         try {
37             union.second();
38             fail();
39         } catch (IllegalArgumentException JavaDoc e) {/*OK*/}
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         // Second type now.
51
union = Union2.createSecond("hello");
52         try {
53             union.first();
54             fail();
55         } catch (IllegalArgumentException JavaDoc e) {/*OK*/}
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 JavaDoc s = union.clone().second();
66         assertEquals("hello", s);
67     }
68
69 }
70
Popular Tags