KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > poa > ByteArrayKeyTest


1 package org.jacorb.test.poa;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2001 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import junit.framework.*;
24 import junit.extensions.TestSetup;
25 import org.jacorb.test.common.ORBSetup;
26 import org.jacorb.poa.util.ByteArrayKey;
27
28
29 /**
30  * <code>ByteArrayKeyTest</code> tests JacORB ByteArrayKey class.
31  *
32  * @author <a HREF="mailto:rnc@prismtechnologies.com"></a>
33  * @version 1.0
34  */

35 public class ByteArrayKeyTest extends TestCase
36 {
37     /**
38      * <code>orb</code> is used to obtain the root poa.
39      */

40     private static org.omg.CORBA.ORB JavaDoc orb = null;
41
42
43
44     /**
45      * <code>ByteArrayKeyTest</code> constructor - for JUnit.
46      *
47      * @param name a <code>String</code> value
48      */

49     public ByteArrayKeyTest (String JavaDoc name)
50     {
51         super (name);
52     }
53
54
55     /**
56      * <code>suite</code> lists the tests for Junit to run.
57      *
58      * @return a <code>Test</code> value
59      */

60     public static Test suite ()
61     {
62         TestSuite suite = new TestSuite ("ByteArrayKey Test");
63         Setup setup = new Setup( suite );
64         ORBSetup osetup = new ORBSetup( setup );
65
66         suite.addTest (new ByteArrayKeyTest ("testKey1"));
67         suite.addTest (new ByteArrayKeyTest ("testKey2"));
68
69         return osetup;
70     }
71
72
73     /**
74      * <code>testKey1</code> tests that JacORB can handle a null key.
75      */

76     public void testKey1 ()
77     {
78         ByteArrayKey bk = new ByteArrayKey( (byte[])null );
79
80         try
81         {
82             bk.toString();
83             bk.getBytes();
84             bk.hashCode();
85
86             if( System.identityHashCode( bk.toString() ) !=
87                 System.identityHashCode( bk.toString() ) )
88             {
89                 fail( "Different Strings returned on toString" );
90             }
91         }
92         catch( Exception JavaDoc e )
93         {
94             fail( "Caught exception processing ByteArrayKey" );
95         }
96     }
97
98
99     /**
100      * <code>testKey2</code> does some basic tests.
101      */

102     public void testKey2 ()
103     {
104         ByteArrayKey bk = new ByteArrayKey( ( "bytearraykeytest" ).getBytes() );
105
106         try
107         {
108             bk.toString();
109             bk.getBytes();
110             bk.hashCode();
111
112             if( System.identityHashCode( bk.toString() ) !=
113                 System.identityHashCode( bk.toString() ) )
114             {
115                 fail( "Different Strings returned on toString" );
116             }
117         }
118         catch( Exception JavaDoc e )
119         {
120             fail( "Caught exception processing ByteArrayKey" );
121         }
122     }
123
124
125     /**
126      * <code>Setup</code> is an inner class to initialize the ORB.
127      */

128     private static class Setup extends TestSetup
129     {
130         /**
131          * Creates a new <code>Setup</code> instance.
132          *
133          * @param test a <code>Test</code> value
134          */

135         public Setup (Test test)
136         {
137             super (test);
138         }
139
140         /**
141          * <code>setUp</code> sets the orb variable.
142          */

143         protected void setUp ()
144         {
145             org.omg.CORBA.Object JavaDoc obj = null;
146
147             orb = ORBSetup.getORB ();
148         }
149
150         /**
151          * <code>tearDown</code> does nothing for this test.
152          */

153         protected void tearDown ()
154         {
155         }
156     }
157 }
158
Popular Tags