1 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 32 public class RoleEntryTestCase extends TestCase 33 { 34 public RoleEntryTestCase( String name ) 35 { 36 super( name ); 37 } 38 39 public void testRoleEntry() 40 { 41 String role = Role1.class.getName(); 42 String name = "component1"; 43 Class componentClass = Component1.class; 44 Class 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 role = Role1.class.getName(); 63 String name = "component1"; 64 Class componentClass = Component1.class; 65 Class 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 npe ) 73 { 74 } 76 catch ( Exception 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 npe ) 87 { 88 } 90 catch ( Exception 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 npe ) 101 { 102 } 104 catch ( Exception 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 npe ) 115 { 116 } 118 catch ( Exception e ) 119 { 120 fail( "threw the wrong exception: " + e.getClass().getName() ); 121 } 122 } 123 } 124 | Popular Tags |