KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > eaio > nativecall > HolderTest


1 /*
2  * HolderTest.java
3  *
4  * Created on 05.01.2006.
5  *
6  * eaio: NativeCall - calling operating system methods from Java
7  * Copyright (c) 2004-2006 Johann Burkard (<mailto:jb@eaio.com>)
8  * <http://eaio.com>
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a
11  * copy of this software and associated documentation files (the "Software"),
12  * to deal in the Software without restriction, including without limitation
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  * and/or sell copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included
18  * in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
23  * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
24  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
26  * USE OR OTHER DEALINGS IN THE SOFTWARE.
27  *
28  */

29 package com.eaio.nativecall;
30
31 import java.util.HashSet JavaDoc;
32
33 import junit.framework.TestCase;
34
35 /**
36  * Test case for the {@link com.eaio.nativecall.Holder} class.
37  *
38  * @author <a HREF="mailto:jb@eaio.com">Johann Burkard</a>
39  * @version $Id: HolderTest.java,v 1.2 2006/04/19 20:54:58 grnull Exp $
40  */

41 public class HolderTest extends TestCase {
42
43     /**
44      * Constructor for HolderTest.
45      * @param arg0
46      */

47     public HolderTest(String JavaDoc arg0) {
48         super(arg0);
49     }
50
51     public static void main(String JavaDoc[] args) {
52         junit.awtui.TestRunner.run(HolderTest.class);
53     }
54
55     public void testHolder() {
56         try {
57             new Holder(new Holder(null));
58             fail("Did not throw ClassCastException");
59         }
60         catch (ClassCastException JavaDoc ex) {}
61     }
62
63     public void testHashCode() {
64         Holder h1 = new Holder(new Integer JavaDoc(10));
65         assertEquals(-7460404, h1.hashCode());
66         Holder h2 = new Holder(new Integer JavaDoc(10));
67         assertEquals(h1.hashCode(), h2.hashCode());
68
69         HashSet JavaDoc set = new HashSet JavaDoc();
70         set.add(h1);
71         set.add(h2);
72         assertEquals(1, set.size());
73     }
74
75     public void testGet() {
76         Integer JavaDoc i = new Integer JavaDoc(20);
77         Holder h = new Holder(i);
78         assertTrue(i == h.get());
79     }
80
81     /*
82      * Test for boolean equals(Object)
83      */

84     public void testEqualsObject() {
85         Integer JavaDoc i = new Integer JavaDoc(42);
86         Holder h1 = new Holder(i);
87         Holder h2 = new Holder(i);
88         assertEquals(h1, h2);
89         assertFalse(h1.equals(null));
90         assertEquals(h1, h1);
91         assertFalse(h1.equals(new Holder(new Integer JavaDoc(0))));
92     }
93
94 }
95
Popular Tags