KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > UIUtilTest


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.ui;
21
22 import java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24 import javax.swing.ComboBoxModel JavaDoc;
25 import javax.swing.KeyStroke JavaDoc;
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 /**
36  * @author Martin Krauskopf
37  */

38 public class UIUtilTest extends LayerTestBase {
39     
40     public UIUtilTest(String JavaDoc testName) {
41         super(testName);
42     }
43     
44     protected void setUp() throws Exception JavaDoc {
45         super.setUp();
46         TestBase.initializeBuildProperties(getWorkDir(), getDataDir());
47     }
48     
49     /**
50      * Test of createLayerPresenterComboModel method, of class org.netbeans.modules.apisupport.project.ui.UIUtil.
51      */

52     public void testCreateLayerPresenterComboModel() throws Exception JavaDoc {
53         Project project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
54         Map JavaDoc<String JavaDoc,Object JavaDoc> excludes = new HashMap JavaDoc<String JavaDoc,Object JavaDoc>();
55         excludes.put("template", true);
56         excludes.put("simple", false);
57         String JavaDoc sfsRoot = "Templates";
58         ComboBoxModel JavaDoc allModel = UIUtil.createLayerPresenterComboModel(project, sfsRoot);
59         ComboBoxModel JavaDoc 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 JavaDoc {
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 JavaDoc expected, String JavaDoc swingKeyStroke) {
74         assertEquals(swingKeyStroke + " corresponding to " + expected, expected, UIUtil.keyToLogicalString(KeyStroke.getKeyStroke(swingKeyStroke)));
75     }
76     
77     public void testLayerItemPresenterCompareTo() throws Exception JavaDoc {
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