KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > junit > ClassNameTextFieldTest


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 2005 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.junit;
21
22 import junit.framework.TestCase;
23
24 /**
25  *
26  * @author Marian Petras
27  */

28 public class ClassNameTextFieldTest extends TestCase {
29
30     public ClassNameTextFieldTest(String JavaDoc testName) {
31         super(testName);
32     }
33
34     private class StringIntPair {
35         private final String JavaDoc str;
36         private final int value;
37         StringIntPair(String JavaDoc str, int value) {
38             this.str = str;
39             this.value = value;
40         }
41     }
42
43     /**
44      * Test of determineStatus method, of class org.netbeans.modules.junit.ClassNameTextField.
45      */

46     public void testDetermineStatus() {
47         StringIntPair[] testData = new StringIntPair[] {
48                 new StringIntPair("", ClassNameTextField.STATUS_BEFORE_PART),
49                 new StringIntPair("A", ClassNameTextField.STATUS_VALID),
50                 new StringIntPair("abc", ClassNameTextField.STATUS_VALID),
51                 new StringIntPair("Abc", ClassNameTextField.STATUS_VALID),
52                 new StringIntPair("abc2", ClassNameTextField.STATUS_VALID),
53                 new StringIntPair("Abc2", ClassNameTextField.STATUS_VALID),
54                 new StringIntPair("a2", ClassNameTextField.STATUS_VALID),
55                 new StringIntPair("A2", ClassNameTextField.STATUS_VALID),
56                 new StringIntPair("abc2.", ClassNameTextField.STATUS_BEFORE_PART),
57                 new StringIntPair("Abc2.", ClassNameTextField.STATUS_BEFORE_PART),
58                 new StringIntPair("a2.", ClassNameTextField.STATUS_BEFORE_PART),
59                 new StringIntPair("A2.", ClassNameTextField.STATUS_BEFORE_PART),
60                 new StringIntPair("2a", ClassNameTextField.STATUS_INVALID),
61                 new StringIntPair("2A", ClassNameTextField.STATUS_INVALID),
62                 new StringIntPair("2a.", ClassNameTextField.STATUS_INVALID),
63                 new StringIntPair("2A.", ClassNameTextField.STATUS_INVALID),
64                 new StringIntPair("A.B", ClassNameTextField.STATUS_VALID),
65                 new StringIntPair("a.B", ClassNameTextField.STATUS_VALID),
66                 new StringIntPair("A.b", ClassNameTextField.STATUS_VALID),
67                 new StringIntPair("a.b", ClassNameTextField.STATUS_VALID),
68                 new StringIntPair("A2.b", ClassNameTextField.STATUS_VALID),
69                 new StringIntPair("a2.b", ClassNameTextField.STATUS_VALID),
70                 new StringIntPair("A.b2", ClassNameTextField.STATUS_VALID),
71                 new StringIntPair("a.b2", ClassNameTextField.STATUS_VALID),
72         };
73         assertEquals(
74                 "check determined status if no text is passed",
75                 ClassNameTextField.STATUS_BEFORE_PART,
76                 new ClassNameTextField().determineStatus());
77         for (int i = 0; i < testData.length; i++) {
78             assertEquals(
79                     "check determined status for text \"" + testData[i].str + '"',
80                     testData[i].value,
81                     new ClassNameTextField(testData[i].str).determineStatus());
82         }
83     }
84
85     /**
86      * Test of getStatus method, of class org.netbeans.modules.junit.ClassNameTextField.
87      */

88     public void testGetStatus() {
89         StringIntPair[] testData = new StringIntPair[] {
90                 new StringIntPair("", ClassNameTextField.STATUS_EMPTY),
91                 new StringIntPair("A", ClassNameTextField.STATUS_VALID),
92                 new StringIntPair("abc", ClassNameTextField.STATUS_VALID),
93                 new StringIntPair("Abc", ClassNameTextField.STATUS_VALID),
94                 new StringIntPair("abc2", ClassNameTextField.STATUS_VALID),
95                 new StringIntPair("Abc2", ClassNameTextField.STATUS_VALID),
96                 new StringIntPair("a2", ClassNameTextField.STATUS_VALID),
97                 new StringIntPair("A2", ClassNameTextField.STATUS_VALID),
98                 new StringIntPair("abc2.", ClassNameTextField.STATUS_INVALID),
99                 new StringIntPair("Abc2.", ClassNameTextField.STATUS_INVALID),
100                 new StringIntPair("a2.", ClassNameTextField.STATUS_INVALID),
101                 new StringIntPair("A2.", ClassNameTextField.STATUS_INVALID),
102                 new StringIntPair("2a", ClassNameTextField.STATUS_INVALID),
103                 new StringIntPair("2A", ClassNameTextField.STATUS_INVALID),
104                 new StringIntPair("2a.", ClassNameTextField.STATUS_INVALID),
105                 new StringIntPair("2A.", ClassNameTextField.STATUS_INVALID),
106                 new StringIntPair("A.B", ClassNameTextField.STATUS_VALID),
107                 new StringIntPair("a.B", ClassNameTextField.STATUS_VALID),
108                 new StringIntPair("A.b", ClassNameTextField.STATUS_VALID),
109                 new StringIntPair("a.b", ClassNameTextField.STATUS_VALID),
110                 new StringIntPair("A2.b", ClassNameTextField.STATUS_VALID),
111                 new StringIntPair("a2.b", ClassNameTextField.STATUS_VALID),
112                 new StringIntPair("A.b2", ClassNameTextField.STATUS_VALID),
113                 new StringIntPair("a.b2", ClassNameTextField.STATUS_VALID),
114         };
115         assertEquals(
116                 "check status if no parameter passed",
117                 ClassNameTextField.STATUS_EMPTY,
118                 new ClassNameTextField().getStatus());
119         for (int i = 0; i < testData.length; i++) {
120             assertEquals(
121                     "check status for text \"" + testData[i].str + '"',
122                     testData[i].value,
123                     new ClassNameTextField(testData[i].str).getStatus());
124         }
125     }
126
127 }
128
Popular Tags