KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javacore > parsing > ParserErrorsTest


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 package org.netbeans.modules.javacore.parsing;
20
21 import java.util.List JavaDoc;
22
23 import junit.textui.TestRunner;
24 import org.netbeans.jmi.javamodel.*;
25 import org.netbeans.jmi.javamodel.codegen.Utility;
26 import org.netbeans.junit.NbTestCase;
27 import org.netbeans.junit.NbTestSuite;
28
29 /**
30  * @author Jan Becicka
31  */

32 public class ParserErrorsTest extends NbTestCase {
33
34     /** Need to be defined because of JUnit */
35     public ParserErrorsTest(String JavaDoc name) {
36         super(name);
37
38     }
39
40     public static NbTestSuite suite() {
41         NbTestSuite suite = new NbTestSuite();
42         suite.addTest(new ParserErrorsTest("testSyntaxErrors"));
43         suite.addTest(new ParserErrorsTest("testSemanticErrors"));
44 // suite.addTest(new ParserErrorsTest("testWarnings"));
45
return suite;
46     }
47     
48     /** Use for execution inside IDE */
49     public static void main(java.lang.String JavaDoc[] args) {
50         TestRunner.run(suite());
51     }
52
53     protected void setUp() {
54     }
55     
56     public void testSyntaxErrors() {
57         JavaClass clazz = Utility.findClass("org.netbeans.test.parser.SyntaxError");
58         Resource res = clazz.getResource();
59         List JavaDoc errors = res.getErrors();
60         assertEquals(1, errors.size());
61         ErrorInfo error = (ErrorInfo) errors.iterator().next();
62         assertEquals(9, error.getLineNumber());
63         assertEquals("';' expected", error.getDescription());
64         assertEquals(ErrorTypeEnum.ERROR, error.getSeverity());
65         assertEquals(12, error.getColumn());
66     }
67     
68     public void testSemanticErrors() {
69         JavaClass clazz = Utility.findClass("org.netbeans.test.parser.SemanticError");
70         Resource res = clazz.getResource();
71         List JavaDoc errors = res.getErrors();
72         assertEquals(1, errors.size());
73         ErrorInfo error = (ErrorInfo) errors.iterator().next();
74         assertEquals(7, error.getLineNumber());
75 // assertEquals("cannot find symbol symbol : class JFrame location: class org.netbeans.test.parser.SemanticError", error.getDescription());
76
assertEquals(ErrorTypeEnum.ERROR, error.getSeverity());
77         assertEquals(13, error.getColumn());
78     }
79     
80 // public void testWarnings() {
81
// JavaClass clazz = Utility.findClass("org.netbeans.test.parser.Warning");
82
// Resource res = clazz.getResource();
83
// List errors = res.getErrors();
84
// assertEquals(1, errors.size());
85
// ErrorInfo error = (ErrorInfo) errors.iterator().next();
86
// assertEquals(0, error.getLineNumber());
87
// assertEquals(null, error.getDescription());
88
// assertEquals(ErrorTypeEnum.ERROR, error.getSeverity());
89
// assertEquals(0, error.getColumn());
90
// }
91

92 }
93
Popular Tags