KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seproject > queries > BinaryForSourceQueryImplTest


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.j2seproject.queries;
21
22 import java.io.IOException JavaDoc;
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 /**
36  * Tests for BinaryForSourceQueryImpl
37  *
38  * @author Tomas Zezula
39  */

40 public class BinaryForSourceQueryImplTest extends NbTestCase {
41     
42     public BinaryForSourceQueryImplTest(String JavaDoc 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 JavaDoc {
55         super.setUp();
56     }
57
58     protected void tearDown() throws Exception JavaDoc {
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 JavaDoc {
68         scratch = TestUtil.makeScratchDir(this);
69         projdir = scratch.createFolder("proj");
70         J2SEProjectGenerator.setDefaultSourceLevel(new SpecificationVersion ("1.4")); //NOI18N
71
helper = J2SEProjectGenerator.createProject(FileUtil.toFile(projdir),"proj",null,null);
72         J2SEProjectGenerator.setDefaultSourceLevel(null); //NOI18N
73
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 JavaDoc {
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