Source Code Cross Referenced for JCheckBoxMenuItemTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » javax package » javax.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Alexander T. Simbirtsev
019:         * @version $Revision$
020:         */package javax.swing;
021:
022:        import java.awt.event.ActionEvent;
023:        import javax.accessibility.AccessibleRole;
024:        import javax.swing.JToggleButton.ToggleButtonModel;
025:
026:        public class JCheckBoxMenuItemTest extends JMenuItemTest {
027:            @Override
028:            protected void setUp() throws Exception {
029:                super .setUp();
030:                menuItem = new JCheckBoxMenuItem();
031:                button = menuItem;
032:            }
033:
034:            @Override
035:            protected void tearDown() throws Exception {
036:                super .tearDown();
037:            }
038:
039:            /*
040:             * Test method for 'javax.swing.JCheckBoxMenuItem.JCheckBoxMenuItem()'
041:             */
042:            public void testJCheckBoxMenuItem() {
043:                assertFalse(menuItem.isSelected());
044:                assertTrue("default buttonModel ",
045:                        button.getModel() instanceof  ToggleButtonModel);
046:                assertNull("icon ", button.getIcon());
047:                assertEquals("text ", "", button.getText());
048:                assertFalse("default FocusPainted", menuItem.isFocusPainted());
049:                assertEquals(SwingConstants.LEADING, button
050:                        .getHorizontalAlignment());
051:                assertEquals(SwingConstants.TRAILING, button
052:                        .getHorizontalTextPosition());
053:                assertEquals(SwingConstants.CENTER, button
054:                        .getVerticalAlignment());
055:                assertEquals(SwingConstants.CENTER, button
056:                        .getVerticalTextPosition());
057:            }
058:
059:            /*
060:             * Test method for 'javax.swing.JCheckBoxMenuItem.JCheckBoxMenuItem(Icon)'
061:             */
062:            public void testJCheckBoxMenuItemIcon() {
063:                Icon icon = createNewIcon();
064:                menuItem = new JCheckBoxMenuItem(icon);
065:                assertTrue("default buttonModel ",
066:                        button.getModel() instanceof  ToggleButtonModel);
067:                assertEquals("icon ", icon, menuItem.getIcon());
068:                assertEquals("text ", "", menuItem.getText());
069:                assertFalse("default FocusPainted", menuItem.isFocusPainted());
070:                assertEquals(SwingConstants.LEADING, button
071:                        .getHorizontalAlignment());
072:                assertEquals(SwingConstants.TRAILING, button
073:                        .getHorizontalTextPosition());
074:                assertEquals(SwingConstants.CENTER, button
075:                        .getVerticalAlignment());
076:                assertEquals(SwingConstants.CENTER, button
077:                        .getVerticalTextPosition());
078:            }
079:
080:            /*
081:             * Test method for 'javax.swing.JCheckBoxMenuItem.JCheckBoxMenuItem(String)'
082:             */
083:            public void testJCheckBoxMenuItemString() {
084:                String text = "texttext";
085:                menuItem = new JCheckBoxMenuItem(text);
086:                assertFalse(menuItem.isSelected());
087:                assertTrue("default buttonModel ",
088:                        button.getModel() instanceof  ToggleButtonModel);
089:                assertNull("icon ", menuItem.getIcon());
090:                assertEquals("text ", text, menuItem.getText());
091:                assertEquals(SwingConstants.LEADING, button
092:                        .getHorizontalAlignment());
093:                assertEquals(SwingConstants.TRAILING, button
094:                        .getHorizontalTextPosition());
095:                assertEquals(SwingConstants.CENTER, button
096:                        .getVerticalAlignment());
097:                assertEquals(SwingConstants.CENTER, button
098:                        .getVerticalTextPosition());
099:            }
100:
101:            /*
102:             * Test method for 'javax.swing.JCheckBoxMenuItem.JCheckBoxMenuItem(String, Icon)'
103:             */
104:            public void testJCheckBoxMenuItemStringIcon() {
105:                Icon icon = createNewIcon();
106:                String text = "texttext";
107:                menuItem = new JCheckBoxMenuItem(text, icon);
108:                assertFalse(menuItem.isSelected());
109:                assertTrue("default buttonModel ",
110:                        button.getModel() instanceof  ToggleButtonModel);
111:                assertEquals("icon ", icon, menuItem.getIcon());
112:                assertEquals("text ", text, menuItem.getText());
113:                assertFalse("default FocusPainted", menuItem.isFocusPainted());
114:                assertEquals(SwingConstants.LEADING, button
115:                        .getHorizontalAlignment());
116:                assertEquals(SwingConstants.TRAILING, button
117:                        .getHorizontalTextPosition());
118:                assertEquals(SwingConstants.CENTER, button
119:                        .getVerticalAlignment());
120:                assertEquals(SwingConstants.CENTER, button
121:                        .getVerticalTextPosition());
122:            }
123:
124:            /*
125:             * Test method for 'javax.swing.JCheckBoxMenuItem.JCheckBoxMenuItem(Action)'
126:             */
127:            public void testJCheckBoxMenuItemAction() {
128:                final String command = "dnammoc";
129:                final KeyStroke accelerator = KeyStroke.getKeyStroke('a');
130:                class MyAction extends AbstractAction {
131:                    private static final long serialVersionUID = 1L;
132:
133:                    public MyAction(final String text, final Icon icon) {
134:                        super (text, icon);
135:                        putValue(Action.ACTION_COMMAND_KEY, command);
136:                        putValue(Action.ACCELERATOR_KEY, accelerator);
137:                    }
138:
139:                    public void actionPerformed(final ActionEvent e) {
140:                    }
141:                }
142:                ;
143:                Icon icon = createNewIcon();
144:                String text = "texttext";
145:                MyAction action = new MyAction(text, icon);
146:                menuItem = new JCheckBoxMenuItem(action);
147:                assertFalse(menuItem.isSelected());
148:                assertEquals("icon ", icon, menuItem.getIcon());
149:                assertEquals("text ", text, menuItem.getText());
150:                assertEquals("action", action, menuItem.getAction());
151:                assertEquals("command ", command, menuItem.getActionCommand());
152:                assertFalse("selected ", menuItem.isSelected());
153:                assertTrue("enabled ", menuItem.isEnabled());
154:                assertEquals("accelerator ", accelerator, menuItem
155:                        .getAccelerator());
156:                action.setEnabled(false);
157:                menuItem = new JCheckBoxMenuItem(action);
158:                assertEquals("icon ", icon, menuItem.getIcon());
159:                assertEquals("text ", text, menuItem.getText());
160:                assertEquals("action", action, menuItem.getAction());
161:                assertEquals("command ", command, menuItem.getActionCommand());
162:                assertFalse("selected ", menuItem.isSelected());
163:                assertFalse("enabled ", menuItem.isEnabled());
164:                assertFalse("default FocusPainted", menuItem.isFocusPainted());
165:                menuItem = new JCheckBoxMenuItem((Action) null);
166:                assertNull("icon ", menuItem.getIcon());
167:                assertNull("text ", menuItem.getText());
168:                assertNull("action", menuItem.getAction());
169:                assertNull("command ", menuItem.getActionCommand());
170:                assertFalse("selected ", menuItem.isSelected());
171:                assertTrue("enabled ", menuItem.isEnabled());
172:                assertTrue("default buttonModel ",
173:                        button.getModel() instanceof  ToggleButtonModel);
174:                assertEquals(SwingConstants.LEADING, button
175:                        .getHorizontalAlignment());
176:                assertEquals(SwingConstants.TRAILING, button
177:                        .getHorizontalTextPosition());
178:                assertEquals(SwingConstants.CENTER, button
179:                        .getVerticalAlignment());
180:                assertEquals(SwingConstants.CENTER, button
181:                        .getVerticalTextPosition());
182:            }
183:
184:            /*
185:             * Test method for 'javax.swing.JCheckBoxMenuItem.JCheckBoxMenuItem(String, Icon, boolean)'
186:             */
187:            public void testJCheckBoxMenuItemStringIconBoolean() {
188:                Icon icon = createNewIcon();
189:                String text = "texttext";
190:                menuItem = new JCheckBoxMenuItem(text, icon, true);
191:                assertTrue("default buttonModel ",
192:                        button.getModel() instanceof  ToggleButtonModel);
193:                assertEquals("icon ", icon, menuItem.getIcon());
194:                assertEquals("text ", text, menuItem.getText());
195:                assertFalse("default FocusPainted", menuItem.isFocusPainted());
196:                assertTrue(menuItem.isSelected());
197:                assertEquals(SwingConstants.LEADING, button
198:                        .getHorizontalAlignment());
199:                assertEquals(SwingConstants.TRAILING, button
200:                        .getHorizontalTextPosition());
201:                assertEquals(SwingConstants.CENTER, button
202:                        .getVerticalAlignment());
203:                assertEquals(SwingConstants.CENTER, button
204:                        .getVerticalTextPosition());
205:                menuItem = new JCheckBoxMenuItem(text, icon, false);
206:                assertFalse(menuItem.isSelected());
207:            }
208:
209:            /*
210:             * Test method for 'javax.swing.JCheckBoxMenuItem.getAccessibleContext()'
211:             */
212:            @Override
213:            public void testGetAccessibleContext() {
214:                boolean assertedValue = (menuItem.getAccessibleContext() != null && menuItem
215:                        .getAccessibleContext()
216:                        .getClass()
217:                        .getName()
218:                        .equals(
219:                                "javax.swing.JCheckBoxMenuItem$AccessibleJCheckBoxMenuItem"));
220:                assertTrue("AccessibleContext created properly ", assertedValue);
221:                assertEquals("AccessibleRole", AccessibleRole.CHECK_BOX,
222:                        menuItem.getAccessibleContext().getAccessibleRole());
223:            }
224:
225:            /*
226:             * Test method for 'javax.swing.JCheckBoxMenuItem.getUIClassID()'
227:             */
228:            @Override
229:            public void testGetUIClassID() {
230:                assertEquals("CheckBoxMenuItemUI", menuItem.getUIClassID());
231:            }
232:
233:            /*
234:             * Test method for 'javax.swing.JCheckBoxMenuItem.getSelectedObjects()'
235:             */
236:            @Override
237:            public void testGetSelectedObjects() {
238:                String text = "texttext";
239:                menuItem = new JCheckBoxMenuItem(text);
240:                assertNull(((JCheckBoxMenuItem) menuItem).getSelectedObjects());
241:                menuItem.setSelected(true);
242:                assertEquals(1, ((JCheckBoxMenuItem) menuItem)
243:                        .getSelectedObjects().length);
244:                assertEquals(menuItem.getText(), ((JCheckBoxMenuItem) menuItem)
245:                        .getSelectedObjects()[0]);
246:            }
247:
248:            /*
249:             * Test method for 'javax.swing.JCheckBoxMenuItem.getState()'
250:             */
251:            public void testGetSetState() {
252:                assertEquals("default Selected", ((JCheckBoxMenuItem) menuItem)
253:                        .getState(), menuItem.isSelected());
254:                menuItem.setSelected(true);
255:                assertEquals("Selected", ((JCheckBoxMenuItem) menuItem)
256:                        .getState(), menuItem.isSelected());
257:                ((JCheckBoxMenuItem) menuItem).setState(false);
258:                assertEquals("Selected", ((JCheckBoxMenuItem) menuItem)
259:                        .getState(), menuItem.isSelected());
260:            }
261:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.