1 19 20 package org.netbeans.modules.apisupport.project.suite; 21 22 import javax.swing.event.ChangeEvent ; 23 import javax.swing.event.ChangeListener ; 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 32 public class SuiteSubprojectProviderImplTest extends TestBase { 33 34 public SuiteSubprojectProviderImplTest(String testName) { 35 super(testName); 36 } 37 38 public void testGetSubprojects() throws Exception { 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 { 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 { 71 72 boolean changed; 73 74 public void stateChanged(ChangeEvent e) { 75 changed = true; 76 } 77 78 } 79 80 } 81 | Popular Tags |