KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > project > ui > OpenProjectsTest


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

19
20 package org.netbeans.api.project.ui;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
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 /**
33  *
34  * @author Jan Lahoda
35  */

36 public class OpenProjectsTest extends NbTestCase {
37
38     private FileObject scratch;
39     private FileObject testProjectFolder;
40     private Project testProject;
41     
42     public OpenProjectsTest(String JavaDoc testName) {
43         super(testName);
44     }
45
46     protected void setUp() throws Exception JavaDoc {
47         scratch = TestUtil.makeScratchDir(this);
48         TestUtil.setLookup(new Object JavaDoc[] {
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 JavaDoc {
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 JavaDoc 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 JavaDoc {
102         
103         private List JavaDoc<PropertyChangeEvent JavaDoc> events = new ArrayList JavaDoc<PropertyChangeEvent JavaDoc>();
104         
105         public void propertyChange(PropertyChangeEvent JavaDoc evt) {
106             events.add(evt);
107         }
108         
109     }
110     
111 }
112
Popular Tags