KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > editor > semantic > MarkOccurencesDetectorTest


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 package org.netbeans.modules.java.editor.semantic;
20
21 import java.util.Collection JavaDoc;
22 import javax.swing.text.Document JavaDoc;
23 import javax.swing.text.StyledDocument JavaDoc;
24 import junit.framework.Test;
25 import junit.framework.TestSuite;
26 import org.netbeans.api.java.source.CompilationController;
27 import org.netbeans.api.java.source.test.support.MemoryValidator;
28 import org.netbeans.modules.editor.highlights.spi.Highlight;
29 import org.netbeans.modules.java.editor.semantic.TestBase.Performer;
30 import org.openide.text.NbDocument;
31
32 /**XXX: constructors throwing an exception are not marked as exit points
33  *
34  * @author Jan Lahoda
35  */

36 public class MarkOccurencesDetectorTest extends TestBase {
37     
38     public MarkOccurencesDetectorTest(String JavaDoc testName) {
39         super(testName);
40     }
41
42     public static Test suite() {
43         return MemoryValidator.wrap(new TestSuite(MarkOccurencesDetectorTest.class));
44     }
45     
46     public void testExitPointForReturnTypesVoid() throws Exception JavaDoc {
47         performTest("ExitPoints", 7, 12);
48     }
49     
50     public void testExitPointForReturnTypesInt() throws Exception JavaDoc {
51         performTest("ExitPoints", 17, 12);
52     }
53     
54     public void testExitPointForReturnTypesObject() throws Exception JavaDoc {
55         performTest("ExitPoints", 27, 12);
56     }
57     
58     public void testExitPointForReturnTypesVoidForMethodThrowingException() throws Exception JavaDoc {
59         performTest("ExitPoints", 37, 12);
60     }
61     
62     public void testExitPointForThrowsNPE() throws Exception JavaDoc {
63         performTest("ExitPoints", 37, 45);
64     }
65     
66     public void testExitPointForThrowsBLE() throws Exception JavaDoc {
67         performTest("ExitPoints", 37, 85);
68     }
69     
70     public void testExitPointStartedMethod() throws Exception JavaDoc {
71         performTest("ExitPointsStartedMethod", 5, 13);
72     }
73     
74     public void testExitPointEmptyMethod() throws Exception JavaDoc {
75         performTest("ExitPointsEmptyMethod", 5, 13);
76     }
77     
78     public void testConstructorThrows() throws Exception JavaDoc {
79         performTest("ExitPoints", 88, 90, true);
80     }
81     
82     public void testUsagesField1() throws Exception JavaDoc {
83         performTest("Usages", 7, 19);
84         performTest("Usages", 14, 10);
85         performTest("Usages", 17, 17);
86         performTest("Usages", 26, 10);
87     }
88     
89     public void testUsagesField2() throws Exception JavaDoc {
90         performTest("Usages", 6, 18);
91     }
92     
93     public void testUsagesField3() throws Exception JavaDoc {
94         performTest("Usages", 10, 14);
95         performTest("Usages", 13, 9);
96         performTest("Usages", 20, 13);
97         performTest("Usages", 25, 9);
98     }
99     
100     public void testUsagesField4() throws Exception JavaDoc {
101         performTest("Usages", 11, 16);
102         performTest("Usages", 15, 10);
103         performTest("Usages", 22, 14);
104         performTest("Usages", 27, 10);
105     }
106     
107     public void testUsagesField5() throws Exception JavaDoc {
108         performTest("Usages", 18, 19);
109         performTest("Usages", 21, 14);
110     }
111     
112     public void testUsagesMethodTrivial() throws Exception JavaDoc {
113         performTest("Usages", 9, 20);
114         performTest("Usages", 29, 11);
115     }
116     
117     public void testUsagesClassTrivial() throws Exception JavaDoc {
118         performTest("Usages", 4, 17);
119         performTest("Usages", 31, 12);
120     }
121     
122     public void testMemberSelect1() throws Exception JavaDoc {
123         performTest("MemberSelect", 2, 29);
124         performTest("MemberSelect", 6, 70);
125         performTest("MemberSelect", 7, 30);
126     }
127     
128     public void testMemberSelect2() throws Exception JavaDoc {
129         performTest("MemberSelect", 14, 33);
130     }
131     
132     public void testMemberSelect3() throws Exception JavaDoc {
133         performTest("MemberSelect", 13, 30);
134     }
135     
136     public void testSimpleFallThroughExitPoint() throws Exception JavaDoc {
137         performTest("MethodFallThroughExitPoints", 4, 13);
138     }
139     
140     public void testFallThroughExitPointWithIf() throws Exception JavaDoc {
141         performTest("MethodFallThroughExitPoints", 7, 13);
142     }
143     
144     public void testNotFallThroughIfWithElse() throws Exception JavaDoc {
145         performTest("MethodFallThroughExitPoints", 12, 13);
146     }
147     
148     public void testFallThroughExitPointWithTryCatch() throws Exception JavaDoc {
149         performTest("MethodFallThroughExitPoints", 19, 13);
150     }
151     
152     public void testNotFallThroughTryCatchWithReturns() throws Exception JavaDoc {
153         performTest("MethodFallThroughExitPoints", 28, 13);
154     }
155     
156     public void testNotFallThroughFinallyWithReturn() throws Exception JavaDoc {
157         performTest("MethodFallThroughExitPoints", 38, 13);
158     }
159     
160     public void testNotFallThroughThrow() throws Exception JavaDoc {
161         performTest("MethodFallThroughExitPoints", 46, 13);
162     }
163     
164     private void performTest(String JavaDoc name, final int line, final int column) throws Exception JavaDoc {
165         performTest(name, line, column, false);
166     }
167     
168     private void performTest(String JavaDoc name, final int line, final int column, boolean doCompileRecursively) throws Exception JavaDoc {
169         performTest(name, new Performer() {
170             public Collection JavaDoc<Highlight> compute(CompilationController info, Document JavaDoc doc) {
171                 int offset = NbDocument.findLineOffset((StyledDocument JavaDoc) doc, line) + column;
172                 
173                 return new MarkOccurencesHighlighter(null).processImpl(info, doc, offset);
174             }
175         }, doCompileRecursively);
176     }
177     
178 }
179
Popular Tags