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 JRadioButtonMenuItemTest extends JMenuItemTest {
027: @Override
028: protected void setUp() throws Exception {
029: super .setUp();
030: menuItem = new JRadioButtonMenuItem();
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.JRadioButtonMenuItem.JRadioButtonMenuItem()'
041: */
042: public void testJRadioButtonMenuItem() {
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.JRadioButtonMenuItem.JRadioButtonMenuItem(Icon)'
061: */
062: public void testJRadioButtonMenuItemIcon() {
063: Icon icon = createNewIcon();
064: menuItem = new JRadioButtonMenuItem(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.JRadioButtonMenuItem.JRadioButtonMenuItem(String)'
082: */
083: public void testJRadioButtonMenuItemString() {
084: String text = "texttext";
085: menuItem = new JRadioButtonMenuItem(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.JRadioButtonMenuItem.JRadioButtonMenuItem(String, Icon)'
103: */
104: public void testJRadioButtonMenuItemStringIcon() {
105: Icon icon = createNewIcon();
106: String text = "texttext";
107: menuItem = new JRadioButtonMenuItem(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.JRadioButtonMenuItem.JRadioButtonMenuItem(Action)'
126: */
127: public void testJRadioButtonMenuItemAction() {
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 JRadioButtonMenuItem(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 JRadioButtonMenuItem(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 JRadioButtonMenuItem((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.JRadioButtonMenuItem.JRadioButtonMenuItem(Icon, boolean)'
186: */
187: public void testJRadioButtonMenuItemIconBoolean() {
188: Icon icon = createNewIcon();
189: menuItem = new JRadioButtonMenuItem(icon, true);
190: assertTrue("default buttonModel ",
191: button.getModel() instanceof ToggleButtonModel);
192: assertEquals("icon ", icon, menuItem.getIcon());
193: assertEquals("text ", "", menuItem.getText());
194: assertFalse("default FocusPainted", menuItem.isFocusPainted());
195: assertTrue(menuItem.isSelected());
196: assertEquals(SwingConstants.LEADING, button
197: .getHorizontalAlignment());
198: assertEquals(SwingConstants.TRAILING, button
199: .getHorizontalTextPosition());
200: assertEquals(SwingConstants.CENTER, button
201: .getVerticalAlignment());
202: assertEquals(SwingConstants.CENTER, button
203: .getVerticalTextPosition());
204: menuItem = new JRadioButtonMenuItem(icon, false);
205: assertFalse(menuItem.isSelected());
206: }
207:
208: /*
209: * Test method for 'javax.swing.JRadioButtonMenuItem.JRadioButtonMenuItem(String, Icon, boolean)'
210: */
211: public void testJRadioButtonMenuItemStringIconBoolean() {
212: Icon icon = createNewIcon();
213: String text = "texttext";
214: menuItem = new JRadioButtonMenuItem(text, icon, true);
215: assertTrue("default buttonModel ",
216: button.getModel() instanceof ToggleButtonModel);
217: assertEquals("icon ", icon, menuItem.getIcon());
218: assertEquals("text ", text, menuItem.getText());
219: assertFalse("default FocusPainted", menuItem.isFocusPainted());
220: assertTrue(menuItem.isSelected());
221: assertEquals(SwingConstants.LEADING, button
222: .getHorizontalAlignment());
223: assertEquals(SwingConstants.TRAILING, button
224: .getHorizontalTextPosition());
225: assertEquals(SwingConstants.CENTER, button
226: .getVerticalAlignment());
227: assertEquals(SwingConstants.CENTER, button
228: .getVerticalTextPosition());
229: menuItem = new JRadioButtonMenuItem(text, icon, false);
230: assertFalse(menuItem.isSelected());
231: }
232:
233: /*
234: * Test method for 'javax.swing.JRadioButtonMenuItem.getAccessibleContext()'
235: */
236: @Override
237: public void testGetAccessibleContext() {
238: boolean assertedValue = (menuItem.getAccessibleContext() != null && menuItem
239: .getAccessibleContext()
240: .getClass()
241: .getName()
242: .equals(
243: "javax.swing.JRadioButtonMenuItem$AccessibleJRadioButtonMenuItem"));
244: assertTrue("AccessibleContext created properly ", assertedValue);
245: assertEquals("AccessibleRole", AccessibleRole.RADIO_BUTTON,
246: menuItem.getAccessibleContext().getAccessibleRole());
247: }
248:
249: /*
250: * Test method for 'javax.swing.JRadioButtonMenuItem.getUIClassID()'
251: */
252: @Override
253: public void testGetUIClassID() {
254: assertEquals("RadioButtonMenuItemUI", menuItem.getUIClassID());
255: }
256: }
|