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:
037: package edu.rice.cs.drjava.model.javadoc;
038:
039: import edu.rice.cs.drjava.DrJavaTestCase;
040: import edu.rice.cs.drjava.model.GlobalModel;
041: import edu.rice.cs.drjava.model.DummyGlobalModel;
042: import edu.rice.cs.drjava.model.OpenDefinitionsDocument;
043: import edu.rice.cs.drjava.model.DummyOpenDefDoc;
044: import edu.rice.cs.drjava.model.definitions.InvalidPackageException;
045:
046: import java.io.File;
047:
048: /**
049: * Tests the functionality provided by an implementation of JavadocModel.
050: * For now, this class is hard-coded to test DefaultJavadocModel, but it can be
051: * extended to test any implementation of the interface.
052: * @version $Id: JavadocModelTest.java 4255 2007-08-28 19:17:37Z mgricken $
053: */
054: public class JavadocModelTest extends DrJavaTestCase {
055:
056: /** Field needed by testUnsavedSuggestedDirectory */
057: private File _storedFile;
058:
059: /** Tests that a simple suggestion can be made for the destination directory. */
060: public void testSimpleSuggestedDirectory() {
061: GlobalModel getDocs = new DummyGlobalModel() {
062: public boolean hasModifiedDocuments() {
063: return false; // pretend all docs are saved
064: }
065:
066: public boolean hasUntitledDocuments() {
067: return false; // pretend no docs are untitled
068: }
069: };
070: // TODO: define so that tools.jar doesn't need to be on the class path
071: JavadocModel jModel = new DefaultJavadocModel(getDocs, null,
072: GlobalModel.RUNTIME_CLASS_PATH);
073: final File file = new File(System.getProperty("user.dir"));
074: OpenDefinitionsDocument doc = new DummyOpenDefDoc() {
075: public File getSourceRoot() throws InvalidPackageException {
076: return file;
077: }
078: };
079:
080: File suggestion = jModel.suggestJavadocDestination(doc);
081: File expected = new File(file, JavadocModel.SUGGESTED_DIR_NAME);
082: assertEquals("simple suggested destination", expected,
083: suggestion);
084: }
085:
086: /** Tests that a suggestion can be made for an unsaved file, if the user chooses to save it. */
087: public void testUnsavedSuggestedDirectory() {
088: _storedFile = null;
089:
090: GlobalModel getDocs = new DummyGlobalModel() {
091: public boolean hasModifiedDocuments() {
092: return true; // pretend doc is unsaved
093: }
094: };
095: JavadocModel jModel = new DefaultJavadocModel(getDocs, null,
096: GlobalModel.RUNTIME_CLASS_PATH);
097: final File file = new File(System.getProperty("user.dir"));
098:
099: // Make sure it doesn't return a file until it's saved.
100: JavadocListener listener = new JavadocListener() {
101: public void saveBeforeJavadoc() {
102: _storedFile = file;
103: }
104:
105: public void javadocStarted() {
106: }
107:
108: public void javadocEnded(boolean success, File destDir,
109: boolean allDocs) {
110: }
111: };
112: jModel.addListener(listener);
113:
114: OpenDefinitionsDocument doc = new DummyOpenDefDoc() {
115: public File getSourceRoot() throws InvalidPackageException {
116: return _storedFile;
117: }
118: };
119:
120: File suggestion = jModel.suggestJavadocDestination(doc);
121: File expected = new File(file, JavadocModel.SUGGESTED_DIR_NAME);
122: assertEquals("simple suggested destination", expected,
123: suggestion);
124: }
125:
126: /** Tests that a no suggestion can be made for the destination directory if there is no valid source root. */
127: public void testNoSuggestedDirectory() {
128: GlobalModel getDocs = new DummyGlobalModel() {
129: public boolean hasModifiedDocuments() {
130: return false; /* pretend all docs are saved */
131: }
132:
133: public boolean hasUntitledDocuments() {
134: return false; /* pretend no docs are untitled */
135: }
136: };
137: JavadocModel jModel = new DefaultJavadocModel(getDocs, null,
138: null);
139: // final File file = new File(System.getProperty("user.dir"));
140: OpenDefinitionsDocument doc = new DummyOpenDefDoc() {
141: public File getSourceRoot() throws InvalidPackageException {
142: throw new InvalidPackageException(-1, "invalid package");
143: }
144: };
145:
146: File suggestion = jModel.suggestJavadocDestination(doc);
147: assertNull("suggestion should be null", suggestion);
148: }
149:
150: public void testFileDefaultPackage() {
151: }
152:
153: public void testFileOnePackage() {
154: }
155:
156: public void testFilesOnePackage() {
157: }
158:
159: public void testFilesMultiplePackages() {
160: }
161:
162: public void testWarnings() {
163: }
164:
165: public void testErrors() {
166: }
167:
168: public void testSaveFirst() {
169: }
170:
171: public void testPromptForDestination() {
172: }
173:
174: public void testExtractErrors() {
175: }
176:
177: public void testParseLine() {
178: }
179:
180: /** Be sure to test: -tag require:a:"Require:" */
181: public void testCustomArguments() {
182: }
183: }
|