KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > ClassAndInterfaceFinderTest


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project:
4  * http://sourceforge.net/projects/drjava/ or http://www.drjava.org/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2003 JavaPLT group at Rice University (javaplt@rice.edu)
9  * All rights reserved.
10  *
11  * Developed by: Java Programming Languages Team
12  * Rice University
13  * http://www.cs.rice.edu/~javaplt/
14  *
15  * Permission is hereby granted, free of charge, to any person obtaining a
16  * copy of this software and associated documentation files (the "Software"),
17  * to deal with the Software without restriction, including without
18  * limitation the rights to use, copy, modify, merge, publish, distribute,
19  * sublicense, and/or sell copies of the Software, and to permit persons to
20  * whom the Software is furnished to do so, subject to the following
21  * conditions:
22  *
23  * - Redistributions of source code must retain the above copyright
24  * notice, this list of conditions and the following disclaimers.
25  * - Redistributions in binary form must reproduce the above copyright
26  * notice, this list of conditions and the following disclaimers in the
27  * documentation and/or other materials provided with the distribution.
28  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the
29  * names of its contributors may be used to endorse or promote products
30  * derived from this Software without specific prior written permission.
31  * - Products derived from this software may not be called "DrJava" nor
32  * use the term "DrJava" as part of their names without prior written
33  * permission from the JavaPLT group. For permission, write to
34  * javaplt@rice.edu.
35  *
36  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
39  * THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
40  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
41  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
42  * OTHER DEALINGS WITH THE SOFTWARE.
43  *
44  END_COPYRIGHT_BLOCK*/

45
46 package edu.rice.cs.drjava.model;
47 import edu.rice.cs.drjava.DrJavaTestCase;
48
49 import java.io.Reader JavaDoc;
50 import java.io.StringReader JavaDoc;
51
52 /**
53  * ClassAndInterfaceFinderTest for unit testing ClassAndInterfaceFinder. Uses
54  * junit for testing.
55  *
56  * @author <a HREF="mailto:jasonbs@rice.edu">Jason Schiller</a>
57  * @version $Id: ClassAndInterfaceFinderTest.java 3521 2006-02-10 21:39:52Z mgricken $
58  */

59
60 public class ClassAndInterfaceFinderTest extends DrJavaTestCase {
61   
62   
63   /**
64    * Tests to see if string input is properly parsed to obtain interface name.
65    */

66   public void testStringInterfaceRecognition() {
67     try {
68       Reader JavaDoc r = new StringReader JavaDoc("//\n /**/public Class Interface interface Aa.12_34 {}");
69       ClassAndInterfaceFinder finder = new ClassAndInterfaceFinder(r);
70       String JavaDoc s = finder.getClassOrInterfaceName();
71       assertEquals("stringInterfaceRecognition","Aa.12_34", s);
72     }
73     catch (Exception JavaDoc e) {
74       fail("stringInterfaceRecognition threw "+e);
75     }
76   }
77   
78   
79   /**
80    * Tests to see if string input is properly parsed to reject interface name.
81    */

82   public void testStringInterfaceRejection() {
83     try {
84       Reader JavaDoc r = new StringReader JavaDoc("//\n /**/public Class Interface interface Aa.12_34 {}");
85       ClassAndInterfaceFinder finder = new ClassAndInterfaceFinder(r);
86       String JavaDoc s = finder.getClassName();
87       assertEquals("stringInterfaceRejection","", s);
88     }
89     catch (Exception JavaDoc e) {
90       fail("stringInterfaceRejection threw "+ e);
91     }
92   }
93   
94   
95   /**
96    * Tests to see if string input is properly parsed to obtain class name.
97    */

98   public void testStringClassRecognition() {
99     try {
100       Reader JavaDoc r = new StringReader JavaDoc("//\n /**/public Class Interface class Aa.12_34 {}");
101       ClassAndInterfaceFinder finder = new ClassAndInterfaceFinder(r);
102       String JavaDoc s = finder.getClassOrInterfaceName();
103       assertEquals("stringNameRecognition","Aa.12_34", s);
104     }
105     catch (Exception JavaDoc e) {
106       fail("stringClassRecognition threw " +e);
107     }
108   }
109   
110   /**
111    * Tests to see if string input is properly parsed to insert package name.
112    */

113   public void testStringPackageRecognition() {
114     try {
115       Reader JavaDoc r = new StringReader JavaDoc("//\n /**/package x public interface Aa.12_34 {}");
116       ClassAndInterfaceFinder finder = new ClassAndInterfaceFinder(r);
117       String JavaDoc s = finder.getClassOrInterfaceName();
118       assertEquals("stringNameRecognition","x.Aa.12_34", s);
119     }
120     catch (Exception JavaDoc e) {
121       fail("stringPackageRecognition threw " + e);
122     }
123   }
124   
125   
126 }
127
Popular Tags