KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > queries > UnitTestForSourceQueryImplTest


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.apisupport.project.queries;
21
22 import java.net.URI JavaDoc;
23 import java.io.File JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.util.Arrays JavaDoc;
26 import java.util.Collections JavaDoc;
27 import org.netbeans.api.java.queries.UnitTestForSourceQuery;
28 import org.netbeans.modules.apisupport.project.TestBase;
29 import org.openide.filesystems.FileObject;
30 import org.openide.filesystems.URLMapper;
31
32 /**
33  * Test for UnitTestForSourceQuery
34  * @author Tomas Zezula
35  */

36 public class UnitTestForSourceQueryImplTest extends TestBase {
37
38     public UnitTestForSourceQueryImplTest(String JavaDoc testName) {
39         super(testName);
40     }
41
42     public void testFindUnitTest() throws Exception JavaDoc {
43         URL JavaDoc[] testRoots = UnitTestForSourceQuery.findUnitTests(nbCVSRoot());
44         assertEquals("Test root for non project folder should be null", Collections.EMPTY_LIST, Arrays.asList(testRoots));
45         FileObject srcRoot = nbCVSRoot().getFileObject("apisupport/project");
46         testRoots = UnitTestForSourceQuery.findUnitTests(srcRoot);
47         assertEquals("Test root for project should be null", Collections.EMPTY_LIST, Arrays.asList(testRoots));
48         srcRoot = nbCVSRoot().getFileObject("apisupport/project/test/unit/src");
49         testRoots = UnitTestForSourceQuery.findUnitTests(srcRoot);
50         assertEquals("Test root for tests should be null", Collections.EMPTY_LIST, Arrays.asList(testRoots));
51         srcRoot = nbCVSRoot().getFileObject("apisupport/project/src");
52         testRoots = UnitTestForSourceQuery.findUnitTests(srcRoot);
53         assertEquals("Test root defined", 1, testRoots.length);
54         assertTrue("Test root exists", new File JavaDoc(URI.create(testRoots[0].toExternalForm())).exists());
55         assertEquals("Test root", URLMapper.findFileObject(testRoots[0]), nbCVSRoot().getFileObject("apisupport/project/test/unit/src"));
56         assertEquals("One test for this project", 1, UnitTestForSourceQuery.findUnitTests(nbCVSRoot().getFileObject("openide/windows/src")).length);
57     }
58
59     public void testFindSource() {
60         URL JavaDoc[] srcRoots = UnitTestForSourceQuery.findSources(nbCVSRoot());
61         assertEquals("Source root for non project folder should be null", Collections.EMPTY_LIST, Arrays.asList(srcRoots));
62         FileObject testRoot = nbCVSRoot().getFileObject("apisupport/project");
63         srcRoots = UnitTestForSourceQuery.findSources(testRoot);
64         assertEquals("Source root for project should be null", Collections.EMPTY_LIST, Arrays.asList(srcRoots));
65         testRoot = nbCVSRoot().getFileObject("apisupport/project/src");
66         srcRoots = UnitTestForSourceQuery.findSources(testRoot);
67         assertEquals("Source root for sources should be null", Collections.EMPTY_LIST, Arrays.asList(srcRoots));
68         assertEquals("No sources for this project's sources", Collections.EMPTY_LIST, Arrays.asList(UnitTestForSourceQuery.findSources(nbCVSRoot().getFileObject("openide/windows/src"))));
69         testRoot = nbCVSRoot().getFileObject("apisupport/project/test/unit/src");
70         srcRoots = UnitTestForSourceQuery.findSources(testRoot);
71         assertEquals("Source root defined", 1, srcRoots.length);
72         assertTrue("Source root exists", new File JavaDoc(URI.create(srcRoots[0].toExternalForm())).exists());
73         assertEquals("Source root", URLMapper.findFileObject(srcRoots[0]), nbCVSRoot().getFileObject("apisupport/project/src"));
74     }
75     
76 }
77
Popular Tags