1 19 20 package org.netbeans.api.project.ui; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.util.ArrayList ; 25 import java.util.List ; 26 import org.netbeans.api.project.Project; 27 import org.netbeans.api.project.ProjectManager; 28 import org.netbeans.api.project.TestUtil; 29 import org.netbeans.junit.NbTestCase; 30 import org.openide.filesystems.FileObject; 31 32 36 public class OpenProjectsTest extends NbTestCase { 37 38 private FileObject scratch; 39 private FileObject testProjectFolder; 40 private Project testProject; 41 42 public OpenProjectsTest(String testName) { 43 super(testName); 44 } 45 46 protected void setUp() throws Exception { 47 scratch = TestUtil.makeScratchDir(this); 48 TestUtil.setLookup(new Object [] { 49 TestUtil.testProjectFactory(), 50 }); 51 52 assertNotNull(testProjectFolder = scratch.createFolder("test")); 53 assertNotNull(testProjectFolder.createFolder("testproject")); 54 55 testProject = ProjectManager.getDefault().findProject(testProjectFolder); 56 57 assertNotNull(testProject); 58 } 59 60 public void testListenersNotified() throws Exception { 61 PropertyChangeListenerImpl l = new PropertyChangeListenerImpl(); 62 63 OpenProjects.getDefault().addPropertyChangeListener(l); 64 65 assertEquals(0, l.events.size()); 66 67 OpenProjects.getDefault().open(new Project[] {testProject}, false); 68 69 assertEquals(1, l.events.size()); 70 71 PropertyChangeEvent e = l.events.remove(0); 72 73 assertEquals(OpenProjects.PROPERTY_OPEN_PROJECTS, e.getPropertyName()); 74 75 OpenProjects.getDefault().setMainProject(testProject); 76 77 assertEquals(1, l.events.size()); 78 79 e = l.events.remove(0); 80 81 assertEquals(OpenProjects.PROPERTY_MAIN_PROJECT, e.getPropertyName()); 82 83 OpenProjects.getDefault().setMainProject(null); 84 85 assertEquals(1, l.events.size()); 86 87 e = l.events.remove(0); 88 89 assertEquals(OpenProjects.PROPERTY_MAIN_PROJECT, e.getPropertyName()); 90 91 OpenProjects.getDefault().close(new Project[] {testProject}); 92 93 assertEquals(1, l.events.size()); 94 95 e = l.events.remove(0); 96 97 assertEquals(OpenProjects.PROPERTY_OPEN_PROJECTS, e.getPropertyName()); 98 } 99 100 101 private static final class PropertyChangeListenerImpl implements PropertyChangeListener { 102 103 private List <PropertyChangeEvent > events = new ArrayList <PropertyChangeEvent >(); 104 105 public void propertyChange(PropertyChangeEvent evt) { 106 events.add(evt); 107 } 108 109 } 110 111 } 112 | Popular Tags |