KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > fortress > test > RoleEntryTestCase


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.avalon.fortress.test;
19
20 import junit.framework.TestCase;
21 import org.apache.avalon.fortress.RoleEntry;
22 import org.apache.avalon.fortress.impl.handler.ThreadSafeComponentHandler;
23 import org.apache.avalon.fortress.test.data.Component1;
24 import org.apache.avalon.fortress.test.data.Role1;
25
26 /**
27  * RoleEntryTestCase tests the RoleEntry class.
28  *
29  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
30  * @version CVS $ Revision: 1.1 $
31  */

32 public class RoleEntryTestCase extends TestCase
33 {
34     public RoleEntryTestCase( String JavaDoc name )
35     {
36         super( name );
37     }
38
39     public void testRoleEntry()
40     {
41         String JavaDoc role = Role1.class.getName();
42         String JavaDoc name = "component1";
43         Class JavaDoc componentClass = Component1.class;
44         Class JavaDoc handlerClass = ThreadSafeComponentHandler.class;
45
46         RoleEntry entry = new RoleEntry( role, name, componentClass, handlerClass );
47
48         assertNotNull( entry );
49         assertNotNull( entry.getRole() );
50         assertNotNull( entry.getShortname() );
51         assertNotNull( entry.getComponentClass() );
52         assertNotNull( entry.getHandlerClass() );
53
54         assertEquals( role, entry.getRole() );
55         assertEquals( name, entry.getShortname() );
56         assertEquals( componentClass, entry.getComponentClass() );
57         assertEquals( handlerClass, entry.getHandlerClass() );
58     }
59
60     public void testNullPointerExceptions()
61     {
62         String JavaDoc role = Role1.class.getName();
63         String JavaDoc name = "component1";
64         Class JavaDoc componentClass = Component1.class;
65         Class JavaDoc handlerClass = ThreadSafeComponentHandler.class;
66
67         try
68         {
69             new RoleEntry( null, name, componentClass, handlerClass );
70             fail( "Did not throw an exception" );
71         }
72         catch ( NullPointerException JavaDoc npe )
73         {
74             // SUCCESS!
75
}
76         catch ( Exception JavaDoc e )
77         {
78             fail( "threw the wrong exception: " + e.getClass().getName() );
79         }
80
81         try
82         {
83             new RoleEntry( role, null, componentClass, handlerClass );
84             fail( "Did not throw an exception" );
85         }
86         catch ( NullPointerException JavaDoc npe )
87         {
88             // SUCCESS!
89
}
90         catch ( Exception JavaDoc e )
91         {
92             fail( "threw the wrong exception: " + e.getClass().getName() );
93         }
94
95         try
96         {
97             new RoleEntry( role, name, null, handlerClass );
98             fail( "Did not throw an exception" );
99         }
100         catch ( NullPointerException JavaDoc npe )
101         {
102             // SUCCESS!
103
}
104         catch ( Exception JavaDoc e )
105         {
106             fail( "threw the wrong exception: " + e.getClass().getName() );
107         }
108
109         try
110         {
111             new RoleEntry( role, name, componentClass, null );
112             fail( "Did not throw an exception" );
113         }
114         catch ( NullPointerException JavaDoc npe )
115         {
116             // SUCCESS!
117
}
118         catch ( Exception JavaDoc e )
119         {
120             fail( "threw the wrong exception: " + e.getClass().getName() );
121         }
122     }
123 }
124
Popular Tags