Line 0
Link Here
|
|
|
1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 |
* |
4 |
* Copyright 2013 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 2013 Sun Microsystems, Inc. |
41 |
*/ |
42 |
package org.netbeans.modules.java.hints.suggestions; |
43 |
|
44 |
import org.junit.Test; |
45 |
import org.netbeans.modules.java.hints.test.api.HintTest; |
46 |
|
47 |
/** |
48 |
* @author markiewb |
49 |
*/ |
50 |
public class UseBDConstFixTest { |
51 |
|
52 |
@Test |
53 |
public void testConvertONE_A() throws Exception { |
54 |
HintTest.create() |
55 |
.input("package test;\n" |
56 |
+ "public class Test {\n" |
57 |
+ " public static void main(String[] args) {\n" |
58 |
+ " java.math.BigDecimal a=new java.math.BigDecimal(\"1\");\n" |
59 |
+ " }\n" |
60 |
+ "}\n") |
61 |
.run(UseBDConstFix.class) |
62 |
.findWarning("3:31-3:60:hint:" + Bundle.DN_UseBigDecimalConstants()) |
63 |
.applyFix() |
64 |
.assertCompilable() |
65 |
.assertOutput("package test;\n" |
66 |
+ "import java.math.BigDecimal;\n" |
67 |
+ "public class Test {\n" |
68 |
+ " public static void main(String[] args) {\n" |
69 |
+ " java.math.BigDecimal a=BigDecimal.ONE;\n" |
70 |
+ " }\n" |
71 |
+ "}\n"); |
72 |
|
73 |
} |
74 |
|
75 |
@Test |
76 |
public void testConvertONE_B() throws Exception { |
77 |
HintTest.create() |
78 |
.input("package test;\n" |
79 |
+ "public class Test {\n" |
80 |
+ " public static void main(String[] args) {\n" |
81 |
+ " java.math.BigDecimal a=new java.math.BigDecimal(\"1.0\");\n" |
82 |
+ " }\n" |
83 |
+ "}\n") |
84 |
.run(UseBDConstFix.class) |
85 |
.findWarning("3:31-3:62:hint:" + Bundle.DN_UseBigDecimalConstants()) |
86 |
.applyFix() |
87 |
.assertCompilable() |
88 |
.assertOutput("package test;\n" |
89 |
+ "import java.math.BigDecimal;\n" |
90 |
+ "public class Test {\n" |
91 |
+ " public static void main(String[] args) {\n" |
92 |
+ " java.math.BigDecimal a=BigDecimal.ONE;\n" |
93 |
+ " }\n" |
94 |
+ "}\n"); |
95 |
|
96 |
} |
97 |
|
98 |
@Test |
99 |
public void testConvertONE_C() throws Exception { |
100 |
HintTest.create() |
101 |
.input("package test;\n" |
102 |
+ "public class Test {\n" |
103 |
+ " public static void main(String[] args) {\n" |
104 |
+ " java.math.BigDecimal a=new java.math.BigDecimal(1.0);\n" |
105 |
+ " }\n" |
106 |
+ "}\n") |
107 |
.run(UseBDConstFix.class) |
108 |
.findWarning("3:31-3:60:hint:" + Bundle.DN_UseBigDecimalConstants()) |
109 |
.applyFix() |
110 |
.assertCompilable() |
111 |
.assertOutput("package test;\n" |
112 |
+ "import java.math.BigDecimal;\n" |
113 |
+ "public class Test {\n" |
114 |
+ " public static void main(String[] args) {\n" |
115 |
+ " java.math.BigDecimal a=BigDecimal.ONE;\n" |
116 |
+ " }\n" |
117 |
+ "}\n"); |
118 |
|
119 |
} |
120 |
|
121 |
@Test |
122 |
public void testConvertONE_D() throws Exception { |
123 |
HintTest.create() |
124 |
.input("package test;\n" |
125 |
+ "public class Test {\n" |
126 |
+ " public static void main(String[] args) {\n" |
127 |
+ " java.math.BigDecimal a=new java.math.BigDecimal(1.00d);\n" |
128 |
+ " }\n" |
129 |
+ "}\n") |
130 |
.run(UseBDConstFix.class) |
131 |
.findWarning("3:31-3:62:hint:" + Bundle.DN_UseBigDecimalConstants()) |
132 |
.applyFix() |
133 |
.assertCompilable() |
134 |
.assertOutput("package test;\n" |
135 |
+ "import java.math.BigDecimal;\n" |
136 |
+ "public class Test {\n" |
137 |
+ " public static void main(String[] args) {\n" |
138 |
+ " java.math.BigDecimal a=BigDecimal.ONE;\n" |
139 |
+ " }\n" |
140 |
+ "}\n"); |
141 |
|
142 |
} |
143 |
|
144 |
@Test |
145 |
public void testConvertTEN_A() throws Exception { |
146 |
HintTest.create() |
147 |
.input("package test;\n" |
148 |
+ "public class Test {\n" |
149 |
+ " public static void main(String[] args) {\n" |
150 |
+ " java.math.BigDecimal a=new java.math.BigDecimal(\"10\");\n" |
151 |
+ " }\n" |
152 |
+ "}\n") |
153 |
.run(UseBDConstFix.class) |
154 |
.findWarning("3:31-3:61:hint:" + Bundle.DN_UseBigDecimalConstants()) |
155 |
.applyFix() |
156 |
.assertCompilable() |
157 |
.assertOutput("package test;\n" |
158 |
+ "import java.math.BigDecimal;\n" |
159 |
+ "public class Test {\n" |
160 |
+ " public static void main(String[] args) {\n" |
161 |
+ " java.math.BigDecimal a=BigDecimal.TEN;\n" |
162 |
+ " }\n" |
163 |
+ "}\n"); |
164 |
|
165 |
} |
166 |
|
167 |
@Test |
168 |
public void testConvertTEN_B() throws Exception { |
169 |
HintTest.create() |
170 |
.input("package test;\n" |
171 |
+ "public class Test {\n" |
172 |
+ " public static void main(String[] args) {\n" |
173 |
+ " java.math.BigDecimal a=new java.math.BigDecimal(\"10.0\");\n" |
174 |
+ " }\n" |
175 |
+ "}\n") |
176 |
.run(UseBDConstFix.class) |
177 |
.findWarning("3:31-3:63:hint:" + Bundle.DN_UseBigDecimalConstants()) |
178 |
.applyFix() |
179 |
.assertCompilable() |
180 |
.assertOutput("package test;\n" |
181 |
+ "import java.math.BigDecimal;\n" |
182 |
+ "public class Test {\n" |
183 |
+ " public static void main(String[] args) {\n" |
184 |
+ " java.math.BigDecimal a=BigDecimal.TEN;\n" |
185 |
+ " }\n" |
186 |
+ "}\n"); |
187 |
|
188 |
} |
189 |
|
190 |
@Test |
191 |
public void testConvertTEN_C() throws Exception { |
192 |
HintTest.create() |
193 |
.input("package test;\n" |
194 |
+ "public class Test {\n" |
195 |
+ " public static void main(String[] args) {\n" |
196 |
+ " java.math.BigDecimal a=new java.math.BigDecimal(10.0);\n" |
197 |
+ " }\n" |
198 |
+ "}\n") |
199 |
.run(UseBDConstFix.class) |
200 |
.findWarning("3:31-3:61:hint:" + Bundle.DN_UseBigDecimalConstants()) |
201 |
.applyFix() |
202 |
.assertCompilable() |
203 |
.assertOutput("package test;\n" |
204 |
+ "import java.math.BigDecimal;\n" |
205 |
+ "public class Test {\n" |
206 |
+ " public static void main(String[] args) {\n" |
207 |
+ " java.math.BigDecimal a=BigDecimal.TEN;\n" |
208 |
+ " }\n" |
209 |
+ "}\n"); |
210 |
|
211 |
} |
212 |
|
213 |
@Test |
214 |
public void testConvertTEN_D() throws Exception { |
215 |
HintTest.create() |
216 |
.input("package test;\n" |
217 |
+ "public class Test {\n" |
218 |
+ " public static void main(String[] args) {\n" |
219 |
+ " java.math.BigDecimal a=new java.math.BigDecimal(10.00d);\n" |
220 |
+ " }\n" |
221 |
+ "}\n") |
222 |
.run(UseBDConstFix.class) |
223 |
.findWarning("3:31-3:63:hint:" + Bundle.DN_UseBigDecimalConstants()) |
224 |
.applyFix() |
225 |
.assertCompilable() |
226 |
.assertOutput("package test;\n" |
227 |
+ "import java.math.BigDecimal;\n" |
228 |
+ "public class Test {\n" |
229 |
+ " public static void main(String[] args) {\n" |
230 |
+ " java.math.BigDecimal a=BigDecimal.TEN;\n" |
231 |
+ " }\n" |
232 |
+ "}\n"); |
233 |
|
234 |
} |
235 |
|
236 |
@Test |
237 |
public void testConvertZERO_A() throws Exception { |
238 |
HintTest.create() |
239 |
.input("package test;\n" |
240 |
+ "public class Test {\n" |
241 |
+ " public static void main(String[] args) {\n" |
242 |
+ " java.math.BigDecimal a=new java.math.BigDecimal(\"0\");\n" |
243 |
+ " }\n" |
244 |
+ "}\n") |
245 |
.run(UseBDConstFix.class) |
246 |
.findWarning("3:31-3:60:hint:" + Bundle.DN_UseBigDecimalConstants()) |
247 |
.applyFix() |
248 |
.assertCompilable() |
249 |
.assertOutput("package test;\n" |
250 |
+ "import java.math.BigDecimal;\n" |
251 |
+ "public class Test {\n" |
252 |
+ " public static void main(String[] args) {\n" |
253 |
+ " java.math.BigDecimal a=BigDecimal.ZERO;\n" |
254 |
+ " }\n" |
255 |
+ "}\n"); |
256 |
|
257 |
} |
258 |
|
259 |
@Test |
260 |
public void testConvertZERO_B() throws Exception { |
261 |
HintTest.create() |
262 |
.input("package test;\n" |
263 |
+ "public class Test {\n" |
264 |
+ " public static void main(String[] args) {\n" |
265 |
+ " java.math.BigDecimal a=new java.math.BigDecimal(\"0.0\");\n" |
266 |
+ " }\n" |
267 |
+ "}\n") |
268 |
.run(UseBDConstFix.class) |
269 |
.findWarning("3:31-3:62:hint:" + Bundle.DN_UseBigDecimalConstants()) |
270 |
.applyFix() |
271 |
.assertCompilable() |
272 |
.assertOutput("package test;\n" |
273 |
+ "import java.math.BigDecimal;\n" |
274 |
+ "public class Test {\n" |
275 |
+ " public static void main(String[] args) {\n" |
276 |
+ " java.math.BigDecimal a=BigDecimal.ZERO;\n" |
277 |
+ " }\n" |
278 |
+ "}\n"); |
279 |
|
280 |
} |
281 |
|
282 |
@Test |
283 |
public void testConvertZERO_C() throws Exception { |
284 |
HintTest.create() |
285 |
.input("package test;\n" |
286 |
+ "public class Test {\n" |
287 |
+ " public static void main(String[] args) {\n" |
288 |
+ " java.math.BigDecimal a=new java.math.BigDecimal(0.0);\n" |
289 |
+ " }\n" |
290 |
+ "}\n") |
291 |
.run(UseBDConstFix.class) |
292 |
.findWarning("3:31-3:60:hint:" + Bundle.DN_UseBigDecimalConstants()) |
293 |
.applyFix() |
294 |
.assertCompilable() |
295 |
.assertOutput("package test;\n" |
296 |
+ "import java.math.BigDecimal;\n" |
297 |
+ "public class Test {\n" |
298 |
+ " public static void main(String[] args) {\n" |
299 |
+ " java.math.BigDecimal a=BigDecimal.ZERO;\n" |
300 |
+ " }\n" |
301 |
+ "}\n"); |
302 |
|
303 |
} |
304 |
|
305 |
@Test |
306 |
public void testConvertZERO_D() throws Exception { |
307 |
HintTest.create() |
308 |
.input("package test;\n" |
309 |
+ "public class Test {\n" |
310 |
+ " public static void main(String[] args) {\n" |
311 |
+ " java.math.BigDecimal a=new java.math.BigDecimal(0.00d);\n" |
312 |
+ " }\n" |
313 |
+ "}\n") |
314 |
.run(UseBDConstFix.class) |
315 |
.findWarning("3:31-3:62:hint:" + Bundle.DN_UseBigDecimalConstants()) |
316 |
.applyFix() |
317 |
.assertCompilable() |
318 |
.assertOutput("package test;\n" |
319 |
+ "import java.math.BigDecimal;\n" |
320 |
+ "public class Test {\n" |
321 |
+ " public static void main(String[] args) {\n" |
322 |
+ " java.math.BigDecimal a=BigDecimal.ZERO;\n" |
323 |
+ " }\n" |
324 |
+ "}\n"); |
325 |
|
326 |
} |
327 |
|
328 |
} |