KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jmi > javamodel > getters > ArgumentMatchesTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  *
19  */

20 package org.netbeans.jmi.javamodel.getters;
21
22 import java.lang.reflect.Modifier JavaDoc;
23 import java.util.Collections JavaDoc;
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 /**
32  *
33  * @author Pavel Flaska
34  */

35 public class ArgumentMatchesTest extends CodegenTestCase {
36
37     /** Need to be defined because of JUnit */
38 /** Creates a new instance of ArgumentMatchesTest */
39     public ArgumentMatchesTest(String JavaDoc 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 JavaDoc 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