KickJava   Java API By Example, From Geeks To Geeks.

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


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

33
34 package edu.rice.cs.drjava.model;
35
36 import edu.rice.cs.drjava.DrJavaTestCase;
37 import edu.rice.cs.drjava.model.definitions.InvalidPackageException;
38
39 import java.io.File JavaDoc;
40
41 /**
42  * Tests the functionality provided by an implementation of JavadocModel.
43  * For now, this class is hard-coded to test DefaultJavadocModel, but it can be
44  * extended to test any implementation of the interface.
45  * @version $Id: JavadocModelTest.java 3901 2006-06-30 05:28:11Z rcartwright $
46  */

47 public class JavadocModelTest extends DrJavaTestCase {
48   
49   /** Field needed by testUnsavedSuggestedDirectory */
50   private File JavaDoc _storedFile;
51
52   /** Tests that a simple suggestion can be made for the destination directory. */
53   public void testSimpleSuggestedDirectory() {
54     GlobalModel getDocs = new DummyGlobalModel() {
55       public boolean hasModifiedDocuments() {
56         return false; // pretend all docs are saved
57
}
58       public boolean hasUntitledDocuments() {
59         return false; // pretend no docs are untitled
60
}
61     };
62     JavadocModel jModel = new DefaultJavadocModel(getDocs);
63     final File JavaDoc file = new File JavaDoc(System.getProperty("user.dir"));
64     OpenDefinitionsDocument doc = new DummyOpenDefDoc() {
65       public File JavaDoc getSourceRoot() throws InvalidPackageException { return file; }
66     };
67
68     File JavaDoc suggestion = jModel.suggestJavadocDestination(doc);
69     File JavaDoc expected = new File JavaDoc(file, JavadocModel.SUGGESTED_DIR_NAME);
70     assertEquals("simple suggested destination", expected, suggestion);
71   }
72   
73   /** Tests that a suggestion can be made for an unsaved file, if the user chooses to save it. */
74   public void testUnsavedSuggestedDirectory() {
75     _storedFile = null;
76     
77     GlobalModel getDocs = new DummyGlobalModel() {
78       public boolean hasModifiedDocuments() {
79         return true; // pretend doc is unsaved
80
}
81     };
82     JavadocModel jModel = new DefaultJavadocModel(getDocs);
83     final File JavaDoc file = new File JavaDoc(System.getProperty("user.dir"));
84
85     // Make sure it doesn't return a file until it's saved.
86
JavadocListener listener = new JavadocListener() {
87       public void saveBeforeJavadoc() { _storedFile = file; }
88       public void javadocStarted() { }
89       public void javadocEnded(boolean success, File JavaDoc destDir, boolean allDocs) { }
90     };
91     jModel.addListener(listener);
92     
93     OpenDefinitionsDocument doc = new DummyOpenDefDoc() {
94       public File JavaDoc getSourceRoot() throws InvalidPackageException { return _storedFile; }
95     };
96
97     File JavaDoc suggestion = jModel.suggestJavadocDestination(doc);
98     File JavaDoc expected = new File JavaDoc(file, JavadocModel.SUGGESTED_DIR_NAME);
99     assertEquals("simple suggested destination", expected, suggestion);
100   }
101
102   /** Tests that a no suggestion can be made for the destination directory if there is no valid source root. */
103   public void testNoSuggestedDirectory() {
104     GlobalModel getDocs = new DummyGlobalModel() {
105       public boolean hasModifiedDocuments() { return false; /* pretend all docs are saved */ }
106       public boolean hasUntitledDocuments() { return false; /* pretend no docs are untitled */ }
107     };
108     JavadocModel jModel = new DefaultJavadocModel(getDocs);
109 // final File file = new File(System.getProperty("user.dir"));
110
OpenDefinitionsDocument doc = new DummyOpenDefDoc() {
111       public File JavaDoc getSourceRoot() throws InvalidPackageException {
112         throw new InvalidPackageException(-1, "invalid package");
113       }
114     };
115
116     File JavaDoc suggestion = jModel.suggestJavadocDestination(doc);
117     assertNull("suggestion should be null", suggestion);
118   }
119
120   public void testFileDefaultPackage() { }
121   public void testFileOnePackage() { }
122   public void testFilesOnePackage() { }
123   public void testFilesMultiplePackages() { }
124   public void testWarnings() { }
125   public void testErrors() { }
126   public void testSaveFirst() { }
127   public void testPromptForDestination() { }
128   public void testExtractErrors() { }
129   public void testParseLine() { }
130   /** Be sure to test: -tag require:a:"Require:" */
131   public void testCustomArguments() { }
132 }
133
Popular Tags