1 19 20 package org.netbeans.modules.java.j2seproject.queries; 21 22 import java.net.URL ; 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 42 public class UnitTestForSourceQueryImplTest extends NbTestCase { 43 44 public UnitTestForSourceQueryImplTest(String 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 { 58 super.setUp(); 59 TestUtil.setLookup(new Object [] { 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")); 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 { 76 scratch = null; 77 projdir = null; 78 pm = null; 79 super.tearDown(); 80 } 81 82 public void testFindUnitTest() throws Exception { 83 URL u = UnitTestForSourceQuery.findUnitTest(projdir); 84 assertNull(u); 85 86 u = UnitTestForSourceQuery.findUnitTest(sources); 87 assertNotNull(u); 88 URL 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 result = tests.getURL(); 100 tests.delete(); 101 u = UnitTestForSourceQuery.findUnitTest (sources); 102 assertEquals (result, u); 103 } 104 105 public void testFindUnitTestMultiRoots () throws Exception { 106 FileObject newRoot = SourceRootsTest.addSourceRoot(helper,projdir,"src.other.dir","other"); 107 URL [] 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 |