1 19 20 package org.netbeans.modules.project.ant; 21 22 import java.lang.reflect.Method ; 23 import org.netbeans.api.project.Project; 24 import org.netbeans.api.project.ProjectManager; 25 import org.netbeans.api.project.TestUtil; 26 import org.netbeans.junit.NbTestCase; 27 import org.netbeans.spi.project.support.ant.AntBasedProjectType; 28 import org.netbeans.spi.project.support.ant.AntBasedTestUtil; 29 import org.netbeans.spi.project.support.ant.AntProjectHelper; 30 import org.netbeans.spi.project.support.ant.AntProjectHelperTest; 31 import org.openide.filesystems.FileObject; 32 import org.openide.util.lookup.Lookups; 33 34 38 public class AntBasedProjectFactorySingletonTest extends NbTestCase { 39 40 public AntBasedProjectFactorySingletonTest(String testName) { 41 super(testName); 42 } 43 44 private FileObject scratch; 45 private FileObject projdir; 46 47 protected void setUp() throws Exception { 48 scratch = TestUtil.makeScratchDir(this); 49 projdir = scratch.createFolder("proj"); 50 TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/project.xml"), projdir, "nbproject/project.xml"); 51 TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/private.xml"), projdir, "nbproject/private/private.xml"); 52 TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/project.properties"), projdir, "nbproject/project.properties"); 53 TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/private.properties"), projdir, "nbproject/private/private.properties"); 54 TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/global.properties"), scratch, "userdir/build.properties"); 55 TestUtil.setLookup(new Object [] { 56 AntBasedTestUtil.testAntBasedProjectType(), 57 }); 58 } 59 60 62 public void testAntBasedProjectTypesChanged() throws Exception { 63 AntBasedProjectFactorySingleton factory = new AntBasedProjectFactorySingleton(); 64 AntBasedProjectType type1 = AntBasedTestUtil.testAntBasedProjectType(); 65 AntBasedProjectType type2 = AntBasedTestUtil.testAntBasedProjectType(); 66 67 TestUtil.setLookup(Lookups.fixed(new Object [] { 68 factory, 69 type1, 70 type2, 71 })); 72 73 Method getAntBasedProjectTypeMethod = AntProjectHelper.class.getDeclaredMethod("getType", new Class [0]); 74 75 getAntBasedProjectTypeMethod.setAccessible(true); 76 77 Project p = ProjectManager.getDefault().findProject(projdir); 78 AntProjectHelper helper = p.getLookup().lookup(AntProjectHelper.class); 79 80 assertTrue(getAntBasedProjectTypeMethod.invoke(helper) == type2); 81 82 TestUtil.setLookup(Lookups.fixed(new Object [] { 83 factory, 84 type1, 85 })); 86 87 p = ProjectManager.getDefault().findProject(projdir); 88 helper = p.getLookup().lookup(AntProjectHelper.class); 89 90 assertTrue(getAntBasedProjectTypeMethod.invoke(helper) == type1); 91 92 TestUtil.setLookup(Lookups.fixed(new Object [] { 93 factory, 94 type2, 95 })); 96 97 p = ProjectManager.getDefault().findProject(projdir); 98 helper = p.getLookup().lookup(AntProjectHelper.class); 99 100 assertTrue(getAntBasedProjectTypeMethod.invoke(helper) == type2); 101 102 TestUtil.setLookup(Lookups.fixed(new Object [] { 103 factory, 104 })); 105 106 assertNull(ProjectManager.getDefault().findProject(projdir)); 107 108 TestUtil.setLookup(Lookups.fixed(new Object [] { 109 factory, 110 type1, 111 type2, 112 })); 113 114 assertTrue(getAntBasedProjectTypeMethod.invoke(helper) == type2); 115 } 116 117 } 118 | Popular Tags |