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: * Created on 25.04.2005
021:
022: */package javax.swing;
023:
024: import java.awt.event.ActionEvent;
025: import java.awt.image.BufferedImage;
026: import javax.accessibility.AccessibleRole;
027: import javax.swing.plaf.ButtonUI;
028:
029: public class JToggleButtonTest extends SwingTestCase {
030: protected JToggleButton button;
031:
032: public static void main(final String[] args) {
033: junit.textui.TestRunner.run(JToggleButtonTest.class);
034: }
035:
036: /*
037: * @see AbstractButtonTest#setUp()
038: */
039: @Override
040: protected void setUp() throws Exception {
041: super .setUp();
042: button = new JToggleButton();
043: }
044:
045: /*
046: * @see AbstractButtonTest#tearDown()
047: */
048: @Override
049: protected void tearDown() throws Exception {
050: super .tearDown();
051: }
052:
053: public void testGetAccessibleContext() {
054: boolean assertedValue = (button.getAccessibleContext() != null && button
055: .getAccessibleContext()
056: .getClass()
057: .getName()
058: .equals(
059: "javax.swing.JToggleButton$AccessibleJToggleButton"));
060: assertTrue("AccessibleContext created properly ", assertedValue);
061: assertEquals("AccessibleRole", AccessibleRole.TOGGLE_BUTTON,
062: button.getAccessibleContext().getAccessibleRole());
063: }
064:
065: public void testParamString() {
066: assertTrue("ParamString returns a string ",
067: button.toString() != null);
068: }
069:
070: public void testGetUIClassID() {
071: assertEquals("UI class ID", "ToggleButtonUI", button
072: .getUIClassID());
073: }
074:
075: public void testUpdateUI() {
076: ButtonUI ui = new ButtonUI() {
077: };
078: button.setUI(ui);
079: assertEquals(ui, button.getUI());
080: button.updateUI();
081: assertNotSame(ui, button.getUI());
082: }
083:
084: /*
085: * Class under test for void JToggleButton(String, Icon, boolean)
086: */
087: public void testJToggleButtonStringIconboolean() {
088: Icon icon1 = new ImageIcon(new BufferedImage(20, 20,
089: BufferedImage.TYPE_BYTE_GRAY));
090: Icon icon2 = new ImageIcon(new BufferedImage(20, 20,
091: BufferedImage.TYPE_BYTE_GRAY));
092: String text1 = "texttext1";
093: String text2 = "texttext2";
094: boolean state1 = true;
095: boolean state2 = false;
096: button = new JToggleButton(text1, icon1, state1);
097: assertEquals("icon ", icon1, button.getIcon());
098: assertEquals("text ", text1, button.getText());
099: assertEquals("selected ", state1, button.isSelected());
100: button = new JToggleButton(text2, icon2, state2);
101: assertEquals("icon ", icon2, button.getIcon());
102: assertEquals("text ", text2, button.getText());
103: assertEquals("selected ", state2, button.isSelected());
104: assertTrue("button model is of the proper type", button
105: .getModel() instanceof JToggleButton.ToggleButtonModel);
106: }
107:
108: /*
109: * Class under test for void JToggleButton(String, Icon)
110: */
111: public void testJToggleButtonStringIcon() {
112: Icon icon1 = new ImageIcon(new BufferedImage(20, 20,
113: BufferedImage.TYPE_BYTE_GRAY));
114: Icon icon2 = new ImageIcon(new BufferedImage(20, 20,
115: BufferedImage.TYPE_BYTE_GRAY));
116: String text1 = "texttext1";
117: String text2 = "texttext2";
118: boolean state2 = false;
119: button = new JToggleButton(text1, icon1);
120: assertEquals("icon ", icon1, button.getIcon());
121: assertEquals("text ", text1, button.getText());
122: assertEquals("selected ", state2, button.isSelected());
123: button = new JToggleButton(text2, icon2);
124: assertEquals("icon ", icon2, button.getIcon());
125: assertEquals("text ", text2, button.getText());
126: assertEquals("selected ", state2, button.isSelected());
127: assertTrue("button model is of the proper type", button
128: .getModel() instanceof JToggleButton.ToggleButtonModel);
129: }
130:
131: /*
132: * Class under test for void JToggleButton(Icon, boolean)
133: */
134: public void testJToggleButtonIconboolean() {
135: Icon icon1 = new ImageIcon(new BufferedImage(20, 20,
136: BufferedImage.TYPE_BYTE_GRAY));
137: Icon icon2 = new ImageIcon(new BufferedImage(20, 20,
138: BufferedImage.TYPE_BYTE_GRAY));
139: String text1 = "";
140: String text2 = "";
141: boolean state1 = true;
142: boolean state2 = false;
143: button = new JToggleButton(icon1, state1);
144: assertEquals("icon ", icon1, button.getIcon());
145: assertEquals("text ", text1, button.getText());
146: assertEquals("selected ", state1, button.isSelected());
147: button = new JToggleButton(icon2, state2);
148: assertEquals("icon ", icon2, button.getIcon());
149: assertEquals("text ", text2, button.getText());
150: assertEquals("selected ", state2, button.isSelected());
151: assertTrue("button model is of the proper type", button
152: .getModel() instanceof JToggleButton.ToggleButtonModel);
153: }
154:
155: /*
156: * Class under test for void JToggleButton(Icon)
157: */
158: public void testJToggleButtonIcon() {
159: Icon icon1 = new ImageIcon(new BufferedImage(20, 20,
160: BufferedImage.TYPE_BYTE_GRAY));
161: Icon icon2 = new ImageIcon(new BufferedImage(20, 20,
162: BufferedImage.TYPE_BYTE_GRAY));
163: String text1 = "";
164: String text2 = "";
165: boolean state1 = false;
166: boolean state2 = false;
167: button = new JToggleButton(icon1);
168: assertEquals("icon ", icon1, button.getIcon());
169: assertEquals("text ", text1, button.getText());
170: assertEquals("selected ", state1, button.isSelected());
171: button = new JToggleButton(icon2);
172: assertEquals("icon ", icon2, button.getIcon());
173: assertEquals("text ", text2, button.getText());
174: assertEquals("selected ", state2, button.isSelected());
175: assertTrue("button model is of the proper type", button
176: .getModel() instanceof JToggleButton.ToggleButtonModel);
177: }
178:
179: /*
180: * Class under test for void JToggleButton(Action)
181: */
182: public void testJToggleButtonAction() {
183: final String command = "dnammoc";
184: class MyAction extends AbstractAction {
185: private static final long serialVersionUID = 1L;
186:
187: public MyAction(final String text, final Icon icon) {
188: super (text, icon);
189: putValue(Action.ACTION_COMMAND_KEY, command);
190: }
191:
192: public void actionPerformed(final ActionEvent e) {
193: }
194: }
195: ;
196: Icon icon = new ImageIcon(new BufferedImage(20, 20,
197: BufferedImage.TYPE_BYTE_GRAY));
198: String text = "texttext";
199: MyAction action = new MyAction(text, icon);
200: button = new JToggleButton(action);
201: assertEquals("icon ", icon, button.getIcon());
202: assertEquals("text ", text, button.getText());
203: assertEquals("action", action, button.getAction());
204: assertEquals("command ", command, button.getActionCommand());
205: assertFalse("selected ", button.isSelected());
206: assertTrue("enabled ", button.isEnabled());
207: action.setEnabled(false);
208: button = new JToggleButton(action);
209: assertEquals("icon ", icon, button.getIcon());
210: assertEquals("text ", text, button.getText());
211: assertEquals("action", action, button.getAction());
212: assertEquals("command ", command, button.getActionCommand());
213: assertFalse("selected ", button.isSelected());
214: assertFalse("enabled ", button.isEnabled());
215: button = new JToggleButton((Action) null);
216: assertNull("icon ", button.getIcon());
217: assertNull("text ", button.getText());
218: assertNull("action", button.getAction());
219: assertNull("command ", button.getActionCommand());
220: assertFalse("selected ", button.isSelected());
221: assertTrue("enabled ", button.isEnabled());
222: assertTrue("button model is of the proper type", button
223: .getModel() instanceof JToggleButton.ToggleButtonModel);
224: }
225:
226: /*
227: * Class under test for void JToggleButton(String, boolean)
228: */
229: public void testJToggleButtonStringboolean() {
230: Icon icon1 = null;
231: Icon icon2 = null;
232: String text1 = "texttext1";
233: String text2 = "texttext2";
234: boolean state1 = true;
235: boolean state2 = false;
236: button = new JToggleButton(text1, state1);
237: assertEquals("icon ", icon1, button.getIcon());
238: assertEquals("text ", text1, button.getText());
239: assertEquals("selected ", state1, button.isSelected());
240: button = new JToggleButton(text2, state2);
241: assertEquals("icon ", icon2, button.getIcon());
242: assertEquals("text ", text2, button.getText());
243: assertEquals("selected ", state2, button.isSelected());
244: assertTrue("button model is of the proper type", button
245: .getModel() instanceof JToggleButton.ToggleButtonModel);
246: }
247:
248: /*
249: * Class under test for void JToggleButton(String)
250: */
251: public void testJToggleButtonString() {
252: Icon icon1 = null;
253: Icon icon2 = null;
254: String text1 = "texttext1";
255: String text2 = "texttext2";
256: boolean state1 = false;
257: boolean state2 = false;
258: button = new JToggleButton(text1);
259: assertEquals("icon ", icon1, button.getIcon());
260: assertEquals("text ", text1, button.getText());
261: assertEquals("selected ", state1, button.isSelected());
262: button = new JToggleButton(text2);
263: assertEquals("icon ", icon2, button.getIcon());
264: assertEquals("text ", text2, button.getText());
265: assertEquals("selected ", state2, button.isSelected());
266: assertTrue("button model is of the proper type", button
267: .getModel() instanceof JToggleButton.ToggleButtonModel);
268: }
269:
270: /*
271: * Class under test for void JToggleButton()
272: */
273: public void testJToggleButton() {
274: Icon icon1 = null;
275: String text1 = "";
276: boolean state1 = false;
277: button = new JToggleButton();
278: assertEquals("icon ", icon1, button.getIcon());
279: assertEquals("text ", text1, button.getText());
280: assertEquals("selected ", state1, button.isSelected());
281: assertTrue("button model is of the proper type", button
282: .getModel() instanceof JToggleButton.ToggleButtonModel);
283: }
284:
285: /*
286: * stub to override AbstractButton testcase incorrect for this class
287: */
288: public void testSetAction1() {
289: }
290: }
|