KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > project > ui > OpenProjectsTrampolineImplTest


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.modules.project.ui;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
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 JavaDoc name) {
38         super( name );
39     }
40     
41     
42     private FileObject scratch;
43     private FileObject goodproject;
44     private FileObject goodproject2;
45     // private FileObject badproject;
46
// private FileObject mysteryproject;
47
private ProjectManager pm;
48     
49     protected void setUp() throws Exception JavaDoc {
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 // badproject = scratch.createFolder("bad");
57
// badproject.createFolder("testproject").createData("broken");
58
// mysteryproject = scratch.createFolder("mystery");
59
TestUtil.setLookup(Lookups.singleton(TestUtil.testProjectFactory()));
60         pm = ProjectManager.getDefault();
61     }
62     
63     protected void tearDown() throws Exception JavaDoc {
64         scratch = null;
65         goodproject = null;
66 // badproject = null;
67
// mysteryproject = null;
68
pm = null;
69         TestUtil.setLookup(Lookup.EMPTY);
70         super.tearDown();
71     }
72     
73     public void testOpenProjects() throws Exception JavaDoc {
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 JavaDoc 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 JavaDoc 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 JavaDoc {
130         
131         List JavaDoc<PropertyChangeEvent JavaDoc> events = new ArrayList JavaDoc<PropertyChangeEvent JavaDoc>();
132         
133         public void propertyChange( PropertyChangeEvent JavaDoc e ) {
134             events.add( e );
135         }
136         
137         void clear() {
138             events.clear();
139         }
140         
141         List JavaDoc<PropertyChangeEvent JavaDoc> getEvents() {
142             return events;
143         }
144                 
145     }
146     
147 }
148
Popular Tags