KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > suite > SuiteSubprojectProviderImplTest


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.apisupport.project.suite;
21
22 import javax.swing.event.ChangeEvent JavaDoc;
23 import javax.swing.event.ChangeListener JavaDoc;
24 import org.netbeans.modules.apisupport.project.NbModuleProject;
25 import org.netbeans.modules.apisupport.project.TestBase;
26 import org.netbeans.modules.apisupport.project.ui.customizer.SuiteUtils;
27 import org.netbeans.spi.project.SubprojectProvider;
28
29 /**
30  * @author Martin Krauskopf
31  */

32 public class SuiteSubprojectProviderImplTest extends TestBase {
33
34     public SuiteSubprojectProviderImplTest(String JavaDoc testName) {
35         super(testName);
36     }
37     
38     public void testGetSubprojects() throws Exception JavaDoc {
39         SuiteProject s = generateSuite("suite");
40         SubprojectProvider spp = (SubprojectProvider) s.getLookup().lookup(SubprojectProvider.class);
41         assertEquals("suite doesn't have any submodules", 0, spp.getSubprojects().size());
42         NbModuleProject module1 = generateSuiteComponent(s, "module1");
43         assertEquals("suite has one submodule", 1, spp.getSubprojects().size());
44         SuiteUtils.removeModuleFromSuite(module1);
45         assertEquals("suite doesn't have any submodules", 0, spp.getSubprojects().size());
46         generateSuiteComponent(s, "module2");
47         generateSuiteComponent(s, "module3");
48         assertEquals("suite has two submodules", 2, spp.getSubprojects().size());
49     }
50     
51     public void testChangeListener() throws Exception JavaDoc {
52         SuiteProject s = generateSuite("suite");
53         SubprojectProvider spp = (SubprojectProvider) s.getLookup().lookup(SubprojectProvider.class);
54         SPPChangeListener l = new SPPChangeListener();
55         spp.addChangeListener(l);
56         NbModuleProject module1 = generateSuiteComponent(s, "module1");
57         assertTrue("change was noticed", l.changed);
58         assertEquals("suite has one submodule", 1, spp.getSubprojects().size());
59         l.changed = false;
60         SuiteUtils.removeModuleFromSuite(module1);
61         assertTrue("change was noticed", l.changed);
62         l.changed = false;
63         assertEquals("suite doesn't have any submodules", 0, spp.getSubprojects().size());
64         spp.removeChangeListener(l);
65         generateSuiteComponent(s, "module2");
66         assertFalse("change was noticed", l.changed);
67         assertEquals("suite has one submodule", 1, spp.getSubprojects().size());
68     }
69     
70     private final class SPPChangeListener implements ChangeListener JavaDoc {
71         
72         boolean changed;
73         
74         public void stateChanged(ChangeEvent JavaDoc e) {
75             changed = true;
76         }
77         
78     }
79     
80 }
81
Popular Tags