KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > freeform > JavadocQueryTest


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
20 package org.netbeans.modules.java.freeform;
21
22 import java.net.URL JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.List JavaDoc;
26 import org.netbeans.api.java.queries.JavadocForBinaryQuery;
27 import org.netbeans.modules.ant.freeform.TestBase;
28 import org.openide.filesystems.FileUtil;
29
30 /**
31  * Tests Javadoc reporting.
32  * @author Jesse Glick
33  */

34 public class JavadocQueryTest extends TestBase {
35
36     public JavadocQueryTest(String JavaDoc name) {
37         super(name);
38     }
39
40     private URL JavaDoc classes1Dir, classes1Jar, classes2Dir, javadoc1Dir, javadoc2Zip;
41     
42     protected void setUp() throws Exception JavaDoc {
43         super.setUp();
44         classes1Dir = asDir("classes1");
45         classes1Jar = asJar("classes1.jar");
46         classes2Dir = asDir("classes2");
47         javadoc1Dir = asDir("javadoc1");
48         javadoc2Zip = asJar("javadoc2.zip");
49     }
50     
51     private URL JavaDoc asDir(String JavaDoc path) throws Exception JavaDoc {
52         URL JavaDoc u = simple2.helper().resolveFile(path).toURI().toURL();
53         String JavaDoc us = u.toExternalForm();
54         if (us.endsWith("/")) {
55             return u;
56         } else {
57             return new URL JavaDoc(us + "/");
58         }
59     }
60     
61     private URL JavaDoc asJar(String JavaDoc path) throws Exception JavaDoc {
62         return FileUtil.getArchiveRoot(simple2.helper().resolveFile(path).toURI().toURL());
63     }
64     
65     private List JavaDoc<URL JavaDoc> javadocFor(URL JavaDoc binary) {
66         return Arrays.asList(JavadocForBinaryQuery.findJavadoc(binary).getRoots());
67     }
68     
69     public void testFindJavadoc() throws Exception JavaDoc {
70         List JavaDoc<URL JavaDoc> both = Arrays.asList(new URL JavaDoc[] {javadoc1Dir, javadoc2Zip});
71         assertEquals("both Javadoc found for " + classes1Dir, both, javadocFor(classes1Dir));
72         assertEquals("both Javadoc found for " + classes1Jar, both, javadocFor(classes1Jar));
73         assertEquals("no Javadoc found for " + classes2Dir, Collections.EMPTY_LIST, javadocFor(classes2Dir));
74     }
75
76     // XXX testChangeFiring?
77

78 }
79
Popular Tags