1 15 package org.apache.hivemind.service.impl; 16 17 import org.apache.hivemind.service.ClassFactory; 18 import org.apache.hivemind.service.InterfaceFab; 19 import org.apache.hivemind.service.MethodSignature; 20 import org.apache.hivemind.test.HiveMindTestCase; 21 import org.apache.hivemind.test.TypeMatcher; 22 import org.easymock.MockControl; 23 24 27 public class TestInterfaceSynthesizer extends HiveMindTestCase 28 { 29 private ClassFactory newClassFactory(InterfaceFab fab) 30 { 31 MockControl control = newControl(ClassFactory.class); 32 ClassFactory cf = (ClassFactory) control.getMock(); 33 34 cf.newInterface("UNKNOWN"); 35 control.setMatcher(new TypeMatcher()); 36 control.setReturnValue(fab); 37 38 return cf; 39 } 40 41 public void testSimple() 42 { 43 MockControl control = newControl(InterfaceFab.class); 44 InterfaceFab fab = (InterfaceFab) control.getMock(); 45 46 ClassFactory cf = newClassFactory(fab); 47 48 fab.addMethod(new MethodSignature(void.class, "doStuff", null, null)); 49 50 fab.createInterface(); 51 control.setReturnValue(null); 52 53 replayControls(); 54 55 InterfaceSynthesizerImpl is = new InterfaceSynthesizerImpl(); 56 is.setClassFactory(cf); 57 58 is.synthesizeInterface(SimpleBean.class); 59 60 verifyControls(); 61 } 62 63 public void testExtendingInterface() 64 { 65 MockControl control = newControl(InterfaceFab.class); 66 InterfaceFab fab = (InterfaceFab) control.getMock(); 67 68 ClassFactory cf = newClassFactory(fab); 69 70 fab.addInterface(BeanInterface.class); 71 fab.addMethod(new MethodSignature(String .class, "beanMethod", null, null)); 72 73 fab.createInterface(); 74 control.setReturnValue(null); 75 76 replayControls(); 77 78 InterfaceSynthesizerImpl is = new InterfaceSynthesizerImpl(); 79 is.setClassFactory(cf); 80 81 is.synthesizeInterface(ExtendingInterfaceBean.class); 82 83 verifyControls(); 84 } 85 86 public void testExtendingSubInterface() 87 { 88 92 MockControl control = MockControl.createNiceControl(InterfaceFab.class); 93 addControl(control); 94 95 InterfaceFab fab = (InterfaceFab) control.getMock(); 96 97 ClassFactory cf = newClassFactory(fab); 98 99 fab.addInterface(BeanInterface.class); 100 fab.addInterface(BeanSubInterface.class); 101 fab.addMethod(new MethodSignature(String .class, "beanMethod", null, null)); 102 103 fab.createInterface(); 104 control.setReturnValue(null); 105 106 replayControls(); 107 108 InterfaceSynthesizerImpl is = new InterfaceSynthesizerImpl(); 109 is.setClassFactory(cf); 110 111 is.synthesizeInterface(ExtendingSubInterfaceBean.class); 112 113 verifyControls(); 114 } 115 116 public void testIgnoreStaticAndPrivateMethods() 117 { 118 MockControl control = newControl(InterfaceFab.class); 119 InterfaceFab fab = (InterfaceFab) control.getMock(); 120 121 ClassFactory cf = newClassFactory(fab); 122 123 fab.addInterface(BeanInterface.class); 124 fab.addMethod(new MethodSignature(String .class, "beanMethod", null, null)); 125 126 fab.createInterface(); 127 control.setReturnValue(null); 128 129 replayControls(); 130 131 InterfaceSynthesizerImpl is = new InterfaceSynthesizerImpl(); 132 is.setClassFactory(cf); 133 134 is.synthesizeInterface(IgnoreStaticAndPrivateMethodsBean.class); 135 136 verifyControls(); 137 } 138 139 } | Popular Tags |