KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > hints > CreatorBasedLazyFixListTest


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.java.hints;
20
21 import com.sun.source.util.TreePath;
22 import java.util.Collections JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Set JavaDoc;
26 import org.netbeans.api.java.source.CompilationInfo;
27 import org.netbeans.modules.java.hints.spi.ErrorRule;
28 import org.netbeans.modules.java.hints.spi.ErrorRule.Data;
29 import org.netbeans.spi.editor.hints.Fix;
30
31 /**
32  *
33  * @author Jan Lahoda
34  */

35 public class CreatorBasedLazyFixListTest extends JavaHintsTestBase {
36     
37     public CreatorBasedLazyFixListTest(String JavaDoc testName) {
38         super(testName);
39     }
40     
41     protected void setUp() throws Exception JavaDoc {
42         super.setUp();
43     }
44
45     protected void tearDown() throws Exception JavaDoc {
46         super.tearDown();
47     }
48
49     public void testCancel() throws Exception JavaDoc {
50         prepareTest("Simple");
51         
52         final int[] calledCount = new int[1];
53         final boolean[] cancel = new boolean[1];
54         final CreatorBasedLazyFixList[] list = new CreatorBasedLazyFixList[1];
55         
56         list[0] = new CreatorBasedLazyFixList(null, "", 0, Collections.singleton((ErrorRule) new ErrorRule() {
57             public Set JavaDoc getCodes() {
58                 throw new UnsupportedOperationException JavaDoc("Not supported yet.");
59             }
60             
61             public List JavaDoc<Fix> run(CompilationInfo compilationInfo,
62                     String JavaDoc diagnosticKey, int offset, TreePath treePath,
63                     Data data) {
64                 calledCount[0]++;
65                 if (cancel[0]) {
66                     list[0].cancel();
67                 }
68                 
69                 return Collections.<Fix>emptyList();
70             }
71             
72             public void cancel() {
73                 //expected&ignored for now.
74
}
75             
76             public String JavaDoc getId() {
77                 throw new UnsupportedOperationException JavaDoc("Not supported yet.");
78             }
79             
80             public String JavaDoc getDisplayName() {
81                 throw new UnsupportedOperationException JavaDoc("Not supported yet.");
82             }
83             
84             public String JavaDoc getDescription() {
85                 throw new UnsupportedOperationException JavaDoc("Not supported yet.");
86             }
87         }), new HashMap JavaDoc<Class JavaDoc, Data>());
88         
89         cancel[0] = true;
90         
91         list[0].compute(info);
92         
93         assertEquals(1, calledCount[0]);
94         
95         list[0].compute(info);
96         
97         assertEquals(2, calledCount[0]);
98         
99         cancel[0] = false;
100         
101         list[0].compute(info);
102         
103         assertEquals(3, calledCount[0]);
104         
105         list[0].compute(info);
106         
107         assertEquals(3, calledCount[0]);
108     }
109
110     @Override JavaDoc
111     protected String JavaDoc testDataExtension() {
112         return "org/netbeans/test/java/hints/";
113     }
114     
115     @Override JavaDoc
116     protected boolean createCaches() {
117         return false;
118     }
119     
120 }
121
Popular Tags