KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > editor > java > JavaFormatterArrayInitOrEnumUnitTest


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
20 package org.netbeans.modules.editor.java;
21
22 /**
23  * Java formatter tests.
24  *
25  * @autor Miloslav Metelka
26  */

27 public class JavaFormatterArrayInitOrEnumUnitTest extends JavaFormatterUnitTestCase {
28
29     public JavaFormatterArrayInitOrEnumUnitTest(String JavaDoc testMethodName) {
30         super(testMethodName);
31     }
32
33     public void testReformatIntArray() {
34         setLoadDocumentText(
35                 "void m() {\n" +
36                 "int[] array = {\n" +
37                 "1, 2, 3};\n" +
38                 "f();\n" +
39                 "}\n"
40         );
41         reformat();
42         assertDocumentText("Incorrect multi-array && multi-line reformating",
43                 "void m() {\n" +
44                 " int[] array = {\n" +
45                 " 1, 2, 3};\n" +
46                 " f();\n" +
47                 "}\n"
48         );
49     }
50     
51     public void testReformatStringArray() {
52         setLoadDocumentText(
53                 "void m() {\n" +
54                 "String[] array = {\n" +
55                 "\"first\",\n" +
56                 "\"second\"\n" +
57                 "};\n" +
58                 "f();\n" +
59                 "}\n"
60         );
61         reformat();
62         assertDocumentText("Incorrect multi-array && multi-line reformating",
63                 "void m() {\n" +
64                 " String[] array = {\n" +
65                 " \"first\",\n" +
66                 " \"second\"\n" +
67                 " };\n" +
68                 " f();\n" +
69                 "}\n"
70         );
71     }
72     
73     public void testReformatStringArrayExtraComma() {
74         setLoadDocumentText(
75                 "void m() {\n" +
76                 "String[] array = {\n" +
77                 "\"first\",\n" +
78                 "\"second\",\n" +
79                 "};\n" +
80                 "f();\n" +
81                 "}\n"
82         );
83         reformat();
84         assertDocumentText("Incorrect multi-array && multi-line reformating",
85                 "void m() {\n" +
86                 " String[] array = {\n" +
87                 " \"first\",\n" +
88                 " \"second\",\n" +
89                 " };\n" +
90                 " f();\n" +
91                 "}\n"
92         );
93     }
94     
95     public void testReformatStringArrayRBraceOnSameLine() {
96         setLoadDocumentText(
97                 "void m() {\n" +
98                 "String[] array = {\n" +
99                 "\"first\",\n" +
100                 "\"second\"};\n" +
101                 "f();\n" +
102                 "}\n"
103         );
104         reformat();
105         assertDocumentText("Incorrect multi-array && multi-line reformating",
106                 "void m() {\n" +
107                 " String[] array = {\n" +
108                 " \"first\",\n" +
109                 " \"second\"};\n" +
110                 " f();\n" +
111                 "}\n"
112         );
113     }
114     
115     public void testReformatNewObjectArray() {
116         setLoadDocumentText(
117                 "void m() {\n" +
118                 "Object[] array = {\n" +
119                 "new Object(),\n" +
120                 "new String(\"second\"),\n" +
121                 "new Object()\n" +
122                 "};\n" +
123                 "f();\n" +
124                 "}\n"
125         );
126         reformat();
127         assertDocumentText("Incorrect multi-array && multi-line reformating",
128                 "void m() {\n" +
129                 " Object[] array = {\n" +
130                 " new Object(),\n" +
131                 " new String(\"second\"),\n" +
132                 " new Object()\n" +
133                 " };\n" +
134                 " f();\n" +
135                 "}\n"
136         );
137     }
138     
139     public void testReformatNewObjectArrayMultiLine() {
140         setLoadDocumentText(
141                 "void m() {\n" +
142                 "Object[] array = {\n" +
143                 "new Object(),\n" +
144                 "new String(\n" +
145                 "\"second\"),\n" +
146                 "new Object()\n" +
147                 "};\n" +
148                 "f();\n" +
149                 "}\n"
150         );
151         reformat();
152         assertDocumentText("Incorrect multi-array && multi-line reformating",
153                 "void m() {\n" +
154                 " Object[] array = {\n" +
155                 " new Object(),\n" +
156                 " new String(\n" +
157                 " \"second\"),\n" +
158                 " new Object()\n" +
159                 " };\n" +
160                 " f();\n" +
161                 "}\n"
162         );
163     }
164     
165     public void testReformatStringArrayArgument() {
166         setLoadDocumentText(
167                 "void m() {\n" +
168                 "a(new String[] {\n" +
169                 "\"first\",\n" +
170                 "\"second\"\n" +
171                 "});\n" +
172                 "f();\n" +
173                 "}\n"
174         );
175         reformat();
176         assertDocumentText("Incorrect multi-array && multi-line reformating",
177                 "void m() {\n" +
178                 " a(new String[] {\n" +
179                 " \"first\",\n" +
180                 " \"second\"\n" +
181                 " });\n" +
182                 " f();\n" +
183                 "}\n"
184         );
185     }
186     
187     public void testReformatObjectArrayArgument() {
188         setLoadDocumentText(
189                 "void m() {\n" +
190                 "a(new Object[] {\n" +
191                 "new Object(),\n" +
192                 "\"second\"\n" +
193                 "});\n" +
194                 "f();\n" +
195                 "}\n"
196         );
197         reformat();
198         assertDocumentText("Incorrect multi-array && multi-line reformating",
199                 "void m() {\n" +
200                 " a(new Object[] {\n" +
201                 " new Object(),\n" +
202                 " \"second\"\n" +
203                 " });\n" +
204                 " f();\n" +
205                 "}\n"
206         );
207     }
208     
209     public void testReformatMultiArray() {
210         setLoadDocumentText(
211                 "static int[][] CONVERT_TABLE={\n" +
212                 "{1,2},{2,3},\n" +
213                 "{3,4},{4,5},{5,6},\n" +
214                 "{6,7},{7,8},{8,9}};\n" +
215                 "f();\n"
216         );
217         reformat();
218         assertDocumentText("Incorrect multi-array && multi-line reformating",
219                 "static int[][] CONVERT_TABLE={\n" +
220                 " {1,2},{2,3},\n" +
221                 " {3,4},{4,5},{5,6},\n" +
222                 " {6,7},{7,8},{8,9}};\n" +
223                 "f();\n"
224         );
225     }
226
227     
228     public void testReformatSimpleEnum() {
229         setLoadDocumentText(
230                 "public enum SimpleEnum {\n" +
231                 "ONE,\n" +
232                 "TWO,\n" +
233                 "THREE\n" +
234                 "}\n");
235         reformat();
236         assertDocumentText("Incorrect simple enum reformating",
237                 "public enum SimpleEnum {\n" +
238                 " ONE,\n" +
239                 " TWO,\n" +
240                 " THREE\n" +
241                 "}\n");
242     }
243     
244     public void testReformatNestedEnum() {
245         setLoadDocumentText(
246                 "public enum SimpleEnum {\n" +
247                 "ONE,\n" +
248                 "TWO,\n" +
249                 "THREE;\n" +
250                 "public enum NestedEnum {\n" +
251                 "A,\n" +
252                 "B\n" +
253                 "}\n" +
254                 "}\n");
255         reformat();
256         assertDocumentText("Incorrect nested enum reformating",
257                 "public enum SimpleEnum {\n" +
258                 " ONE,\n" +
259                 " TWO,\n" +
260                 " THREE;\n" +
261                 " public enum NestedEnum {\n" +
262                 " A,\n" +
263                 " B\n" +
264                 " }\n" +
265                 "}\n");
266     }
267     
268     public void testReformatComplexEnum() {
269         setLoadDocumentText(
270                 "public enum ComplexEnum {\n" +
271                 "ONE,\n" +
272                 "TWO {\n" +
273                 "public void op(int a,\n" +
274                 "int b,\n" +
275                 "int c) {\n" +
276                 "}\n" +
277                 "public class Inner {\n" +
278                 "int a, b,\n" +
279                 "c,\n" +
280                 "d;\n" +
281                 "}\n" +
282                 "},\n" +
283                 "THREE\n" +
284                 "}\n");
285         reformat();
286         assertDocumentText("Incorrect complex enum reformating",
287                 "public enum ComplexEnum {\n" +
288                 " ONE,\n" +
289                 " TWO {\n" +
290                 " public void op(int a,\n" +
291                 " int b,\n" +
292                 " int c) {\n" +
293                 " }\n" +
294                 " public class Inner {\n" +
295                 " int a, b,\n" +
296                 " c,\n" +
297                 " d;\n" +
298                 " }\n" +
299                 " },\n" +
300                 " THREE\n" +
301                 "}\n");
302     }
303     
304 }
305
Popular Tags