1 19 20 package org.netbeans.modules.java.j2seproject.queries; 21 22 import java.io.IOException ; 23 import org.netbeans.api.java.queries.BinaryForSourceQuery; 24 import org.netbeans.api.project.Project; 25 import org.netbeans.api.project.ProjectManager; 26 import org.netbeans.junit.NbTestCase; 27 import org.netbeans.modules.java.j2seproject.J2SEProjectGenerator; 28 import org.openide.filesystems.FileObject; 29 import org.netbeans.api.project.TestUtil; 30 import org.netbeans.spi.project.support.ant.AntProjectHelper; 31 import org.openide.filesystems.FileUtil; 32 import org.openide.modules.SpecificationVersion; 33 import org.openide.util.Lookup; 34 35 40 public class BinaryForSourceQueryImplTest extends NbTestCase { 41 42 public BinaryForSourceQueryImplTest(String testName) { 43 super(testName); 44 } 45 46 private FileObject scratch; 47 private FileObject projdir; 48 private FileObject sources; 49 private FileObject buildClasses; 50 private ProjectManager pm; 51 private Project pp; 52 AntProjectHelper helper; 53 54 protected void setUp() throws Exception { 55 super.setUp(); 56 } 57 58 protected void tearDown() throws Exception { 59 scratch = null; 60 projdir = null; 61 pm = null; 62 TestUtil.setLookup(Lookup.EMPTY); 63 super.tearDown(); 64 } 65 66 67 private void prepareProject () throws IOException { 68 scratch = TestUtil.makeScratchDir(this); 69 projdir = scratch.createFolder("proj"); 70 J2SEProjectGenerator.setDefaultSourceLevel(new SpecificationVersion ("1.4")); helper = J2SEProjectGenerator.createProject(FileUtil.toFile(projdir),"proj",null,null); 72 J2SEProjectGenerator.setDefaultSourceLevel(null); pm = ProjectManager.getDefault(); 74 pp = pm.findProject(projdir); 75 sources = projdir.getFileObject("src"); 76 FileObject fo = projdir.createFolder("build"); 77 buildClasses = fo.createFolder("classes"); 78 } 79 80 public void testBinaryForSourceQuery() throws Exception { 81 this.prepareProject(); 82 FileObject folder = scratch.createFolder("SomeFolder"); 83 BinaryForSourceQuery.Result result = BinaryForSourceQuery.findBinaryRoots(folder.getURL()); 84 assertEquals("Non-project folder does not have any source folder", 0, result.getRoots().length); 85 folder = projdir.createFolder("SomeFolderInProject"); 86 result = BinaryForSourceQuery.findBinaryRoots(folder.getURL()); 87 assertEquals("Project non build folder does not have any source folder", 0, result.getRoots().length); 88 result = BinaryForSourceQuery.findBinaryRoots(sources.getURL()); 89 assertEquals("Project build folder must have source folder", 1, result.getRoots().length); 90 assertEquals("Project build folder must have source folder",buildClasses.getURL(),result.getRoots()[0]); 91 assertEquals(BinaryForSourceQueryImpl.R.class, result.getClass()); 92 BinaryForSourceQuery.Result result2 = BinaryForSourceQuery.findBinaryRoots(sources.getURL()); 93 assertTrue (result == result2); 94 } 95 96 } 97 | Popular Tags |