1 19 package org.netbeans.modules.java.editor.semantic; 20 21 import java.util.Collection ; 22 import javax.swing.text.Document ; 23 import javax.swing.text.StyledDocument ; 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 36 public class MarkOccurencesDetectorTest extends TestBase { 37 38 public MarkOccurencesDetectorTest(String 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 { 47 performTest("ExitPoints", 7, 12); 48 } 49 50 public void testExitPointForReturnTypesInt() throws Exception { 51 performTest("ExitPoints", 17, 12); 52 } 53 54 public void testExitPointForReturnTypesObject() throws Exception { 55 performTest("ExitPoints", 27, 12); 56 } 57 58 public void testExitPointForReturnTypesVoidForMethodThrowingException() throws Exception { 59 performTest("ExitPoints", 37, 12); 60 } 61 62 public void testExitPointForThrowsNPE() throws Exception { 63 performTest("ExitPoints", 37, 45); 64 } 65 66 public void testExitPointForThrowsBLE() throws Exception { 67 performTest("ExitPoints", 37, 85); 68 } 69 70 public void testExitPointStartedMethod() throws Exception { 71 performTest("ExitPointsStartedMethod", 5, 13); 72 } 73 74 public void testExitPointEmptyMethod() throws Exception { 75 performTest("ExitPointsEmptyMethod", 5, 13); 76 } 77 78 public void testConstructorThrows() throws Exception { 79 performTest("ExitPoints", 88, 90, true); 80 } 81 82 public void testUsagesField1() throws Exception { 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 { 90 performTest("Usages", 6, 18); 91 } 92 93 public void testUsagesField3() throws Exception { 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 { 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 { 108 performTest("Usages", 18, 19); 109 performTest("Usages", 21, 14); 110 } 111 112 public void testUsagesMethodTrivial() throws Exception { 113 performTest("Usages", 9, 20); 114 performTest("Usages", 29, 11); 115 } 116 117 public void testUsagesClassTrivial() throws Exception { 118 performTest("Usages", 4, 17); 119 performTest("Usages", 31, 12); 120 } 121 122 public void testMemberSelect1() throws Exception { 123 performTest("MemberSelect", 2, 29); 124 performTest("MemberSelect", 6, 70); 125 performTest("MemberSelect", 7, 30); 126 } 127 128 public void testMemberSelect2() throws Exception { 129 performTest("MemberSelect", 14, 33); 130 } 131 132 public void testMemberSelect3() throws Exception { 133 performTest("MemberSelect", 13, 30); 134 } 135 136 public void testSimpleFallThroughExitPoint() throws Exception { 137 performTest("MethodFallThroughExitPoints", 4, 13); 138 } 139 140 public void testFallThroughExitPointWithIf() throws Exception { 141 performTest("MethodFallThroughExitPoints", 7, 13); 142 } 143 144 public void testNotFallThroughIfWithElse() throws Exception { 145 performTest("MethodFallThroughExitPoints", 12, 13); 146 } 147 148 public void testFallThroughExitPointWithTryCatch() throws Exception { 149 performTest("MethodFallThroughExitPoints", 19, 13); 150 } 151 152 public void testNotFallThroughTryCatchWithReturns() throws Exception { 153 performTest("MethodFallThroughExitPoints", 28, 13); 154 } 155 156 public void testNotFallThroughFinallyWithReturn() throws Exception { 157 performTest("MethodFallThroughExitPoints", 38, 13); 158 } 159 160 public void testNotFallThroughThrow() throws Exception { 161 performTest("MethodFallThroughExitPoints", 46, 13); 162 } 163 164 private void performTest(String name, final int line, final int column) throws Exception { 165 performTest(name, line, column, false); 166 } 167 168 private void performTest(String name, final int line, final int column, boolean doCompileRecursively) throws Exception { 169 performTest(name, new Performer() { 170 public Collection <Highlight> compute(CompilationController info, Document doc) { 171 int offset = NbDocument.findLineOffset((StyledDocument ) doc, line) + column; 172 173 return new MarkOccurencesHighlighter(null).processImpl(info, doc, offset); 174 } 175 }, doCompileRecursively); 176 } 177 178 } 179 | Popular Tags |