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: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 2005 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.junit;
043:
044: import junit.framework.TestCase;
045:
046: /**
047: *
048: * @author Marian Petras
049: */
050: public class ClassNameTextFieldTest extends TestCase {
051:
052: public ClassNameTextFieldTest(String testName) {
053: super (testName);
054: }
055:
056: private class StringIntPair {
057: private final String str;
058: private final int value;
059:
060: StringIntPair(String str, int value) {
061: this .str = str;
062: this .value = value;
063: }
064: }
065:
066: /**
067: * Test of determineStatus method, of class org.netbeans.modules.junit.ClassNameTextField.
068: */
069: public void testDetermineStatus() {
070: StringIntPair[] testData = new StringIntPair[] {
071: new StringIntPair("",
072: ClassNameTextField.STATUS_BEFORE_PART),
073: new StringIntPair("A", ClassNameTextField.STATUS_VALID),
074: new StringIntPair("abc",
075: ClassNameTextField.STATUS_VALID),
076: new StringIntPair("Abc",
077: ClassNameTextField.STATUS_VALID),
078: new StringIntPair("abc2",
079: ClassNameTextField.STATUS_VALID),
080: new StringIntPair("Abc2",
081: ClassNameTextField.STATUS_VALID),
082: new StringIntPair("a2", ClassNameTextField.STATUS_VALID),
083: new StringIntPair("A2", ClassNameTextField.STATUS_VALID),
084: new StringIntPair("abc2.",
085: ClassNameTextField.STATUS_BEFORE_PART),
086: new StringIntPair("Abc2.",
087: ClassNameTextField.STATUS_BEFORE_PART),
088: new StringIntPair("a2.",
089: ClassNameTextField.STATUS_BEFORE_PART),
090: new StringIntPair("A2.",
091: ClassNameTextField.STATUS_BEFORE_PART),
092: new StringIntPair("2a",
093: ClassNameTextField.STATUS_INVALID),
094: new StringIntPair("2A",
095: ClassNameTextField.STATUS_INVALID),
096: new StringIntPair("2a.",
097: ClassNameTextField.STATUS_INVALID),
098: new StringIntPair("2A.",
099: ClassNameTextField.STATUS_INVALID),
100: new StringIntPair("A.B",
101: ClassNameTextField.STATUS_VALID),
102: new StringIntPair("a.B",
103: ClassNameTextField.STATUS_VALID),
104: new StringIntPair("A.b",
105: ClassNameTextField.STATUS_VALID),
106: new StringIntPair("a.b",
107: ClassNameTextField.STATUS_VALID),
108: new StringIntPair("A2.b",
109: ClassNameTextField.STATUS_VALID),
110: new StringIntPair("a2.b",
111: ClassNameTextField.STATUS_VALID),
112: new StringIntPair("A.b2",
113: ClassNameTextField.STATUS_VALID),
114: new StringIntPair("a.b2",
115: ClassNameTextField.STATUS_VALID), };
116: assertEquals("check determined status if no text is passed",
117: ClassNameTextField.STATUS_BEFORE_PART,
118: new ClassNameTextField().determineStatus());
119: for (int i = 0; i < testData.length; i++) {
120: assertEquals("check determined status for text \""
121: + testData[i].str + '"', testData[i].value,
122: new ClassNameTextField(testData[i].str)
123: .determineStatus());
124: }
125: }
126:
127: /**
128: * Test of getStatus method, of class org.netbeans.modules.junit.ClassNameTextField.
129: */
130: public void testGetStatus() {
131: StringIntPair[] testData = new StringIntPair[] {
132: new StringIntPair("", ClassNameTextField.STATUS_EMPTY),
133: new StringIntPair("A", ClassNameTextField.STATUS_VALID),
134: new StringIntPair("abc",
135: ClassNameTextField.STATUS_VALID),
136: new StringIntPair("Abc",
137: ClassNameTextField.STATUS_VALID),
138: new StringIntPair("abc2",
139: ClassNameTextField.STATUS_VALID),
140: new StringIntPair("Abc2",
141: ClassNameTextField.STATUS_VALID),
142: new StringIntPair("a2", ClassNameTextField.STATUS_VALID),
143: new StringIntPair("A2", ClassNameTextField.STATUS_VALID),
144: new StringIntPair("abc2.",
145: ClassNameTextField.STATUS_INVALID),
146: new StringIntPair("Abc2.",
147: ClassNameTextField.STATUS_INVALID),
148: new StringIntPair("a2.",
149: ClassNameTextField.STATUS_INVALID),
150: new StringIntPair("A2.",
151: ClassNameTextField.STATUS_INVALID),
152: new StringIntPair("2a",
153: ClassNameTextField.STATUS_INVALID),
154: new StringIntPair("2A",
155: ClassNameTextField.STATUS_INVALID),
156: new StringIntPair("2a.",
157: ClassNameTextField.STATUS_INVALID),
158: new StringIntPair("2A.",
159: ClassNameTextField.STATUS_INVALID),
160: new StringIntPair("A.B",
161: ClassNameTextField.STATUS_VALID),
162: new StringIntPair("a.B",
163: ClassNameTextField.STATUS_VALID),
164: new StringIntPair("A.b",
165: ClassNameTextField.STATUS_VALID),
166: new StringIntPair("a.b",
167: ClassNameTextField.STATUS_VALID),
168: new StringIntPair("A2.b",
169: ClassNameTextField.STATUS_VALID),
170: new StringIntPair("a2.b",
171: ClassNameTextField.STATUS_VALID),
172: new StringIntPair("A.b2",
173: ClassNameTextField.STATUS_VALID),
174: new StringIntPair("a.b2",
175: ClassNameTextField.STATUS_VALID), };
176: assertEquals("check status if no parameter passed",
177: ClassNameTextField.STATUS_EMPTY,
178: new ClassNameTextField().getStatus());
179: for (int i = 0; i < testData.length; i++) {
180: assertEquals("check status for text \"" + testData[i].str
181: + '"', testData[i].value, new ClassNameTextField(
182: testData[i].str).getStatus());
183: }
184: }
185:
186: }
|