1 15 package org.apache.hivemind.service.impl; 16 17 import java.io.Serializable ; 18 19 import org.apache.hivemind.ApplicationRuntimeException; 20 import org.apache.hivemind.service.ClassFactory; 21 import org.apache.hivemind.service.InterfaceFab; 22 import org.apache.hivemind.service.MethodIterator; 23 import org.apache.hivemind.service.MethodSignature; 24 import org.apache.hivemind.test.HiveMindTestCase; 25 26 32 public class TestInterfaceFab extends HiveMindTestCase 33 { 34 private InterfaceFab newInterface(String name) 35 { 36 ClassFactory cf = new ClassFactoryImpl(); 37 38 return cf.newInterface(name); 39 } 40 41 public void testCreateEmptyInterface() 42 { 43 InterfaceFab fab = newInterface("MyNewInterface"); 44 45 Class ic = fab.createInterface(); 46 47 assertEquals("MyNewInterface", ic.getName()); 48 49 assertEquals(0, ic.getMethods().length); 50 51 assertEquals("InterfaceFabImpl[\npublic interface MyNewInterface\n]", fab.toString()); 52 } 53 54 public void testAddMethod() 55 { 56 InterfaceFab fab = newInterface("InterfaceWithMethods"); 57 58 MethodSignature sig = new MethodSignature(void.class, "doStuff", null, null); 59 60 fab.addMethod(sig); 61 62 Class ic = fab.createInterface(); 63 64 MethodIterator mi = new MethodIterator(ic); 65 66 MethodSignature sig2 = mi.next(); 67 68 assertEquals(sig, sig2); 69 70 assertFalse(mi.hasNext()); 71 72 assertEquals( 73 "InterfaceFabImpl[\npublic interface InterfaceWithMethods\n\npublic void doStuff();\n]", 74 fab.toString()); 75 } 76 77 public void testAddInterface() 78 { 79 InterfaceFab fab = newInterface("ExtendInterface"); 80 81 fab.addInterface(Runnable .class); 82 fab.addInterface(Serializable .class); 83 84 Class ic = fab.createInterface(); 85 86 MethodIterator mi = new MethodIterator(ic); 87 88 MethodSignature sig = mi.next(); 89 90 assertEquals(new MethodSignature(void.class, "run", null, null), sig); 91 92 assertFalse(mi.hasNext()); 93 94 assertEquals( 95 "InterfaceFabImpl[\npublic interface ExtendInterface extends java.lang.Runnable, java.io.Serializable\n]", 96 fab.toString()); 97 } 98 99 public void testDuplicateInterface() 100 { 101 ClassFactory cf = new ClassFactoryImpl(); 102 103 cf.newInterface("DuplicateInterface").createInterface(); 104 105 try 106 { 107 cf.newInterface("DuplicateInterface"); 108 unreachable(); 109 } 110 catch (ApplicationRuntimeException ex) 111 { 112 assertExceptionSubstring(ex, "Unable to create interface DuplicateInterface"); 113 } 114 } 115 116 } 117 118 | Popular Tags |