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: * Contributor(s):
025: *
026: * Portions Copyrighted 2007 Sun Microsystems, Inc.
027: */
028: package org.netbeans.test.java.editor.codegeneration;
029:
030: import junit.framework.TestSuite;
031: import junit.textui.TestRunner;
032: import lib.EditorTestCase;
033: import org.netbeans.jellytools.EditorOperator;
034: import org.netbeans.jemmy.operators.JEditorPaneOperator;
035:
036: /**
037: *
038: * @author jp159440
039: */
040: public class GenerateCode extends EditorTestCase {
041:
042: public GenerateCode(String testMethodName) {
043: super (testMethodName);
044: }
045:
046: protected boolean contains(String text, String pattern) {
047: return text.contains(pattern);
048: }
049:
050: private boolean isWin() {
051: return System.getProperty("os.name").contains("Windows");
052: }
053:
054: @Override
055: protected void setUp() throws Exception {
056: super .setUp();
057: openProject("java_editor_test");
058: }
059:
060: @Override
061: protected void tearDown() throws Exception {
062: super .tearDown();
063: }
064:
065: protected void waitAndCompare(String expected) {
066: if (isWin()) {
067: expected = expected.replace("\n", "\r\n");
068: }
069: waitMaxMilisForValue(1500, new EditorValueResolver(expected),
070: Boolean.TRUE);
071: if (!contains(editor.getText(), expected)) {
072: System.out.println("Pattern:");
073: System.out.println(expected);
074: System.out.println("-------------------");
075: System.out.println(editor.getText());
076: }
077: assertTrue("Expected code is not inserted", contains(editor
078: .getText(), expected));
079: }
080:
081: protected EditorOperator editor;
082: protected JEditorPaneOperator txtOper;
083:
084: protected class EditorValueResolver implements ValueResolver {
085:
086: String text;
087:
088: public EditorValueResolver(String text) {
089: this .text = text;
090: }
091:
092: public Object getValue() {
093: return editor.getText().contains(text);
094: }
095:
096: }
097:
098: public static TestSuite suite() {
099: TestSuite ts = new TestSuite();
100: ts.addTestSuite(CreateConstructor.class);
101: ts.addTestSuite(CreateEqualsHashcode.class);
102: ts.addTestSuite(CreateGetterSetter.class);
103: ts.addTestSuite(ImplementMethod.class);
104: return ts;
105: }
106:
107: public static void main(String[] args) {
108: TestRunner.run(suite());
109: }
110:
111: }
|