1 19 20 package org.netbeans.modules.project.ui; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.io.IOException ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 import org.netbeans.api.project.Project; 28 import org.netbeans.api.project.ProjectManager; 29 import org.netbeans.api.project.TestUtil; 30 import org.netbeans.junit.NbTestCase; 31 import org.openide.filesystems.FileObject; 32 import org.openide.util.Lookup; 33 import org.openide.util.lookup.Lookups; 34 35 public class OpenProjectsTrampolineImplTest extends NbTestCase { 36 37 public OpenProjectsTrampolineImplTest(String name) { 38 super( name ); 39 } 40 41 42 private FileObject scratch; 43 private FileObject goodproject; 44 private FileObject goodproject2; 45 private ProjectManager pm; 48 49 protected void setUp() throws Exception { 50 super.setUp(); 51 scratch = TestUtil.makeScratchDir(this); 52 goodproject = scratch.createFolder("good"); 53 goodproject.createFolder("testproject"); 54 goodproject2 = scratch.createFolder("good2"); 55 goodproject2.createFolder("testproject"); 56 TestUtil.setLookup(Lookups.singleton(TestUtil.testProjectFactory())); 60 pm = ProjectManager.getDefault(); 61 } 62 63 protected void tearDown() throws Exception { 64 scratch = null; 65 goodproject = null; 66 pm = null; 69 TestUtil.setLookup(Lookup.EMPTY); 70 super.tearDown(); 71 } 72 73 public void testOpenProjects() throws Exception { 74 75 OpenProjectsTrampolineImpl trampoline = new OpenProjectsTrampolineImpl(); 76 TestPropertyChangeListener tpchl = new TestPropertyChangeListener(); 77 trampoline.addPropertyChangeListenerAPI( tpchl ); 78 79 Project[] projects = trampoline.getOpenProjectsAPI(); 80 81 assertEquals( "No project should be open.", 0, projects.length ); 82 assertEquals( "No events.", 0, tpchl.getEvents().size() ); 83 84 Project p1 = null; 85 86 try { 87 p1 = pm.findProject( goodproject ); 88 } catch ( IOException e ) { 89 fail("Should not fail to load goodproject: " + e); 90 } 91 92 assertNotNull( "Project should not be null", p1 ); 93 94 OpenProjectList.getDefault().open( p1 ); 95 projects = trampoline.getOpenProjectsAPI(); 96 97 assertEquals( "One project should be open.", 1, projects.length ); 98 assertEquals( "Obe event.", 1, tpchl.getEvents().size() ); 99 100 Project p2 = null; 101 102 try { 103 p2 = pm.findProject( goodproject2 ); 104 } catch ( IOException e ) { 105 fail("Should not fail to load goodproject: " + e); 106 } 107 108 assertNotNull( "Project should not be null", p2 ); 109 110 OpenProjectList.getDefault().open( p2 ); 111 projects = trampoline.getOpenProjectsAPI(); 112 assertEquals( "Two projects should be open.", 2, projects.length ); 113 assertEquals( "Two events.", 2, tpchl.getEvents().size() ); 114 115 OpenProjectList.getDefault().close(new Project[] {p1}, false); 116 projects = trampoline.getOpenProjectsAPI(); 117 assertEquals( "Two projects should be open.", 1, projects.length ); 118 assertEquals( "Two events.", 3, tpchl.getEvents().size() ); 119 120 121 OpenProjectList.getDefault().close(new Project[] {p2}, false); 122 projects = trampoline.getOpenProjectsAPI(); 123 assertEquals( "Two projects should be open.", 0, projects.length ); 124 assertEquals( "Two events.", 4, tpchl.getEvents().size() ); 125 126 } 127 128 129 private static class TestPropertyChangeListener implements PropertyChangeListener { 130 131 List <PropertyChangeEvent > events = new ArrayList <PropertyChangeEvent >(); 132 133 public void propertyChange( PropertyChangeEvent e ) { 134 events.add( e ); 135 } 136 137 void clear() { 138 events.clear(); 139 } 140 141 List <PropertyChangeEvent > getEvents() { 142 return events; 143 } 144 145 } 146 147 } 148 | Popular Tags |