001: /*BEGIN_COPYRIGHT_BLOCK
002: *
003: * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are met:
008: * * Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * * Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014: * names of its contributors may be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: *
029: * This software is Open Source Initiative approved Open Source Software.
030: * Open Source Initative Approved is a trademark of the Open Source Initiative.
031: *
032: * This file is part of DrJava. Download the current version of this project
033: * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034: *
035: * END_COPYRIGHT_BLOCK*/
036: package edu.rice.cs.drjava.model;
037:
038: import edu.rice.cs.drjava.DrJavaTestCase;
039:
040: import java.io.Reader;
041: import java.io.StringReader;
042:
043: /**
044: * ClassAndInterfaceFinderTest for unit testing ClassAndInterfaceFinder. Uses
045: * junit for testing.
046: *
047: * @author <a href="mailto:jasonbs@rice.edu">Jason Schiller</a>
048: * @version $Id: ClassAndInterfaceFinderTest.java 4255 2007-08-28 19:17:37Z mgricken $
049: */
050:
051: public class ClassAndInterfaceFinderTest extends DrJavaTestCase {
052:
053: /**
054: * Tests to see if string input is properly parsed to obtain interface name.
055: */
056: public void testStringInterfaceRecognition() {
057: try {
058: Reader r = new StringReader(
059: "//\n /**/public Class Interface interface Aa.12_34 {}");
060: ClassAndInterfaceFinder finder = new ClassAndInterfaceFinder(
061: r);
062: String s = finder.getClassOrInterfaceName();
063: assertEquals("stringInterfaceRecognition", "Aa.12_34", s);
064: } catch (Exception e) {
065: fail("stringInterfaceRecognition threw " + e);
066: }
067: }
068:
069: /**
070: * Tests to see if string input is properly parsed to reject interface name.
071: */
072: public void testStringInterfaceRejection() {
073: try {
074: Reader r = new StringReader(
075: "//\n /**/public Class Interface interface Aa.12_34 {}");
076: ClassAndInterfaceFinder finder = new ClassAndInterfaceFinder(
077: r);
078: String s = finder.getClassName();
079: assertEquals("stringInterfaceRejection", "", s);
080: } catch (Exception e) {
081: fail("stringInterfaceRejection threw " + e);
082: }
083: }
084:
085: /**
086: * Tests to see if string input is properly parsed to obtain class name.
087: */
088: public void testStringClassRecognition() {
089: try {
090: Reader r = new StringReader(
091: "//\n /**/public Class Interface class Aa.12_34 {}");
092: ClassAndInterfaceFinder finder = new ClassAndInterfaceFinder(
093: r);
094: String s = finder.getClassOrInterfaceName();
095: assertEquals("stringNameRecognition", "Aa.12_34", s);
096: } catch (Exception e) {
097: fail("stringClassRecognition threw " + e);
098: }
099: }
100:
101: /**
102: * Tests to see if string input is properly parsed to insert package name.
103: */
104: public void testStringPackageRecognition() {
105: try {
106: Reader r = new StringReader(
107: "//\n /**/package x public interface Aa.12_34 {}");
108: ClassAndInterfaceFinder finder = new ClassAndInterfaceFinder(
109: r);
110: String s = finder.getClassOrInterfaceName();
111: assertEquals("stringNameRecognition", "x.Aa.12_34", s);
112: } catch (Exception e) {
113: fail("stringPackageRecognition threw " + e);
114: }
115: }
116:
117: }
|