KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seproject > 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.java.j2seproject.queries;
21
22 import java.net.URL JavaDoc;
23 import org.netbeans.api.java.queries.UnitTestForSourceQuery;
24 import org.netbeans.api.project.Project;
25 import org.netbeans.api.project.ProjectManager;
26 import org.netbeans.api.project.TestUtil;
27 import org.netbeans.junit.NbTestCase;
28 import org.netbeans.modules.java.j2seproject.J2SEProjectGenerator;
29 import org.netbeans.modules.java.j2seproject.SourceRootsTest;
30 import org.netbeans.spi.project.support.ant.AntProjectHelper;
31 import org.openide.filesystems.FileObject;
32 import org.openide.filesystems.FileUtil;
33 import org.openide.filesystems.URLMapper;
34 import org.openide.modules.SpecificationVersion;
35 import org.openide.util.Lookup;
36
37 /**
38  * Tests for UnitTestForSourceQueryImpl
39  *
40  * @author David Konecny
41  */

42 public class UnitTestForSourceQueryImplTest extends NbTestCase {
43     
44     public UnitTestForSourceQueryImplTest(String JavaDoc testName) {
45         super(testName);
46     }
47     
48     private FileObject scratch;
49     private FileObject projdir;
50     private ProjectManager pm;
51     private FileObject sources;
52     private FileObject tests;
53     private AntProjectHelper helper;
54
55     Project pp;
56     
57     protected void setUp() throws Exception JavaDoc {
58         super.setUp();
59         TestUtil.setLookup(new Object JavaDoc[] {
60             new org.netbeans.modules.java.j2seproject.J2SEProjectType(),
61             new org.netbeans.modules.java.project.UnitTestForSourceQueryImpl(),
62             new org.netbeans.modules.projectapi.SimpleFileOwnerQueryImplementation()
63         });
64         scratch = TestUtil.makeScratchDir(this);
65         projdir = scratch.createFolder("proj");
66         J2SEProjectGenerator.setDefaultSourceLevel(new SpecificationVersion ("1.4")); //NOI18N
67
helper = J2SEProjectGenerator.createProject(FileUtil.toFile(projdir),"proj",null,null);
68         J2SEProjectGenerator.setDefaultSourceLevel(null);
69         sources = projdir.getFileObject("src");
70         tests = projdir.getFileObject("test");
71         pm = ProjectManager.getDefault();
72         pp = pm.findProject(projdir);
73     }
74
75     protected void tearDown() throws Exception JavaDoc {
76         scratch = null;
77         projdir = null;
78         pm = null;
79         super.tearDown();
80     }
81     
82     public void testFindUnitTest() throws Exception JavaDoc {
83         URL JavaDoc u = UnitTestForSourceQuery.findUnitTest(projdir);
84         assertNull(u);
85         
86         u = UnitTestForSourceQuery.findUnitTest(sources);
87         assertNotNull(u);
88         URL JavaDoc result = URLMapper.findURL(tests, URLMapper.EXTERNAL);
89         assertNotNull(result);
90         assertEquals(result, u);
91         
92         u = UnitTestForSourceQuery.findSource(tests);
93         assertNotNull(u);
94         result = URLMapper.findURL(sources, URLMapper.EXTERNAL);
95         assertNotNull(result);
96         assertEquals(result, u);
97         
98         //Test the case when the tests folder does not exist
99
result = tests.getURL();
100         tests.delete();
101         u = UnitTestForSourceQuery.findUnitTest (sources);
102         assertEquals (result, u);
103     }
104
105     public void testFindUnitTestMultiRoots () throws Exception JavaDoc {
106         FileObject newRoot = SourceRootsTest.addSourceRoot(helper,projdir,"src.other.dir","other");
107         URL JavaDoc[] urls = UnitTestForSourceQuery.findSources(tests);
108         assertNotNull(urls);
109         assertEquals(2,urls.length);
110         assertEquals(sources.getURL(), urls[0]);
111         assertEquals(newRoot.getURL(), urls[1]);
112     }
113
114 }
115
Popular Tags