001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * If you wish your version of this file to be governed by only the CDDL
025: * or only the GPL Version 2, indicate your decision by adding
026: * "[Contributor] elects to include this software in this distribution
027: * under the [CDDL or GPL Version 2] license." If you do not indicate a
028: * single choice of license, a recipient has the option to distribute
029: * your version of this file under either the CDDL, the GPL Version 2 or
030: * to extend the choice of license to its licensees as provided above.
031: * However, if you add GPL Version 2 code and therefore, elected the GPL
032: * Version 2 license, then the option applies only if the new code is
033: * made subject to such option by the copyright holder.
034: *
035: * Contributor(s):
036: *
037: * Portions Copyrighted 2007 Sun Microsystems, Inc.
038: */
039: package org.netbeans.test.java.editor.codegeneration;
040:
041: import java.util.List;
042: import junit.textui.TestRunner;
043: import org.netbeans.jellytools.EditorOperator;
044: import org.netbeans.jemmy.EventTool;
045: import org.netbeans.jemmy.operators.JTreeOperator;
046: import org.netbeans.test.java.editor.jelly.GenerateCodeOperator;
047: import org.netbeans.test.java.editor.jelly.GenerateGettersAndSettersOperator;
048:
049: /**
050: *
051: * @author jp159440
052: */
053: public class CreateGetterSetter extends GenerateCode {
054:
055: public CreateGetterSetter(String testMethodName) {
056: super (testMethodName);
057: }
058:
059: public void testAvailableGettersSetters() {
060: openSourceFile("org.netbeans.test.java.editor.codegeneration",
061: "CreateGetterSetter");
062: editor = new EditorOperator("CreateGetterSetter");
063: txtOper = editor.txtEditorPane();
064: try {
065: editor.requestFocus();
066: editor.setCaretPosition(11, 1);
067: GenerateCodeOperator
068: .openDialog(
069: GenerateCodeOperator.GENERATE_GETTER_SETTER,
070: editor);
071: GenerateGettersAndSettersOperator ggso = new GenerateGettersAndSettersOperator(
072: GenerateGettersAndSettersOperator.GETTERS_AND_SETTERS);
073: JTreeOperator jto = ggso.treeTreeView$ExplorerTree();
074: int rowCount = jto.getRowCount();
075: ggso.cancel();
076: assertEquals("Wrong number of rows", 5, rowCount);
077:
078: } finally {
079: editor.close(false);
080: }
081: }
082:
083: public void testAvailableGetters() {
084: openSourceFile("org.netbeans.test.java.editor.codegeneration",
085: "CreateGetterSetter");
086: editor = new EditorOperator("CreateGetterSetter");
087: txtOper = editor.txtEditorPane();
088: try {
089: editor.requestFocus();
090: editor.setCaretPosition(11, 1);
091: GenerateCodeOperator.openDialog(
092: GenerateCodeOperator.GENERATE_GETTER, editor);
093: GenerateGettersAndSettersOperator ggso = new GenerateGettersAndSettersOperator(
094: GenerateGettersAndSettersOperator.GETTERS_ONLY);
095: JTreeOperator jto = ggso.treeTreeView$ExplorerTree();
096: int rowCount = jto.getRowCount();
097: ggso.cancel();
098: assertEquals("Wrong number of rows", 6, rowCount);
099: } finally {
100: editor.close(false);
101: }
102: }
103:
104: public void testAvailableSetters() {
105: openSourceFile("org.netbeans.test.java.editor.codegeneration",
106: "CreateGetterSetter");
107: editor = new EditorOperator("CreateGetterSetter");
108: txtOper = editor.txtEditorPane();
109: try {
110: editor.requestFocus();
111: editor.setCaretPosition(11, 1);
112: GenerateCodeOperator.openDialog(
113: GenerateCodeOperator.GENERATE_SETTER, editor);
114: GenerateGettersAndSettersOperator ggso = new GenerateGettersAndSettersOperator(
115: GenerateGettersAndSettersOperator.SETTERS_ONLY);
116: JTreeOperator jto = ggso.treeTreeView$ExplorerTree();
117: int rowCount = jto.getRowCount();
118: ggso.cancel();
119: assertEquals("Wrong number of rows", 6, rowCount);
120: } finally {
121: editor.close(false);
122: }
123: }
124:
125: public void testPrimitiveType() {
126: openSourceFile("org.netbeans.test.java.editor.codegeneration",
127: "CreateGetterSetter");
128: editor = new EditorOperator("CreateGetterSetter");
129: txtOper = editor.txtEditorPane();
130: try {
131: editor.requestFocus();
132: editor.setCaretPosition(11, 1);
133: GenerateCodeOperator
134: .openDialog(
135: GenerateCodeOperator.GENERATE_GETTER_SETTER,
136: editor);
137: GenerateGettersAndSettersOperator ggso = new GenerateGettersAndSettersOperator(
138: GenerateGettersAndSettersOperator.GETTERS_AND_SETTERS);
139: JTreeOperator jto = ggso.treeTreeView$ExplorerTree();
140: jto.selectRow(2);
141: ggso.generate();
142: String expected = "" + " public int getNum() {\n"
143: + " return num;\n" + " }\n" + "\n"
144: + " public void setNum(int num) {\n"
145: + " this.num = num;\n" + " }\n";
146: waitAndCompare(expected);
147: } finally {
148: editor.close(false);
149: }
150: }
151:
152: public void testObjectType() {
153: openSourceFile("org.netbeans.test.java.editor.codegeneration",
154: "CreateGetterSetter");
155: editor = new EditorOperator("CreateGetterSetter");
156: txtOper = editor.txtEditorPane();
157: try {
158: editor.requestFocus();
159: editor.setCaretPosition(11, 1);
160: GenerateCodeOperator
161: .openDialog(
162: GenerateCodeOperator.GENERATE_GETTER_SETTER,
163: editor);
164: GenerateGettersAndSettersOperator ggso = new GenerateGettersAndSettersOperator(
165: GenerateGettersAndSettersOperator.GETTERS_AND_SETTERS);
166: JTreeOperator jto = ggso.treeTreeView$ExplorerTree();
167: jto.selectRow(4);
168: ggso.generate();
169: String expected = ""
170: + " public List<? extends Thread> getThreads() {\n"
171: + " return threads;\n"
172: + " }\n"
173: + "\n"
174: + " public void setThreads(List<? extends Thread> threads) {\n"
175: + " this.threads = threads;\n" + " }\n";
176: waitAndCompare(expected);
177: } finally {
178: editor.close(false);
179: }
180: }
181:
182: public void testBooleanType() {
183: openSourceFile(
184: "org.netbeans.test.java.editor.codegeneration.CreateGetterSetter",
185: "CreateGetterSetter");
186: editor = new EditorOperator("CreateGetterSetter");
187: txtOper = editor.txtEditorPane();
188: try {
189: editor.requestFocus();
190: editor.setCaretPosition(11, 1);
191: GenerateCodeOperator
192: .openDialog(
193: GenerateCodeOperator.GENERATE_GETTER_SETTER,
194: editor);
195: GenerateGettersAndSettersOperator ggso = new GenerateGettersAndSettersOperator(
196: GenerateGettersAndSettersOperator.GETTERS_AND_SETTERS);
197: JTreeOperator jto = ggso.treeTreeView$ExplorerTree();
198: jto.selectRow(1);
199: ggso.generate();
200: String expected = "" + " public boolean isBool() {\n"
201: + " return bool;\n" + " }\n" + "\n"
202: + " public void setBool(boolean bool) {\n"
203: + " this.bool = bool;\n" + " }\n";
204: waitAndCompare(expected);
205: } finally {
206: editor.close(false);
207: }
208: }
209:
210: public void testStaticType() {
211: openSourceFile(
212: "org.netbeans.test.java.editor.codegeneration.CreateGetterSetter",
213: "CreateGetterSetter");
214: editor = new EditorOperator("CreateGetterSetter");
215: txtOper = editor.txtEditorPane();
216: try {
217: editor.requestFocus();
218: editor.setCaretPosition(11, 1);
219: GenerateCodeOperator
220: .openDialog(
221: GenerateCodeOperator.GENERATE_GETTER_SETTER,
222: editor);
223: GenerateGettersAndSettersOperator ggso = new GenerateGettersAndSettersOperator(
224: GenerateGettersAndSettersOperator.GETTERS_AND_SETTERS);
225: JTreeOperator jto = ggso.treeTreeView$ExplorerTree();
226: jto.selectRow(3);
227: ggso.generate();
228: String expected = ""
229: + " public static int getStatField() {\n"
230: + " return statField;\n"
231: + " }\n"
232: + "\n"
233: + " public static void setStatField(int statField) {\n"
234: + " CreateGetterSetter.statField = statField;\n"
235: + " }\n";
236: waitAndCompare(expected);
237: } finally {
238: editor.close(false);
239: }
240: }
241:
242: public void testMultipleSetter() {
243: openSourceFile(
244: "org.netbeans.test.java.editor.codegeneration.CreateGetterSetter",
245: "CreateGetterSetter");
246: editor = new EditorOperator("CreateGetterSetter");
247: txtOper = editor.txtEditorPane();
248: try {
249: editor.requestFocus();
250: editor.setCaretPosition(11, 1);
251: GenerateCodeOperator.openDialog(
252: GenerateCodeOperator.GENERATE_SETTER, editor);
253: GenerateGettersAndSettersOperator ggso = new GenerateGettersAndSettersOperator(
254: GenerateGettersAndSettersOperator.SETTERS_ONLY);
255: JTreeOperator jto = ggso.treeTreeView$ExplorerTree();
256: jto.selectRow(3);
257: jto.selectRow(2);
258: jto.selectRow(1);
259: ggso.generate();
260: String expected = ""
261: + " public void setBool(boolean bool) {\n"
262: + " this.bool = bool;\n" + " }\n" + "\n"
263: + " public void setHasGetter(int hasGetter) {\n"
264: + " this.hasGetter = hasGetter;\n"
265: + " }\n" + "\n"
266: + " public void setNum(int num) {\n"
267: + " this.num = num;\n" + " }\n";
268: waitAndCompare(expected);
269: } finally {
270: editor.close(false);
271: }
272: }
273:
274: public void testMultipleGetter() {
275: openSourceFile(
276: "org.netbeans.test.java.editor.codegeneration.CreateGetterSetter",
277: "CreateGetterSetter");
278: editor = new EditorOperator("CreateGetterSetter");
279: txtOper = editor.txtEditorPane();
280: try {
281: editor.requestFocus();
282: editor.setCaretPosition(11, 1);
283: GenerateCodeOperator.openDialog(
284: GenerateCodeOperator.GENERATE_GETTER, editor);
285: GenerateGettersAndSettersOperator ggso = new GenerateGettersAndSettersOperator(
286: GenerateGettersAndSettersOperator.GETTERS_ONLY);
287: JTreeOperator jto = ggso.treeTreeView$ExplorerTree();
288: jto.selectRow(1);
289: jto.selectRow(2);
290: jto.selectRow(3);
291: ggso.generate();
292: String expected = "" + " public boolean isBool() {\n"
293: + " return bool;\n" + " }\n" + "\n"
294: + " public int getHasSetter() {\n"
295: + " return hasSetter;\n" + " }\n" + "\n"
296: + " public int getNum() {\n"
297: + " return num;\n" + " }\n";
298: waitAndCompare(expected);
299: } finally {
300: editor.close(false);
301: }
302: }
303:
304: public void testArray() {
305: openSourceFile(
306: "org.netbeans.test.java.editor.codegeneration.CreateGetterSetter",
307: "CreateGetterSetter");
308: editor = new EditorOperator("CreateGetterSetter");
309: txtOper = editor.txtEditorPane();
310: try {
311: editor.requestFocus();
312: editor.setCaretPosition(11, 1);
313: editor.txtEditorPane().typeText("int [] pole;");
314: GenerateCodeOperator
315: .openDialog(
316: GenerateCodeOperator.GENERATE_GETTER_SETTER,
317: editor);
318: GenerateGettersAndSettersOperator ggso = new GenerateGettersAndSettersOperator(
319: GenerateGettersAndSettersOperator.GETTERS_AND_SETTERS);
320: JTreeOperator jto = ggso.treeTreeView$ExplorerTree();
321: jto.selectRow(3);
322: ggso.generate();
323: String expected = "" + " public int[] getPole() {\n"
324: + " return pole;\n" + " }\n" + "\n"
325: + " public void setPole(int[] pole) {\n"
326: + " this.pole = pole;\n" + " }\n";
327: waitAndCompare(expected);
328: } finally {
329: editor.close(false);
330: }
331: }
332:
333: public static void main(String[] args) {
334: TestRunner.run(CreateGetterSetter.class);
335: }
336:
337: }
|