Added
Link Here
|
1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 |
* |
4 |
* Copyright 2012 Oracle and/or its affiliates. All rights reserved. |
5 |
* |
6 |
* Oracle and Java are registered trademarks of Oracle and/or its affiliates. |
7 |
* Other names may be trademarks of their respective owners. |
8 |
* |
9 |
* The contents of this file are subject to the terms of either the GNU |
10 |
* General Public License Version 2 only ("GPL") or the Common |
11 |
* Development and Distribution License("CDDL") (collectively, the |
12 |
* "License"). You may not use this file except in compliance with the |
13 |
* License. You can obtain a copy of the License at |
14 |
* http://www.netbeans.org/cddl-gplv2.html |
15 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the |
16 |
* specific language governing permissions and limitations under the |
17 |
* License. When distributing the software, include this License Header |
18 |
* Notice in each file and include the License file at |
19 |
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this |
20 |
* particular file as subject to the "Classpath" exception as provided |
21 |
* by Oracle in the GPL Version 2 section of the License file that |
22 |
* accompanied this code. If applicable, add the following below the |
23 |
* License Header, with the fields enclosed by brackets [] replaced by |
24 |
* your own identifying information: |
25 |
* "Portions Copyrighted [year] [name of copyright owner]" |
26 |
* |
27 |
* If you wish your version of this file to be governed by only the CDDL |
28 |
* or only the GPL Version 2, indicate your decision by adding |
29 |
* "[Contributor] elects to include this software in this distribution |
30 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a |
31 |
* single choice of license, a recipient has the option to distribute |
32 |
* your version of this file under either the CDDL, the GPL Version 2 or |
33 |
* to extend the choice of license to its licensees as provided above. |
34 |
* However, if you add GPL Version 2 code and therefore, elected the GPL |
35 |
* Version 2 license, then the option applies only if the new code is |
36 |
* made subject to such option by the copyright holder. |
37 |
* |
38 |
* Contributor(s): |
39 |
* |
40 |
* Portions Copyrighted 2012 Oracle |
41 |
* Portions Copyrighted 2012 markiewb@netbeans.org |
42 |
*/ |
43 |
package org.netbeans.modules.debugger.jpda.projects; |
44 |
|
45 |
import org.junit.After; |
46 |
import org.junit.AfterClass; |
47 |
import org.junit.BeforeClass; |
48 |
import org.junit.Test; |
49 |
import static org.junit.Assert.*; |
50 |
import org.junit.Before; |
51 |
import org.netbeans.api.debugger.Breakpoint; |
52 |
import org.netbeans.api.debugger.jpda.FieldBreakpoint; |
53 |
import org.netbeans.api.debugger.jpda.LineBreakpoint; |
54 |
import org.netbeans.api.debugger.jpda.MethodBreakpoint; |
55 |
import org.netbeans.spi.debugger.jpda.EditorContext; |
56 |
import org.openide.text.Line; |
57 |
import org.openide.util.Lookup; |
58 |
|
59 |
/** |
60 |
* |
61 |
* @author markiewb@netbeans.org |
62 |
*/ |
63 |
public class DebuggerBreakpointAnnotationTest { |
64 |
|
65 |
private LineBreakpoint breakpoint; |
66 |
|
67 |
@Before |
68 |
public void setUp () { |
69 |
//FIXME next line will throw nasty java.net.MalformedURLException in the log |
70 |
breakpoint = LineBreakpoint.create("java.util.ArrayList", 2); |
71 |
} |
72 |
|
73 |
@Test |
74 |
public void testGetShortDescription_Condition_None () { |
75 |
DebuggerBreakpointAnnotation sut = new DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE), new LineMock(), breakpoint); |
76 |
assertEquals("Conditional Breakpoint", sut.getShortDescription()); |
77 |
} |
78 |
|
79 |
@Test |
80 |
public void testGetShortDescription_Condition_HitCount_Equal () { |
81 |
DebuggerBreakpointAnnotation sut = new DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE), new LineMock(), breakpoint); |
82 |
breakpoint.setHitCountFilter(42, Breakpoint.HIT_COUNT_FILTERING_STYLE.EQUAL); |
83 |
|
84 |
assertEquals("Conditional Breakpoint\n\nHit count: = 42", sut.getShortDescription()); |
85 |
} |
86 |
|
87 |
@Test |
88 |
public void testGetShortDescription_Condition_HitCount_Greater () { |
89 |
DebuggerBreakpointAnnotation sut = new DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE), new LineMock(), breakpoint); |
90 |
breakpoint.setHitCountFilter(42, Breakpoint.HIT_COUNT_FILTERING_STYLE.GREATER); |
91 |
|
92 |
assertEquals("Conditional Breakpoint\n\nHit count: > 42", sut.getShortDescription()); |
93 |
} |
94 |
|
95 |
@Test |
96 |
public void testGetShortDescription_Condition_HitCount_MultipleOf () { |
97 |
DebuggerBreakpointAnnotation sut = new DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE), new LineMock(), breakpoint); |
98 |
breakpoint.setHitCountFilter(2, Breakpoint.HIT_COUNT_FILTERING_STYLE.MULTIPLE); |
99 |
|
100 |
assertEquals("Conditional Breakpoint\n\nHit count: multiple of 2", sut.getShortDescription()); |
101 |
} |
102 |
|
103 |
@Test |
104 |
public void testGetShortDescription_Condition_Code_Null () { |
105 |
DebuggerBreakpointAnnotation sut = new DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE), new LineMock(), breakpoint); |
106 |
breakpoint.setCondition(null); |
107 |
|
108 |
assertEquals("Conditional Breakpoint", sut.getShortDescription()); |
109 |
} |
110 |
|
111 |
@Test |
112 |
public void testGetShortDescription_Condition_Code_NotNull () { |
113 |
DebuggerBreakpointAnnotation sut = new DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE), new LineMock(), breakpoint); |
114 |
breakpoint.setCondition("a==6"); |
115 |
|
116 |
assertEquals("Conditional Breakpoint\n\nCondition: a==6", sut.getShortDescription()); |
117 |
} |
118 |
|
119 |
@Test |
120 |
public void testGetShortDescription_Condition_Multiple () { |
121 |
DebuggerBreakpointAnnotation sut = new DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE), new LineMock(), breakpoint); |
122 |
breakpoint.setCondition("a==6"); |
123 |
breakpoint.setHitCountFilter(42, Breakpoint.HIT_COUNT_FILTERING_STYLE.EQUAL); |
124 |
|
125 |
assertEquals("Conditional Breakpoint\n\nCondition: a==6\nHit count: = 42", sut.getShortDescription()); |
126 |
} |
127 |
|
128 |
/** |
129 |
* Test whether {@link FieldBreakpoint}, {@link MethodBreakpoint} and {@link |
130 |
* LineBreakpoint} are supported. Tests the {@link DebuggerBreakpointAnnotation#getCondition(org.netbeans.api.debugger.Breakpoint)} too. |
131 |
*/ |
132 |
@Test |
133 |
public void testGetShortDescription_Condition_SupportedBreakpointTypes () { |
134 |
{ |
135 |
//FIXME next line will throw nasty java.net.MalformedURLExceptionin the log |
136 |
FieldBreakpoint b = FieldBreakpoint.create( |
137 |
"org.netbeans.modules.editor.EditorPanel", |
138 |
"state", |
139 |
FieldBreakpoint.TYPE_MODIFICATION); |
140 |
DebuggerBreakpointAnnotation sut = new DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE), new LineMock(), b); |
141 |
b.setCondition("a==6"); |
142 |
assertEquals("Conditional Breakpoint\n\nCondition: a==6", sut.getShortDescription()); |
143 |
} |
144 |
{ |
145 |
//FIXME next line will throw nasty java.net.MalformedURLExceptionin the log |
146 |
MethodBreakpoint b = MethodBreakpoint.create( |
147 |
"org.netbeans.modules.editor.EditorPanel", |
148 |
"state"); |
149 |
DebuggerBreakpointAnnotation sut = new DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE), new LineMock(), b); |
150 |
b.setCondition("a==6"); |
151 |
|
152 |
assertEquals("Conditional Breakpoint\n\nCondition: a==6", sut.getShortDescription()); |
153 |
|
154 |
} |
155 |
{ |
156 |
DebuggerBreakpointAnnotation sut = new DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE), new LineMock(), breakpoint); |
157 |
breakpoint.setCondition("a==6"); |
158 |
|
159 |
assertEquals("Conditional Breakpoint\n\nCondition: a==6", sut.getShortDescription()); |
160 |
|
161 |
} |
162 |
|
163 |
} |
164 |
|
165 |
private static class LineMock extends Line { |
166 |
|
167 |
public LineMock () { |
168 |
super(Lookup.EMPTY); |
169 |
} |
170 |
|
171 |
@Override |
172 |
public int getLineNumber () { |
173 |
throw new UnsupportedOperationException("Not supported yet."); |
174 |
} |
175 |
|
176 |
@Override |
177 |
public void show (int kind, int column) { |
178 |
throw new UnsupportedOperationException("Not supported yet."); |
179 |
} |
180 |
|
181 |
@Override |
182 |
public void setBreakpoint (boolean b) { |
183 |
throw new UnsupportedOperationException("Not supported yet."); |
184 |
} |
185 |
|
186 |
@Override |
187 |
public boolean isBreakpoint () { |
188 |
throw new UnsupportedOperationException("Not supported yet."); |
189 |
} |
190 |
|
191 |
@Override |
192 |
public void markError () { |
193 |
throw new UnsupportedOperationException("Not supported yet."); |
194 |
} |
195 |
|
196 |
@Override |
197 |
public void unmarkError () { |
198 |
throw new UnsupportedOperationException("Not supported yet."); |
199 |
} |
200 |
|
201 |
@Override |
202 |
public void markCurrentLine () { |
203 |
throw new UnsupportedOperationException("Not supported yet."); |
204 |
} |
205 |
|
206 |
@Override |
207 |
public void unmarkCurrentLine () { |
208 |
throw new UnsupportedOperationException("Not supported yet."); |
209 |
} |
210 |
} |
211 |
} |