1 19 20 package org.netbeans.modules.apisupport.project.ui; 21 22 import java.util.HashMap ; 23 import java.util.Map ; 24 import javax.swing.ComboBoxModel ; 25 import javax.swing.KeyStroke ; 26 import org.netbeans.api.project.Project; 27 import org.netbeans.modules.apisupport.project.NbModuleProject; 28 import org.netbeans.modules.apisupport.project.TestBase; 29 import org.netbeans.modules.apisupport.project.layers.LayerTestBase; 30 import org.netbeans.modules.apisupport.project.layers.LayerUtils; 31 import org.netbeans.modules.apisupport.project.ui.UIUtil.LayerItemPresenter; 32 import org.openide.filesystems.FileObject; 33 import org.openide.filesystems.FileSystem; 34 35 38 public class UIUtilTest extends LayerTestBase { 39 40 public UIUtilTest(String testName) { 41 super(testName); 42 } 43 44 protected void setUp() throws Exception { 45 super.setUp(); 46 TestBase.initializeBuildProperties(getWorkDir(), getDataDir()); 47 } 48 49 52 public void testCreateLayerPresenterComboModel() throws Exception { 53 Project project = TestBase.generateStandaloneModule(getWorkDir(), "module1"); 54 Map <String ,Object > excludes = new HashMap <String ,Object >(); 55 excludes.put("template", true); 56 excludes.put("simple", false); 57 String sfsRoot = "Templates"; 58 ComboBoxModel allModel = UIUtil.createLayerPresenterComboModel(project, sfsRoot); 59 ComboBoxModel excludedModel = UIUtil.createLayerPresenterComboModel(project, sfsRoot, excludes); 60 assertTrue("UIUtil.createLayerPresenterComboModel() doesn't work.", allModel.getSize() >= excludedModel.getSize()); 61 } 62 63 public void testKeyToLogicalString() throws Exception { 64 assertKeyLogicalString("X", "pressed X"); 65 assertKeyLogicalString("D-X", "ctrl pressed X"); 66 assertKeyLogicalString("DO-X", "ctrl alt pressed X"); 67 assertKeyLogicalString("DS-X", "shift ctrl pressed X"); 68 assertKeyLogicalString("OS-X", "shift alt pressed X"); 69 assertKeyLogicalString("DOS-X", "shift ctrl alt pressed X"); 70 assertKeyLogicalString("ENTER", "pressed ENTER"); 71 } 72 73 private void assertKeyLogicalString(String expected, String swingKeyStroke) { 74 assertEquals(swingKeyStroke + " corresponding to " + expected, expected, UIUtil.keyToLogicalString(KeyStroke.getKeyStroke(swingKeyStroke))); 75 } 76 77 public void testLayerItemPresenterCompareTo() throws Exception { 78 TestBase.initializeBuildProperties(getWorkDir(), getDataDir()); 79 NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module"); 80 FileSystem fs = LayerUtils.getEffectiveSystemFilesystem(project); 81 FileObject root = fs.getRoot().getFileObject("Templates/Project/APISupport"); 82 FileObject module = root.getFileObject("emptyModule"); 83 FileObject suite = root.getFileObject("emptySuite"); 84 FileObject library = root.getFileObject("libraryModule"); 85 LayerItemPresenter moduleLIP = new LayerItemPresenter(module, root); 86 LayerItemPresenter moduleLIP1 = new LayerItemPresenter(module, root); 87 LayerItemPresenter suiteLIP = new LayerItemPresenter(suite, root); 88 LayerItemPresenter libraryLIP = new LayerItemPresenter(library, root); 89 assertTrue("'Module Project' < 'Module Suite Project'", moduleLIP.compareTo(suiteLIP) < 0); 90 assertTrue("'Module Project' == 'Module Project'", moduleLIP.compareTo(moduleLIP1) == 0); 91 assertTrue("'Library Wrapper Module Project < 'Module Project'", libraryLIP.compareTo(moduleLIP) < 0); 92 assertTrue("'Library Wrapper Module Project < 'Module Suite Project'", libraryLIP.compareTo(suiteLIP) < 0); 93 } 94 95 } 96 | Popular Tags |