KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > api > sql > SQLKeywordsTest


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.db.api.sql;
21
22 import junit.framework.*;
23
24 /**
25  * Tests the SQLKeyword class, that is, it ensures that the is.*Keyword()
26  * methods return true for all keywords. Hopefull this will catch someone
27  * making the keyword lists not correctly ordered when adding a
28  * possibly forgotten keyword.
29  *
30  * @author Andrei Badea
31  */

32 public class SQLKeywordsTest extends TestCase {
33
34     public SQLKeywordsTest(String JavaDoc testName) {
35         super(testName);
36     }
37
38     public void testIsSQL99ReservedKeyword() {
39         for (int i = 0; i < SQLKeywords.SQL99_RESERVED.length; i++) {
40             String JavaDoc identifier = SQLKeywords.SQL99_RESERVED[i].toUpperCase();
41             assertTrue(identifier + " should be a reserved keyword", SQLKeywords.isSQL99ReservedKeyword(identifier));
42             identifier = identifier.toLowerCase();
43             assertTrue(identifier + " should be a reserved keyword", SQLKeywords.isSQL99ReservedKeyword(identifier));
44         }
45
46         // should return null for non-keywords
47
assertFalse(SQLKeywords.isSQL99ReservedKeyword("FOOBAR"));
48
49         // null identifier should throw NPE
50
try {
51             SQLKeywords.isSQL99ReservedKeyword(null);
52             fail("Should have thrown NullPointerException");
53         } catch (NullPointerException JavaDoc e) { }
54     }
55
56     public void testIsSQL99NonReservedKeyword() {
57         for (int i = 0; i < SQLKeywords.SQL99_NON_RESERVED.length; i++) {
58             String JavaDoc identifier = SQLKeywords.SQL99_NON_RESERVED[i].toUpperCase();
59             assertTrue(identifier + " should be a non-reserved keyword", SQLKeywords.isSQL99NonReservedKeyword(identifier));
60             identifier = identifier.toLowerCase();
61             assertTrue(identifier + " should be a non-reserved keyword", SQLKeywords.isSQL99NonReservedKeyword(identifier));
62         }
63
64         // should return null for non-keywords
65
assertFalse(SQLKeywords.isSQL99NonReservedKeyword("FOOBAR"));
66
67         // null identifier should throw NPE
68
try {
69             SQLKeywords.isSQL99NonReservedKeyword(null);
70             fail("Should have thrown NullPointerException");
71         } catch (NullPointerException JavaDoc e) { }
72     }
73
74     public void testIsSQL99Keyword() {
75         for (int i = 0; i < SQLKeywords.SQL99_RESERVED.length; i++) {
76             String JavaDoc identifier = SQLKeywords.SQL99_RESERVED[i].toUpperCase();
77             assertTrue(identifier + " should be a keyword", SQLKeywords.isSQL99Keyword(identifier));
78             identifier = identifier.toLowerCase();
79             assertTrue(identifier + " should be a keyword", SQLKeywords.isSQL99Keyword(identifier));
80         }
81         for (int i = 0; i < SQLKeywords.SQL99_NON_RESERVED.length; i++) {
82             String JavaDoc identifier = SQLKeywords.SQL99_RESERVED[i].toUpperCase();
83             assertTrue(identifier + " should be a keyword", SQLKeywords.isSQL99Keyword(identifier));
84             identifier = identifier.toLowerCase();
85             assertTrue(identifier + " should be a keyword", SQLKeywords.isSQL99Keyword(identifier));
86         }
87
88         // should return null for non-keywords
89
assertFalse(SQLKeywords.isSQL99Keyword("FOOBAR"));
90
91         // null identifier should throw NPE
92
try {
93             SQLKeywords.isSQL99Keyword(null);
94             fail("Should have thrown NullPointerException");
95         } catch (NullPointerException JavaDoc e) { }
96     }
97 }
98
Popular Tags