1 20 package org.netbeans.jmi.javamodel.getters; 21 22 import java.lang.reflect.Modifier ; 23 import java.util.Collections ; 24 import org.netbeans.jmi.javamodel.JavaClass; 25 import org.netbeans.jmi.javamodel.JavaModelPackage; 26 import org.netbeans.jmi.javamodel.Method; 27 import org.netbeans.jmi.javamodel.codegen.CodegenTestCase; 28 import org.netbeans.jmi.javamodel.codegen.Utility; 29 import org.netbeans.junit.NbTestSuite; 30 31 35 public class ArgumentMatchesTest extends CodegenTestCase { 36 37 38 39 public ArgumentMatchesTest(String name) { 40 super(name, "ArgumentMatchesTest"); 41 } 42 43 public static NbTestSuite suite() { 44 NbTestSuite suite = new NbTestSuite(); 45 suite.addTest(new ArgumentMatchesTest("testFindSetterForGetter")); 46 return suite; 47 } 48 49 JavaClass clazz; 50 JavaModelPackage pkg; 51 Method getterMethod; 52 Method setterMethod; 53 54 protected void setUp() { 55 clazz = Utility.findClass("org.netbeans.test.getters.ArgumentMatches"); 56 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 57 getterMethod = (Method) clazz.getContents().get(1); 58 setterMethod = (Method) clazz.getContents().get(2); 59 } 60 61 public void testFindSetterForGetter() { 62 boolean fail = true; 63 Utility.beginTrans(false); 64 try { 65 final String setterName = "setEmployees"; 66 Method setterFound = getterMethod.getDeclaringClass().getMethod( 67 setterName, 68 Collections.singletonList(getterMethod.getType()), 69 true); 70 71 if (setterFound != null) { 72 if (!"void".equals(setterFound.getType().getName()) || Modifier.isStatic(setterFound.getModifiers())) { 73 setterFound = null; 74 } 75 } 76 assertEquals(setterFound, setterMethod); 77 } finally { 78 Utility.endTrans(); 79 } 80 } 81 82 } 83 | Popular Tags |