Source Code Cross Referenced for AbstractButtonTest.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) 


0001:        /*
0002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
0003:         *  contributor license agreements.  See the NOTICE file distributed with
0004:         *  this work for additional information regarding copyright ownership.
0005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
0006:         *  (the "License"); you may not use this file except in compliance with
0007:         *  the License.  You may obtain a copy of the License at
0008:         *
0009:         *     http://www.apache.org/licenses/LICENSE-2.0
0010:         *
0011:         *  Unless required by applicable law or agreed to in writing, software
0012:         *  distributed under the License is distributed on an "AS IS" BASIS,
0013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         *  See the License for the specific language governing permissions and
0015:         *  limitations under the License.
0016:         */
0017:        /**
0018:         * @author Alexander T. Simbirtsev
0019:         * @version $Revision$
0020:         * Created on 31.01.2005
0021:
0022:         */package javax.swing;
0023:
0024:        import java.awt.Component;
0025:        import java.awt.Graphics;
0026:        import java.awt.Image;
0027:        import java.awt.Insets;
0028:        import java.awt.event.ActionEvent;
0029:        import java.awt.event.ActionListener;
0030:        import java.awt.event.ItemEvent;
0031:        import java.awt.event.ItemListener;
0032:        import java.awt.event.KeyEvent;
0033:        import java.awt.image.BufferedImage;
0034:        import java.awt.image.ImageObserver;
0035:        import java.beans.PropertyChangeListener;
0036:        import java.util.EventListener;
0037:        import javax.swing.border.Border;
0038:        import javax.swing.event.ChangeEvent;
0039:        import javax.swing.event.ChangeListener;
0040:
0041:        @SuppressWarnings("serial")
0042:        public class AbstractButtonTest extends SwingTestCase {
0043:            class TestButtonModel extends DefaultButtonModel {
0044:                private static final long serialVersionUID = 1L;
0045:
0046:                boolean wasPressed;
0047:
0048:                boolean wasArmed;
0049:
0050:                @Override
0051:                public void setPressed(boolean b) {
0052:                    wasPressed = true;
0053:                    super .setPressed(b);
0054:                }
0055:
0056:                @Override
0057:                public void setArmed(boolean b) {
0058:                    wasArmed = true;
0059:                    super .setArmed(b);
0060:                }
0061:            }
0062:
0063:            class ConcreteActionListener implements  ActionListener {
0064:                public ActionEvent eventHappened = null;
0065:
0066:                private boolean debugOut = false;
0067:
0068:                public ConcreteActionListener() {
0069:                }
0070:
0071:                public ConcreteActionListener(final boolean debugOut) {
0072:                    this .debugOut = debugOut;
0073:                }
0074:
0075:                public void actionPerformed(final ActionEvent event) {
0076:                    eventHappened = event;
0077:                    if (debugOut) {
0078:                        System.out.println("actionPerformed");
0079:                        System.out.println("ID " + event.getID());
0080:                        System.out.println("Source " + event.getSource());
0081:                        System.out.println("Modifiers " + event.getModifiers());
0082:                        System.out.println("Command "
0083:                                + event.getActionCommand());
0084:                        System.out.println("When " + event.getWhen());
0085:                        System.out.println();
0086:                    }
0087:                }
0088:            };
0089:
0090:            class ConcreteItemListener implements  ItemListener {
0091:                public ItemEvent eventHappened = null;
0092:
0093:                private boolean debugOut = false;
0094:
0095:                public ConcreteItemListener() {
0096:                }
0097:
0098:                public ConcreteItemListener(final boolean debugOut) {
0099:                    this .debugOut = debugOut;
0100:                }
0101:
0102:                public void itemStateChanged(final ItemEvent event) {
0103:                    eventHappened = event;
0104:                    if (debugOut) {
0105:                        System.out.println("itemStateChanged");
0106:                        System.out.println("ID " + event.getID());
0107:                        System.out.println("Source " + event.getSource());
0108:                        System.out.println("StateChange "
0109:                                + event.getStateChange());
0110:                        System.out.println("Item " + event.getItem());
0111:                        System.out.println("ItemSelectable "
0112:                                + event.getItemSelectable());
0113:                        System.out.println();
0114:                    }
0115:                }
0116:            };
0117:
0118:            class ConcreteChangeListener implements  ChangeListener {
0119:                public ChangeEvent eventHappened = null;
0120:
0121:                private boolean debugOut = false;
0122:
0123:                public ConcreteChangeListener() {
0124:                }
0125:
0126:                public ConcreteChangeListener(final boolean debugOut) {
0127:                    this .debugOut = debugOut;
0128:                }
0129:
0130:                public void stateChanged(final ChangeEvent event) {
0131:                    eventHappened = event;
0132:                    if (debugOut) {
0133:                        System.out.println("stateChanged");
0134:                        System.out.println("Class " + event.getClass());
0135:                        System.out.println("Source " + event.getSource());
0136:                        System.out.println();
0137:                    }
0138:                }
0139:            };
0140:
0141:            class ConcreteAction extends AbstractAction {
0142:                private static final long serialVersionUID = 1L;
0143:
0144:                ActionEvent eventHappened;
0145:
0146:                public void actionPerformed(ActionEvent e) {
0147:                    eventHappened = e;
0148:                }
0149:            }
0150:
0151:            protected AbstractButton button = null;
0152:
0153:            protected final Icon icon1 = createNewIcon();
0154:
0155:            protected final Icon icon2 = createNewIcon();
0156:
0157:            protected final String text1 = "texttext1";
0158:
0159:            protected final String text2 = "texttext2";
0160:
0161:            protected final String text3 = "texttext3";
0162:
0163:            protected final String text4 = "texttext4";
0164:
0165:            protected AbstractAction action1;
0166:
0167:            protected AbstractAction action2;
0168:
0169:            public AbstractButtonTest() {
0170:                super ("");
0171:            }
0172:
0173:            @Override
0174:            protected void setUp() throws Exception {
0175:                super .setUp();
0176:                button = new AbstractButton() {
0177:                    private static final long serialVersionUID = 1L;
0178:                };
0179:                if (button.getModel() == null) {
0180:                    button.setModel(new DefaultButtonModel());
0181:                }
0182:                action1 = new AbstractAction(text1, icon1) {
0183:                    private static final long serialVersionUID = 1L;
0184:
0185:                    public void actionPerformed(final ActionEvent event) {
0186:                    }
0187:                };
0188:                action2 = new AbstractAction(text2, icon2) {
0189:                    private static final long serialVersionUID = 1L;
0190:
0191:                    public void actionPerformed(final ActionEvent event) {
0192:                    }
0193:                };
0194:            }
0195:
0196:            /*
0197:             * @see JComponentTest#tearDown()
0198:             */
0199:            @Override
0200:            protected void tearDown() throws Exception {
0201:                button = null;
0202:                super .tearDown();
0203:            }
0204:
0205:            public void testParamString() {
0206:                assertTrue("ParamString returns a string ",
0207:                        button.toString() != null);
0208:            }
0209:
0210:            public void testSetEnabled() {
0211:                PropertyChangeController listener1 = new PropertyChangeController();
0212:                PropertyChangeController listener2 = new PropertyChangeController();
0213:                ConcreteChangeListener listener3 = new ConcreteChangeListener();
0214:                button.addPropertyChangeListener(listener1);
0215:                button.addPropertyChangeListener(listener2);
0216:                button.addChangeListener(listener3);
0217:                button.setEnabled(false);
0218:                assertFalse(button.isEnabled());
0219:                listener1.checkPropertyFired(button, "enabled", Boolean.TRUE,
0220:                        Boolean.FALSE);
0221:                listener2.checkPropertyFired(button, "enabled", Boolean.TRUE,
0222:                        Boolean.FALSE);
0223:                assertTrue("state event's been fired ",
0224:                        listener3.eventHappened != null);
0225:                assertEquals("state event fired properly ", ChangeEvent.class,
0226:                        listener3.eventHappened.getClass());
0227:                assertEquals("state event fired properly ", button,
0228:                        listener3.eventHappened.getSource());
0229:                listener1.reset();
0230:                listener2.reset();
0231:                listener3.eventHappened = null;
0232:                button.setEnabled(true);
0233:                assertTrue(button.isEnabled());
0234:                listener1.checkPropertyFired(button, "enabled", Boolean.FALSE,
0235:                        Boolean.TRUE);
0236:                listener2.checkPropertyFired(button, "enabled", Boolean.FALSE,
0237:                        Boolean.TRUE);
0238:                assertTrue("state event's been fired ",
0239:                        listener3.eventHappened != null);
0240:                assertEquals("state event fired properly ", ChangeEvent.class,
0241:                        listener3.eventHappened.getClass());
0242:                assertEquals("state event fired properly ", button,
0243:                        listener3.eventHappened.getSource());
0244:                listener1.reset();
0245:                listener2.reset();
0246:                listener3.eventHappened = null;
0247:                button.setEnabled(true);
0248:                assertFalse("event's not been fired ", listener1.isChanged());
0249:                assertFalse("event's not been fired ", listener2.isChanged());
0250:                assertNull("event's not been fired ", listener3.eventHappened);
0251:                listener1.reset();
0252:                listener2.reset();
0253:            }
0254:
0255:            public void testPaintBorder() {
0256:                class ThisBorder implements  Border {
0257:                    public boolean haveBeenPainted = false;
0258:
0259:                    public boolean isBorderOpaque() {
0260:                        return true;
0261:                    }
0262:
0263:                    public void paintBorder(final Component arg0,
0264:                            final Graphics arg1, final int arg2,
0265:                            final int arg3, final int arg4, final int arg5) {
0266:                        haveBeenPainted = true;
0267:                    }
0268:
0269:                    public Insets getBorderInsets(final Component c) {
0270:                        return new Insets(1, 2, 3, 4);
0271:                    }
0272:                }
0273:                ;
0274:                ThisBorder border = new ThisBorder();
0275:                button.setBorder(border);
0276:                button.setBorderPainted(false);
0277:                button.paintBorder(button.getGraphics());
0278:                assertFalse("painted", border.haveBeenPainted);
0279:                button.setBorderPainted(true);
0280:                button.paintBorder(button.getGraphics());
0281:                assertTrue("painted", border.haveBeenPainted);
0282:            }
0283:
0284:            public void testImageUpdate() {
0285:                Image image1 = new BufferedImage(10, 20,
0286:                        BufferedImage.TYPE_INT_RGB);
0287:                Image image2 = new BufferedImage(10, 20,
0288:                        BufferedImage.TYPE_INT_RGB);
0289:                Icon icon1 = new Icon() {
0290:                    public void paintIcon(final Component c, final Graphics g,
0291:                            final int x, final int y) {
0292:                    }
0293:
0294:                    public int getIconWidth() {
0295:                        return 0;
0296:                    }
0297:
0298:                    public int getIconHeight() {
0299:                        return 0;
0300:                    }
0301:                };
0302:                Icon icon2 = new ImageIcon(image1);
0303:                Icon icon3 = new ImageIcon(image2);
0304:                assertFalse(button.imageUpdate(image1, ImageObserver.SOMEBITS,
0305:                        1, 1, 1, 1));
0306:                button.setIcon(icon1);
0307:                assertFalse(button.imageUpdate(image1, ImageObserver.SOMEBITS,
0308:                        1, 1, 1, 1));
0309:                button.setIcon(icon2);
0310:                assertTrue(button.imageUpdate(image1, ImageObserver.SOMEBITS,
0311:                        1, 1, 1, 1));
0312:                button.setSelectedIcon(icon3);
0313:                button.setSelected(true);
0314:                assertFalse(button.imageUpdate(image1, ImageObserver.SOMEBITS,
0315:                        1, 1, 1, 1));
0316:                assertTrue(button.imageUpdate(image2, ImageObserver.SOMEBITS,
0317:                        1, 1, 1, 1));
0318:                button.setSelected(false);
0319:                assertTrue(button.imageUpdate(image1, ImageObserver.SOMEBITS,
0320:                        1, 1, 1, 1));
0321:                assertFalse(button.imageUpdate(image2, ImageObserver.SOMEBITS,
0322:                        1, 1, 1, 1));
0323:            }
0324:
0325:            /**
0326:             * since this method has empty implementation, there's no need to test it
0327:             */
0328:            public void testUpdateUI() {
0329:            }
0330:
0331:            /**
0332:             * as method setUI() just calls super.setUI(), it is being tested by JCompomentTest.setUI()
0333:             * nevertheless it is also beeeing tested by testInit()
0334:             */
0335:            public void testSetUIButtonUI() {
0336:            }
0337:
0338:            public void testGetUI() {
0339:                assertNull("ui is returned ", button.getUI());
0340:            }
0341:
0342:            @SuppressWarnings("serial")
0343:            public void testAbstractButton() {
0344:                button = new AbstractButton() {
0345:                };
0346:                assertNull(button.getIcon());
0347:                assertEquals("", button.getText());
0348:                assertNull(button.getModel());
0349:                assertNull(button.getUI());
0350:            }
0351:
0352:            public void testGetSelectedObjects() {
0353:                String text = "Om mani padme hum";
0354:                button.setText(text);
0355:                button.setSelected(false);
0356:                assertNull("no selected objects", button.getSelectedObjects());
0357:                button.setSelected(true);
0358:                assertTrue("there are selected objects", button
0359:                        .getSelectedObjects() != null
0360:                        && button.getSelectedObjects().length > 0);
0361:                assertEquals("selected object ", text, button
0362:                        .getSelectedObjects()[0]);
0363:            }
0364:
0365:            public void testConfigurePropertiesFromAction() {
0366:                action1.setEnabled(true);
0367:                action1.putValue(Action.SHORT_DESCRIPTION, text3);
0368:                action1.putValue(Action.MNEMONIC_KEY, new Integer(1));
0369:                button.setAction(action1);
0370:                assertEquals("action ", action1, button.getAction());
0371:                assertTrue("enabled ", button.isEnabled());
0372:                assertTrue("enabled ", action1.isEnabled());
0373:                action1.setEnabled(false);
0374:                assertFalse(button.isEnabled());
0375:                assertFalse("enabled ", button.isEnabled());
0376:                assertFalse("enabled ", action1.isEnabled());
0377:                assertEquals("icon ", icon1, button.getIcon());
0378:                action1.putValue(Action.SMALL_ICON, icon2);
0379:                assertEquals("icon ", icon2, button.getIcon());
0380:                assertEquals("mnemonic ", 1, button.getMnemonic());
0381:                action1.putValue(Action.MNEMONIC_KEY, new Integer(27));
0382:                assertEquals("mnemonic ", 27, button.getMnemonic());
0383:                assertEquals("text ", text1, button.getText());
0384:                action1.putValue(Action.NAME, text2);
0385:                assertEquals("text ", text2, button.getText());
0386:            }
0387:
0388:            public void testConfigurePropertiesFromAction_ShortDescription() {
0389:                action1.putValue(Action.SHORT_DESCRIPTION, text3);
0390:                button.setAction(action1);
0391:                assertEquals("ToolTipText ", text3, button.getToolTipText());
0392:                action1.putValue(Action.SHORT_DESCRIPTION, text4);
0393:                assertEquals("ToolTipText ", text4, button.getToolTipText());
0394:                button.setAction(action2);
0395:                action1.putValue(Action.SHORT_DESCRIPTION, text4);
0396:                assertNull("ToolTipText ", button.getToolTipText());
0397:                action2.putValue(Action.SHORT_DESCRIPTION, text4);
0398:                assertEquals("ToolTipText ", text4, button.getToolTipText());
0399:            }
0400:
0401:            public void testInit() {
0402:                PropertyChangeController listener = new PropertyChangeController();
0403:                button.addPropertyChangeListener(listener);
0404:                button.init(text1, icon1);
0405:                assertEquals(text1, button.getText());
0406:                assertEquals(icon1, button.getIcon());
0407:                listener.checkPropertyFired(button, "text", "", text1);
0408:                listener.checkPropertyFired(button, "icon", null, icon1);
0409:                button.init(null, null);
0410:                assertEquals(text1, button.getText());
0411:                assertEquals(icon1, button.getIcon());
0412:                button.setText("");
0413:                button.init(text1, null);
0414:                assertEquals(text1, button.getText());
0415:                assertEquals(icon1, button.getIcon());
0416:                button = new AbstractButton() {
0417:                };
0418:                button.init(null, null);
0419:                assertEquals(button.getText(), "");
0420:                assertNull(button.getIcon());
0421:                button.init(null, icon1);
0422:                assertEquals(button.getText(), "");
0423:                assertEquals(icon1, button.getIcon());
0424:            }
0425:
0426:            public void testSetText1() {
0427:                PropertyChangeController listener1 = new PropertyChangeController();
0428:                PropertyChangeController listener2 = new PropertyChangeController();
0429:                button.addPropertyChangeListener(listener1);
0430:                button.addPropertyChangeListener(listener2);
0431:                button.setText(text1);
0432:                listener1.checkPropertyFired(button, "text", "", text1);
0433:                listener2.checkPropertyFired(button, "text", "", text1);
0434:                listener1.reset();
0435:                listener2.reset();
0436:                button.setText(text2);
0437:                listener1.checkPropertyFired(button, "text", text1, text2);
0438:                listener2.checkPropertyFired(button, "text", text1, text2);
0439:                listener1.reset();
0440:                listener2.reset();
0441:                button.setText(text2);
0442:                assertFalse("event's not been fired ", listener1.isChanged());
0443:                assertFalse("event's not been fired ", listener2.isChanged());
0444:                listener1.reset();
0445:                listener2.reset();
0446:                button.setText(null);
0447:                assertNull("text ", button.getText());
0448:            }
0449:
0450:            public void testSetText2() {
0451:                button.setText(text1);
0452:                button.setMnemonic(KeyEvent.VK_X);
0453:                assertEquals(2, button.getDisplayedMnemonicIndex());
0454:                assertEquals(KeyEvent.VK_X, button.getMnemonic());
0455:                button.setText(text2);
0456:                assertEquals(2, button.getDisplayedMnemonicIndex());
0457:                assertEquals(KeyEvent.VK_X, button.getMnemonic());
0458:                button.setText(null);
0459:                assertEquals(-1, button.getDisplayedMnemonicIndex());
0460:                assertEquals(KeyEvent.VK_X, button.getMnemonic());
0461:            }
0462:
0463:            public void testSetText3() {
0464:                button.setText(text1);
0465:                button.setMnemonic(KeyEvent.VK_X);
0466:                button.setDisplayedMnemonicIndex(3);
0467:                assertEquals(3, button.getDisplayedMnemonicIndex());
0468:                assertEquals(KeyEvent.VK_X, button.getMnemonic());
0469:                button.setText(text2);
0470:                assertEquals(2, button.getDisplayedMnemonicIndex());
0471:                assertEquals(KeyEvent.VK_X, button.getMnemonic());
0472:                button.setDisplayedMnemonicIndex(3);
0473:                button.setMnemonic(KeyEvent.VK_D);
0474:                button.setText(text1);
0475:                assertEquals(-1, button.getDisplayedMnemonicIndex());
0476:                assertEquals(KeyEvent.VK_D, button.getMnemonic());
0477:            }
0478:
0479:            public void testGetText() {
0480:                String text1 = "text1";
0481:                String text2 = "text2";
0482:                assertEquals("default text ", "", button.getText());
0483:                button.setText(text1);
0484:                assertEquals("text ", text1, button.getText());
0485:                button.setText(text2);
0486:                assertEquals("text ", text2, button.getText());
0487:            }
0488:
0489:            @SuppressWarnings("deprecation")
0490:            public void testSetLabel() {
0491:                String text1 = "text1";
0492:                String text2 = "text2";
0493:                PropertyChangeController listener1 = new PropertyChangeController();
0494:                PropertyChangeController listener2 = new PropertyChangeController();
0495:                button.addPropertyChangeListener(listener1);
0496:                button.addPropertyChangeListener(listener2);
0497:                button.setLabel(text1);
0498:                listener1.checkPropertyFired(button, "text", "", text1);
0499:                listener2.checkPropertyFired(button, "text", "", text1);
0500:                listener1.reset();
0501:                listener2.reset();
0502:                button.setLabel(text2);
0503:                listener1.checkPropertyFired(button, "text", text1, text2);
0504:                listener2.checkPropertyFired(button, "text", text1, text2);
0505:                listener1.reset();
0506:                listener2.reset();
0507:                button.setLabel(text2);
0508:                assertFalse("event's not been fired ", listener1.isChanged());
0509:                assertFalse("event's not been fired ", listener2.isChanged());
0510:                listener1.reset();
0511:                listener2.reset();
0512:            }
0513:
0514:            @SuppressWarnings("deprecation")
0515:            public void testGetLabel() {
0516:                String text1 = "text1";
0517:                String text2 = "text2";
0518:                assertEquals("default label ", "", button.getLabel());
0519:                button.setLabel(text1);
0520:                assertEquals("text ", text1, button.getText());
0521:                assertEquals("label ", text1, button.getLabel());
0522:                button.setLabel(text2);
0523:                assertEquals("text ", text2, button.getText());
0524:                assertEquals("label ", text2, button.getLabel());
0525:            }
0526:
0527:            public void testSetAction1() {
0528:                PropertyChangeController listener1 = new PropertyChangeController();
0529:                ConcreteChangeListener listener2 = new ConcreteChangeListener();
0530:                button.setEnabled(false);
0531:                button.addPropertyChangeListener(listener1);
0532:                button.addChangeListener(listener2);
0533:                action1.setEnabled(true);
0534:                action1.putValue(Action.SHORT_DESCRIPTION, text3);
0535:                action1.putValue(Action.MNEMONIC_KEY, new Integer(1));
0536:                button.setAction(action1);
0537:                assertTrue("event's been fired ", listener1.isChanged());
0538:                listener1.checkPropertyFired(button, "mnemonic",
0539:                        new Integer(0), new Integer(1));
0540:                listener1
0541:                        .checkPropertyFired(button, "ToolTipText", null, text3);
0542:                listener1.checkPropertyFired(button, "icon", null, icon1);
0543:                listener1.checkPropertyFired(button, "enabled", Boolean.FALSE,
0544:                        Boolean.TRUE);
0545:                listener1.checkPropertyFired(button, "text", "", text1);
0546:                listener1.checkPropertyFired(button, "action", null, action1);
0547:                assertTrue("state event's been fired ",
0548:                        listener2.eventHappened != null);
0549:                assertEquals("state event fired properly ", ChangeEvent.class,
0550:                        listener2.eventHappened.getClass());
0551:                assertEquals("state event fired properly ", button,
0552:                        listener2.eventHappened.getSource());
0553:                listener1.reset();
0554:                listener2.eventHappened = null;
0555:                button.setAction(action2);
0556:                listener1.checkPropertyFired(button, "mnemonic",
0557:                        new Integer(1), new Integer(0));
0558:                listener1
0559:                        .checkPropertyFired(button, "ToolTipText", text3, null);
0560:                listener1.checkPropertyFired(button, "icon", icon1, icon2);
0561:                listener1.checkPropertyFired(button, "text", text1, text2);
0562:                listener1
0563:                        .checkPropertyFired(button, "action", action1, action2);
0564:                assertTrue("state event's been fired ",
0565:                        listener2.eventHappened != null);
0566:                assertEquals("state event fired properly ", ChangeEvent.class,
0567:                        listener2.eventHappened.getClass());
0568:                assertEquals("state event fired properly ", button,
0569:                        listener2.eventHappened.getSource());
0570:                listener1.reset();
0571:                listener2.eventHappened = null;
0572:                button.setAction(action2);
0573:                assertFalse("event's not been fired ", listener1.isChanged());
0574:                assertNull("event's not been fired ", listener2.eventHappened);
0575:                listener1.reset();
0576:                listener2.eventHappened = null;
0577:            }
0578:
0579:            public void testSetAction2() {
0580:                action1.setEnabled(true);
0581:                action1.putValue(Action.SHORT_DESCRIPTION, text3);
0582:                action1.putValue(Action.MNEMONIC_KEY, new Integer(1));
0583:                button.setAction(action1);
0584:                assertTrue("enabled ", button.isEnabled());
0585:                assertTrue("enabled ", action1.isEnabled());
0586:                action1.setEnabled(false);
0587:                button.isEnabled();
0588:                assertFalse("enabled ", button.isEnabled());
0589:                assertFalse("enabled ", action1.isEnabled());
0590:                assertEquals("icon ", icon1, button.getIcon());
0591:                action1.putValue(Action.SMALL_ICON, icon2);
0592:                assertEquals("icon ", icon2, button.getIcon());
0593:                assertEquals("mnemonic ", 1, button.getMnemonic());
0594:                action1.putValue(Action.MNEMONIC_KEY, new Integer(27));
0595:                assertEquals("mnemonic ", 27, button.getMnemonic());
0596:                assertEquals("text ", text1, button.getText());
0597:                action1.putValue(Action.NAME, text2);
0598:                assertEquals("text ", text2, button.getText());
0599:            }
0600:
0601:            public void testSetAction3() {
0602:                Action action1 = new AbstractAction() {
0603:                    public void actionPerformed(ActionEvent e) {
0604:                        putValue("performed", e);
0605:                    }
0606:                };
0607:                Action action2 = new AbstractAction() {
0608:                    public void actionPerformed(ActionEvent e) {
0609:                        putValue("performed", e);
0610:                    }
0611:                };
0612:                ActionEvent event1 = new ActionEvent(button,
0613:                        ActionEvent.ACTION_PERFORMED, "1");
0614:                ActionEvent event2 = new ActionEvent(button,
0615:                        ActionEvent.ACTION_PERFORMED, "2");
0616:                button.setAction(action1);
0617:                button.fireActionPerformed(event1);
0618:                assertEquals("1", ((ActionEvent) action1.getValue("performed"))
0619:                        .getActionCommand());
0620:                button.setAction(action2);
0621:                button.fireActionPerformed(event2);
0622:                assertEquals("1", ((ActionEvent) action1.getValue("performed"))
0623:                        .getActionCommand());
0624:                assertEquals("2", ((ActionEvent) action2.getValue("performed"))
0625:                        .getActionCommand());
0626:            }
0627:
0628:            public void testSetAction4() {
0629:                button.setAction(null);
0630:                button.setText("text");
0631:                button.setIcon(icon1);
0632:                button.setAction(null);
0633:                assertNull(button.getText());
0634:                assertNull(button.getIcon());
0635:            }
0636:
0637:            public void testSetAction5() {
0638:                if (!isHarmony()) {
0639:                    return;
0640:                }
0641:                button.addActionListener(action1);
0642:                button.addActionListener(action1);
0643:                button.setAction(action1);
0644:                assertEquals(2, button.getActionListeners().length);
0645:                button.setAction(null);
0646:                assertEquals(2, button.getActionListeners().length);
0647:                button.removeActionListener(action1);
0648:                button.removeActionListener(action1);
0649:                assertEquals(0, button.getActionListeners().length);
0650:                button.setAction(action1);
0651:                button.addActionListener(action1);
0652:                button.addActionListener(action1);
0653:                assertEquals(3, button.getActionListeners().length);
0654:                button.setAction(null);
0655:                assertEquals(2, button.getActionListeners().length);
0656:                button.removeActionListener(action1);
0657:                button.removeActionListener(action1);
0658:                assertEquals(0, button.getActionListeners().length);
0659:            }
0660:
0661:            public void setActionGetToolTipText() {
0662:                assertEquals("ToolTipText ", text3, button.getToolTipText());
0663:                action1.putValue(Action.SHORT_DESCRIPTION, text4);
0664:                assertEquals("ToolTipText ", text4, button.getToolTipText());
0665:                button.setAction(action2);
0666:                action1.putValue(Action.SHORT_DESCRIPTION, text4);
0667:                assertNull("ToolTipText ", button.getToolTipText());
0668:                action2.putValue(Action.SHORT_DESCRIPTION, text4);
0669:                assertEquals("ToolTipText ", text4, button.getToolTipText());
0670:            }
0671:
0672:            public void testGetAction() {
0673:                Action action1 = new AbstractAction() {
0674:                    public void actionPerformed(final ActionEvent event) {
0675:                    }
0676:                };
0677:                Action action2 = new AbstractAction() {
0678:                    public void actionPerformed(final ActionEvent event) {
0679:                    }
0680:                };
0681:                assertNull("default action ", button.getAction());
0682:                button.setAction(action1);
0683:                assertEquals("action ", action1, button.getAction());
0684:                button.setAction(action2);
0685:                assertEquals("action ", action2, button.getAction());
0686:            }
0687:
0688:            public void testSetSelectedIcon() {
0689:                Icon icon1 = createNewIcon();
0690:                Icon icon2 = createNewIcon();
0691:                PropertyChangeController listener1 = new PropertyChangeController();
0692:                PropertyChangeController listener2 = new PropertyChangeController();
0693:                button.addPropertyChangeListener(listener1);
0694:                button.addPropertyChangeListener(listener2);
0695:                button.setSelectedIcon(icon1);
0696:                listener1.checkPropertyFired(button, "selectedIcon", null,
0697:                        icon1);
0698:                listener2.checkPropertyFired(button, "selectedIcon", null,
0699:                        icon1);
0700:                listener1.reset();
0701:                listener2.reset();
0702:                button.setSelectedIcon(icon2);
0703:                listener1.checkPropertyFired(button, "selectedIcon", icon1,
0704:                        icon2);
0705:                listener2.checkPropertyFired(button, "selectedIcon", icon1,
0706:                        icon2);
0707:                listener1.reset();
0708:                listener2.reset();
0709:                button.setSelectedIcon(icon2);
0710:                assertFalse("event's not been fired ", listener1.isChanged());
0711:                assertFalse("event's not been fired ", listener2.isChanged());
0712:                listener1.reset();
0713:                listener2.reset();
0714:            }
0715:
0716:            public void testSetRolloverSelectedIcon() {
0717:                PropertyChangeController listener = new PropertyChangeController();
0718:                Icon icon1 = createNewIcon();
0719:                Icon icon2 = createNewIcon();
0720:                button.setRolloverEnabled(true);
0721:                button.addPropertyChangeListener(listener);
0722:                button.setRolloverSelectedIcon(icon1);
0723:                listener.checkLastPropertyFired(button, "rolloverSelectedIcon",
0724:                        null, icon1);
0725:                button.setRolloverEnabled(false);
0726:                listener.reset();
0727:                button.setRolloverSelectedIcon(icon2);
0728:                listener.checkPropertyFired(button, "rolloverSelectedIcon",
0729:                        icon1, icon2);
0730:                listener.checkPropertyFired(button, "rolloverEnabled",
0731:                        Boolean.FALSE, Boolean.TRUE);
0732:                listener.reset();
0733:                button.setRolloverSelectedIcon(icon2);
0734:                assertFalse("event's not been fired ", listener.isChanged());
0735:                button.setRolloverSelectedIcon(null);
0736:                button.setRolloverEnabled(false);
0737:                listener.reset();
0738:                if (isHarmony()) {
0739:                    button.setRolloverSelectedIcon(null);
0740:                    assertFalse("event fired", listener.isChanged());
0741:                }
0742:            }
0743:
0744:            public void testSetRolloverIcon() {
0745:                PropertyChangeController listener = new PropertyChangeController();
0746:                Icon icon1 = createNewIcon();
0747:                Icon icon2 = createNewIcon();
0748:                button.setRolloverEnabled(true);
0749:                button.addPropertyChangeListener(listener);
0750:                button.setRolloverIcon(icon1);
0751:                listener.checkLastPropertyFired(button, "rolloverIcon", null,
0752:                        icon1);
0753:                button.setRolloverEnabled(false);
0754:                listener.reset();
0755:                button.setRolloverIcon(icon2);
0756:                listener.checkPropertyFired(button, "rolloverIcon", icon1,
0757:                        icon2);
0758:                listener.checkPropertyFired(button, "rolloverEnabled",
0759:                        Boolean.FALSE, Boolean.TRUE);
0760:                listener.reset();
0761:                button.setRolloverIcon(icon2);
0762:                assertFalse("event's not been fired ", listener.isChanged());
0763:                button.setRolloverIcon(null);
0764:                button.setRolloverEnabled(false);
0765:                listener.reset();
0766:                if (isHarmony()) {
0767:                    button.setRolloverIcon(null);
0768:                    assertFalse("event's not been fired ", listener.isChanged());
0769:                }
0770:            }
0771:
0772:            public void testSetPressedIcon() {
0773:                Icon icon1 = createNewIcon();
0774:                Icon icon2 = createNewIcon();
0775:                PropertyChangeController listener1 = new PropertyChangeController();
0776:                PropertyChangeController listener2 = new PropertyChangeController();
0777:                button.addPropertyChangeListener(listener1);
0778:                button.addPropertyChangeListener(listener2);
0779:                button.setPressedIcon(icon1);
0780:                listener1
0781:                        .checkPropertyFired(button, "pressedIcon", null, icon1);
0782:                listener2
0783:                        .checkPropertyFired(button, "pressedIcon", null, icon1);
0784:                listener1.reset();
0785:                listener2.reset();
0786:                button.setPressedIcon(icon2);
0787:                listener1.checkPropertyFired(button, "pressedIcon", icon1,
0788:                        icon2);
0789:                listener2.checkPropertyFired(button, "pressedIcon", icon1,
0790:                        icon2);
0791:                listener1.reset();
0792:                listener2.reset();
0793:                button.setPressedIcon(icon2);
0794:                assertFalse("event's not been fired ", listener1.isChanged());
0795:                assertFalse("event's not been fired ", listener2.isChanged());
0796:                listener1.reset();
0797:                listener2.reset();
0798:            }
0799:
0800:            public void testSetIcon() {
0801:                Icon icon1 = createNewIcon();
0802:                Icon icon2 = createNewIcon();
0803:                PropertyChangeController listener1 = new PropertyChangeController();
0804:                PropertyChangeController listener2 = new PropertyChangeController();
0805:                button.addPropertyChangeListener(listener1);
0806:                button.addPropertyChangeListener(listener2);
0807:                button.setIcon(icon1);
0808:                listener1.checkPropertyFired(button, "icon", null, icon1);
0809:                listener2.checkPropertyFired(button, "icon", null, icon1);
0810:                listener1.reset();
0811:                listener2.reset();
0812:                button.setIcon(icon2);
0813:                listener1.checkPropertyFired(button, "icon", icon1, icon2);
0814:                listener2.checkPropertyFired(button, "icon", icon1, icon2);
0815:                listener1.reset();
0816:                listener2.reset();
0817:                button.setIcon(icon2);
0818:                assertFalse("event's not been fired ", listener1.isChanged());
0819:                assertFalse("event's not been fired ", listener2.isChanged());
0820:                listener1.reset();
0821:                listener2.reset();
0822:            }
0823:
0824:            public void testSetDisabledSelectedIcon() {
0825:                Icon icon1 = createNewIcon();
0826:                Icon icon2 = createNewIcon();
0827:                PropertyChangeController listener1 = new PropertyChangeController();
0828:                PropertyChangeController listener2 = new PropertyChangeController();
0829:                button.addPropertyChangeListener(listener1);
0830:                button.addPropertyChangeListener(listener2);
0831:                button.setDisabledSelectedIcon(icon1);
0832:                listener1.checkPropertyFired(button, "disabledSelectedIcon",
0833:                        null, icon1);
0834:                listener2.checkPropertyFired(button, "disabledSelectedIcon",
0835:                        null, icon1);
0836:                listener1.reset();
0837:                listener2.reset();
0838:                button.setDisabledSelectedIcon(icon2);
0839:                listener1.checkPropertyFired(button, "disabledSelectedIcon",
0840:                        icon1, icon2);
0841:                listener2.checkPropertyFired(button, "disabledSelectedIcon",
0842:                        icon1, icon2);
0843:                listener1.reset();
0844:                listener2.reset();
0845:                button.setDisabledSelectedIcon(icon2);
0846:                assertFalse("event's not been fired ", listener1.isChanged());
0847:                assertFalse("event's not been fired ", listener2.isChanged());
0848:                listener1.reset();
0849:                listener2.reset();
0850:            }
0851:
0852:            public void testSetDisabledIcon() {
0853:                Icon icon1 = createNewIcon();
0854:                Icon icon2 = createNewIcon();
0855:                PropertyChangeController listener1 = new PropertyChangeController();
0856:                PropertyChangeController listener2 = new PropertyChangeController();
0857:                button.addPropertyChangeListener(listener1);
0858:                button.addPropertyChangeListener(listener2);
0859:                button.setDisabledIcon(icon1);
0860:                listener1.checkPropertyFired(button, "disabledIcon", null,
0861:                        icon1);
0862:                listener2.checkPropertyFired(button, "disabledIcon", null,
0863:                        icon1);
0864:                listener1.reset();
0865:                listener2.reset();
0866:                button.setDisabledIcon(icon2);
0867:                listener1.checkPropertyFired(button, "disabledIcon", icon1,
0868:                        icon2);
0869:                listener2.checkPropertyFired(button, "disabledIcon", icon1,
0870:                        icon2);
0871:                listener1.reset();
0872:                listener2.reset();
0873:                button.setDisabledIcon(icon2);
0874:                assertFalse("event's not been fired ", listener1.isChanged());
0875:                assertFalse("event's not been fired ", listener2.isChanged());
0876:                listener1.reset();
0877:                listener2.reset();
0878:            }
0879:
0880:            public void testGetSelectedIcon() {
0881:                Icon icon1 = createNewIcon();
0882:                Icon icon2 = createNewIcon();
0883:                assertNull("default Selected Icon ", button.getSelectedIcon());
0884:                button.setSelectedIcon(icon1);
0885:                assertEquals("Selected Icon ", icon1, button.getSelectedIcon());
0886:                button.setSelectedIcon(icon2);
0887:                assertEquals("Selected Icon ", icon2, button.getSelectedIcon());
0888:            }
0889:
0890:            public void testGetRolloverSelectedIcon() {
0891:                Icon icon1 = createNewIcon();
0892:                Icon icon2 = createNewIcon();
0893:                assertNull("default Rollover Selected Icon ", button
0894:                        .getRolloverSelectedIcon());
0895:                button.setRolloverSelectedIcon(icon1);
0896:                assertEquals("Rollover Selected Icon ", icon1, button
0897:                        .getRolloverSelectedIcon());
0898:                button.setRolloverSelectedIcon(icon2);
0899:                assertEquals("Rollover Selected Icon ", icon2, button
0900:                        .getRolloverSelectedIcon());
0901:            }
0902:
0903:            public void testGetRolloverIcon() {
0904:                Icon icon1 = createNewIcon();
0905:                Icon icon2 = createNewIcon();
0906:                assertNull("default Rollover Icon ", button.getRolloverIcon());
0907:                button.setRolloverIcon(icon1);
0908:                assertEquals("Rollover Icon ", icon1, button.getRolloverIcon());
0909:                button.setRolloverIcon(icon2);
0910:                assertEquals("Rollover Icon ", icon2, button.getRolloverIcon());
0911:            }
0912:
0913:            public void testGetPressedIcon() {
0914:                Icon icon1 = createNewIcon();
0915:                Icon icon2 = createNewIcon();
0916:                assertNull("default Pressed Icon ", button.getPressedIcon());
0917:                button.setPressedIcon(icon1);
0918:                assertEquals("Pressed Icon ", icon1, button.getPressedIcon());
0919:                button.setPressedIcon(icon2);
0920:                assertEquals("Pressed Icon ", icon2, button.getPressedIcon());
0921:            }
0922:
0923:            public void testGetIcon() {
0924:                Icon icon1 = createNewIcon();
0925:                Icon icon2 = createNewIcon();
0926:                assertNull("default Icon ", button.getIcon());
0927:                button.setIcon(icon1);
0928:                assertEquals("Icon ", icon1, button.getIcon());
0929:                button.setIcon(icon2);
0930:                assertEquals("Icon ", icon2, button.getIcon());
0931:            }
0932:
0933:            public void testGetDisabledSelectedIcon() {
0934:                Icon icon1 = createNewIcon();
0935:                Icon icon2 = createNewIcon();
0936:                Icon icon3 = createNewIcon();
0937:                assertNull("default Icon ", button.getDisabledSelectedIcon());
0938:                button.setDisabledSelectedIcon(icon1);
0939:                assertEquals("DisabledSelected Icon ", icon1, button
0940:                        .getDisabledSelectedIcon());
0941:                button.setDisabledSelectedIcon(icon2);
0942:                assertEquals("DisabledSelected Icon ", icon2, button
0943:                        .getDisabledSelectedIcon());
0944:                button.setIcon(icon1);
0945:                button.setDisabledSelectedIcon(null);
0946:                button.setDisabledIcon(null);
0947:                assertNotNull(button.getDisabledSelectedIcon());
0948:                assertEquals(icon1.getIconHeight(), button
0949:                        .getDisabledSelectedIcon().getIconHeight());
0950:                assertEquals(icon1.getIconWidth(), button
0951:                        .getDisabledSelectedIcon().getIconWidth());
0952:                button.setIcon(null);
0953:                button.setSelectedIcon(icon2);
0954:                assertNotNull(button.getDisabledSelectedIcon());
0955:                assertEquals(icon2.getIconHeight(), button
0956:                        .getDisabledSelectedIcon().getIconHeight());
0957:                assertEquals(icon2.getIconWidth(), button
0958:                        .getDisabledSelectedIcon().getIconWidth());
0959:                button.setSelectedIcon(null);
0960:                button.setDisabledIcon(icon1);
0961:                assertNotNull(button.getDisabledSelectedIcon());
0962:                assertEquals(icon1.getIconHeight(), button
0963:                        .getDisabledSelectedIcon().getIconHeight());
0964:                assertEquals(icon1.getIconWidth(), button
0965:                        .getDisabledSelectedIcon().getIconWidth());
0966:                button.setSelectedIcon(icon2);
0967:                assertNotNull(button.getDisabledSelectedIcon());
0968:                assertEquals(icon2.getIconHeight(), button
0969:                        .getDisabledSelectedIcon().getIconHeight());
0970:                assertEquals(icon2.getIconWidth(), button
0971:                        .getDisabledSelectedIcon().getIconWidth());
0972:                button.setIcon(icon3);
0973:                assertNotNull(button.getDisabledSelectedIcon());
0974:                assertEquals(icon2.getIconHeight(), button
0975:                        .getDisabledSelectedIcon().getIconHeight());
0976:                assertEquals(icon2.getIconWidth(), button
0977:                        .getDisabledSelectedIcon().getIconWidth());
0978:            }
0979:
0980:            public void testGetDisabledIcon() {
0981:                Icon icon1 = createNewIcon();
0982:                Icon icon2 = createNewIcon();
0983:                assertNull("default Icon ", button.getDisabledIcon());
0984:                button.setDisabledIcon(icon1);
0985:                assertEquals("Disabled Icon ", icon1, button.getDisabledIcon());
0986:                button.setDisabledIcon(icon2);
0987:                assertEquals("Disabled Icon ", icon2, button.getDisabledIcon());
0988:                button.setIcon(icon1);
0989:                button.setDisabledIcon(null);
0990:                assertNotNull(button.getDisabledIcon());
0991:                assertEquals(icon1.getIconHeight(), button.getDisabledIcon()
0992:                        .getIconHeight());
0993:                assertEquals(icon1.getIconWidth(), button.getDisabledIcon()
0994:                        .getIconWidth());
0995:                button.setIcon(new Icon() {
0996:                    public void paintIcon(Component c, Graphics g, int x, int y) {
0997:                    }
0998:
0999:                    public int getIconWidth() {
1000:                        return 10;
1001:                    }
1002:
1003:                    public int getIconHeight() {
1004:                        return 10;
1005:                    }
1006:                });
1007:                assertNull(button.getDisabledIcon());
1008:            }
1009:
1010:            public void testSetModel() {
1011:                DefaultButtonModel model1 = new DefaultButtonModel();
1012:                DefaultButtonModel model2 = new DefaultButtonModel();
1013:                PropertyChangeController listener1 = new PropertyChangeController();
1014:                PropertyChangeController listener2 = new PropertyChangeController();
1015:                button.addPropertyChangeListener(listener1);
1016:                button.addPropertyChangeListener(listener2);
1017:                ButtonModel oldModel = button.getModel();
1018:                button.setModel(model1);
1019:                assertSame(model1, button.getModel());
1020:                listener1.checkPropertyFired(button, "model", oldModel, model1);
1021:                listener2.checkPropertyFired(button, "model", oldModel, model1);
1022:                listener1.reset();
1023:                listener2.reset();
1024:                button.setModel(model2);
1025:                assertSame(model2, button.getModel());
1026:                listener1.checkPropertyFired(button, "model", model1, model2);
1027:                listener2.checkPropertyFired(button, "model", model1, model2);
1028:                assertEquals("model's action listeners ", 0, model1
1029:                        .getActionListeners().length);
1030:                assertEquals("model's change listeners ", 0, model1
1031:                        .getChangeListeners().length);
1032:                listener1.reset();
1033:                listener2.reset();
1034:                button.setModel(model2);
1035:                assertFalse("event's not been fired ", listener1.isChanged());
1036:                assertFalse("event's not been fired ", listener2.isChanged());
1037:                listener1.reset();
1038:                listener2.reset();
1039:            }
1040:
1041:            public void testNumberOfModelListeners() {
1042:                button.setUI(null);
1043:                DefaultButtonModel model = (DefaultButtonModel) button
1044:                        .getModel();
1045:                assertEquals("model's action listeners ", 1, model
1046:                        .getActionListeners().length);
1047:                assertEquals("model's item listeners ", 1, model
1048:                        .getItemListeners().length);
1049:                assertEquals("model's change listeners ", 1, model
1050:                        .getChangeListeners().length);
1051:            }
1052:
1053:            public void testGetModel() {
1054:                ButtonModel model1 = new DefaultButtonModel();
1055:                ButtonModel model2 = new DefaultButtonModel();
1056:                assertNotNull("default buttonModel ", button.getModel());
1057:                button.setModel(model1);
1058:                assertEquals("buttonModel ", model1, button.getModel());
1059:                button.setModel(model2);
1060:                assertEquals("buttonModel ", model2, button.getModel());
1061:                button = new AbstractButton() {
1062:                };
1063:                assertNull("default buttonModel", button.getModel());
1064:            }
1065:
1066:            public void testSetActionCommand() {
1067:                String command1 = "When one door is closed";
1068:                String command2 = "Don't you know other is opened?";
1069:                button.setActionCommand(command1);
1070:                assertEquals("comman action ", command1, button
1071:                        .getActionCommand());
1072:                button.setActionCommand(command2);
1073:                assertEquals("comman action ", command2, button
1074:                        .getActionCommand());
1075:            }
1076:
1077:            public void testGetActionCommand() {
1078:                assertEquals("default comman action ", "", button
1079:                        .getActionCommand());
1080:            }
1081:
1082:            public void testCheckVerticalKey() {
1083:                String exceptionText = "exceptionText";
1084:                int res = button.checkVerticalKey(SwingConstants.TOP,
1085:                        exceptionText);
1086:                assertEquals("returned value ", 1, res);
1087:                try {
1088:                    res = button.checkVerticalKey(SwingConstants.WEST,
1089:                            exceptionText);
1090:                } catch (IllegalArgumentException e) {
1091:                    assertEquals("exception's message ", exceptionText, e
1092:                            .getMessage());
1093:                    return;
1094:                }
1095:
1096:                fail("Expected IllegalArgumentException to be thrown");
1097:            }
1098:
1099:            public void testCheckHorizontalKey() {
1100:                String exceptionText = "exceptionText";
1101:                int res = button.checkHorizontalKey(SwingConstants.TRAILING,
1102:                        exceptionText);
1103:                assertEquals("returned value ", SwingConstants.TRAILING, res);
1104:                try {
1105:                    res = button.checkHorizontalKey(SwingConstants.TOP,
1106:                            exceptionText);
1107:                } catch (IllegalArgumentException e) {
1108:                    assertEquals("exception's message ", exceptionText, e
1109:                            .getMessage());
1110:                    return;
1111:                }
1112:
1113:                fail("Expected IllegalArgumentException to be thrown");
1114:            }
1115:
1116:            public void testCreateActionPropertyChangeListener() {
1117:                Object res1 = null;
1118:                Object res2 = null;
1119:                AbstractAction action1 = new AbstractAction() {
1120:                    private static final long serialVersionUID = 1L;
1121:
1122:                    public void actionPerformed(final ActionEvent event) {
1123:                    }
1124:                };
1125:                res1 = button.createActionPropertyChangeListener(action1);
1126:                assertNotNull(res1);
1127:                res2 = button.createActionPropertyChangeListener(null);
1128:                assertNotNull(res2);
1129:            }
1130:
1131:            public void testCreateActionListener() throws Exception {
1132:                Object res1 = button.createActionListener();
1133:                Object res2 = button.createActionListener();
1134:                assertNotNull(res1);
1135:                assertNotNull(res2);
1136:                if (isHarmony()) {
1137:                    assertSame("created listener is shared ", res1, res2);
1138:                }
1139:            }
1140:
1141:            public void testCreateItemListener() {
1142:                button.itemListener = null;
1143:                Object res1 = button.createItemListener();
1144:                Object res2 = button.createItemListener();
1145:                assertNotNull(res1);
1146:                assertNotNull(res2);
1147:                assertNull(button.itemListener);
1148:            }
1149:
1150:            public void testCreateChangeListener() {
1151:                button.changeListener = null;
1152:                Object res1 = button.createChangeListener();
1153:                Object res2 = button.createChangeListener();
1154:                assertNotNull(res1);
1155:                assertNotNull(res2);
1156:                assertNull(button.changeListener);
1157:            }
1158:
1159:            public void testRemoveChangeListener() {
1160:                ChangeListener listener1 = new ConcreteChangeListener();
1161:                ChangeListener listener2 = new ConcreteChangeListener();
1162:                ChangeListener listener3 = new ConcreteChangeListener();
1163:                button.addChangeListener(listener1);
1164:                button.addChangeListener(listener2);
1165:                button.addChangeListener(listener2);
1166:                button.addChangeListener(listener3);
1167:                EventListener[] listeners = button
1168:                        .getListeners(ChangeListener.class);
1169:                assertTrue("listener's array is valid ", listeners != null);
1170:                button.removeChangeListener(listener1);
1171:                listeners = button.getListeners(ChangeListener.class);
1172:                assertTrue("listener's array is valid ", listeners != null);
1173:                assertTrue("listener's removed successfully ", find(listeners,
1174:                        listener3) == 1);
1175:                assertTrue("listener's removed successfully ", find(listeners,
1176:                        listener2) == 2);
1177:                button.removeChangeListener(listener2);
1178:                listeners = button.getListeners(ChangeListener.class);
1179:                assertTrue("listener's array is valid ", listeners != null);
1180:                assertTrue("listener's removed successfully ", find(listeners,
1181:                        listener3) == 1);
1182:                assertTrue("listener's removed successfully ", find(listeners,
1183:                        listener2) == 1);
1184:                button.removeChangeListener(listener2);
1185:                listeners = button.getListeners(ChangeListener.class);
1186:                assertTrue("listener's array is valid ", listeners != null);
1187:                assertTrue("listener's removed successfully ", find(listeners,
1188:                        listener3) == 1);
1189:                assertTrue("listener's removed successfully ", find(listeners,
1190:                        listener2) == 0);
1191:                button.removeChangeListener(listener2);
1192:                listeners = button.getListeners(ChangeListener.class);
1193:                assertTrue("listener's array is valid ", listeners != null);
1194:                assertTrue("listener's removed successfully ", find(listeners,
1195:                        listener3) == 1);
1196:                assertTrue("listener's removed successfully ", find(listeners,
1197:                        listener2) == 0);
1198:                button.removeChangeListener(listener3);
1199:                listeners = button.getListeners(ChangeListener.class);
1200:                assertTrue("listener's array is valid ", listeners != null);
1201:                assertTrue("listener's removed successfully ", find(listeners,
1202:                        listener3) == 0);
1203:            }
1204:
1205:            public void testAddChangeListener() {
1206:                ChangeListener listener1 = new ConcreteChangeListener();
1207:                ChangeListener listener2 = new ConcreteChangeListener();
1208:                EventListener[] listeners = button.getChangeListeners();
1209:                int numListeners = listeners.length;
1210:                button.addChangeListener(null);
1211:                listeners = button.getChangeListeners();
1212:                assertEquals("listener's array is valid ", numListeners,
1213:                        listeners.length);
1214:                button.addChangeListener(listener1);
1215:                listeners = button.getListeners(ChangeListener.class);
1216:                assertTrue("listener's array is valid ", listeners != null);
1217:                assertTrue("listener's added successfully ", find(listeners,
1218:                        listener1) == 1);
1219:                button.addChangeListener(listener2);
1220:                listeners = button.getListeners(ChangeListener.class);
1221:                assertTrue("listener's array is valid ", listeners != null);
1222:                assertTrue("listener's added successfully ", find(listeners,
1223:                        listener1) == 1);
1224:                assertTrue("listener's added successfully ", find(listeners,
1225:                        listener2) == 1);
1226:                button.addChangeListener(listener2);
1227:                listeners = button.getListeners(ChangeListener.class);
1228:                assertTrue("listener's array is valid ", listeners != null);
1229:                assertTrue("listener's added successfully ", find(listeners,
1230:                        listener1) == 1);
1231:                assertTrue("listener's added successfully ", find(listeners,
1232:                        listener2) == 2);
1233:            }
1234:
1235:            /**
1236:             * this method is being tested mostly with testAddChangeListener()
1237:             * and testRemoveChangeListener()
1238:             */
1239:            public void testGetChangeListeners() {
1240:                EventListener[] listeners = button
1241:                        .getListeners(ChangeListener.class);
1242:                assertTrue("listener's array is not null ", listeners != null);
1243:            }
1244:
1245:            public void testFireStateChanged() {
1246:                ChangeEvent event1 = null;
1247:                ChangeEvent event2 = null;
1248:                ConcreteChangeListener listener1 = new ConcreteChangeListener();
1249:                ConcreteChangeListener listener2 = new ConcreteChangeListener();
1250:                button.addChangeListener(listener1);
1251:                button.addChangeListener(listener2);
1252:                button.fireStateChanged();
1253:                event1 = listener1.eventHappened;
1254:                assertTrue("event fired ", listener1.eventHappened != null);
1255:                assertTrue("event fired ", listener2.eventHappened != null);
1256:                assertTrue("one event fired ",
1257:                        listener1.eventHappened == listener2.eventHappened);
1258:                assertEquals("event fired properly ", ChangeEvent.class,
1259:                        listener1.eventHappened.getClass());
1260:                assertEquals("event fired properly ", ChangeEvent.class,
1261:                        listener2.eventHappened.getClass());
1262:                assertEquals("event's source ", button, listener1.eventHappened
1263:                        .getSource());
1264:                assertEquals("event's source ", button, listener2.eventHappened
1265:                        .getSource());
1266:                button.fireStateChanged();
1267:                event2 = listener1.eventHappened;
1268:                assertTrue("event fired ", listener1.eventHappened != null);
1269:                assertTrue("event fired ", listener2.eventHappened != null);
1270:                assertTrue("one event fired ",
1271:                        listener1.eventHappened == listener2.eventHappened);
1272:                assertEquals("event's class ", ChangeEvent.class,
1273:                        listener1.eventHappened.getClass());
1274:                assertEquals("event's class ", ChangeEvent.class,
1275:                        listener2.eventHappened.getClass());
1276:                assertEquals("event's source ", button, listener1.eventHappened
1277:                        .getSource());
1278:                assertEquals("event's source ", button, listener2.eventHappened
1279:                        .getSource());
1280:                assertTrue("the same event is fired always ", event1 == event2);
1281:            }
1282:
1283:            public void testRemoveItemListener() {
1284:                ItemListener listener1 = new ConcreteItemListener();
1285:                ItemListener listener2 = new ConcreteItemListener();
1286:                ItemListener listener3 = new ConcreteItemListener();
1287:                button.addItemListener(listener1);
1288:                button.addItemListener(listener2);
1289:                button.addItemListener(listener2);
1290:                button.addItemListener(listener3);
1291:                EventListener[] listeners = button
1292:                        .getListeners(ItemListener.class);
1293:                assertTrue("listener's array has the proper size ",
1294:                        listeners != null && listeners.length == 4);
1295:                button.removeItemListener(listener1);
1296:                listeners = button.getListeners(ItemListener.class);
1297:                assertTrue("listener's array has the proper size ",
1298:                        listeners != null && listeners.length == 3);
1299:                assertTrue("listener's removed successfully ", find(listeners,
1300:                        listener3) == 1);
1301:                assertTrue("listener's removed successfully ", find(listeners,
1302:                        listener2) == 2);
1303:                button.removeItemListener(listener2);
1304:                listeners = button.getListeners(ItemListener.class);
1305:                assertTrue("listener's array has the proper size ",
1306:                        listeners != null && listeners.length == 2);
1307:                assertTrue("listener's removed successfully ", find(listeners,
1308:                        listener3) == 1);
1309:                assertTrue("listener's removed successfully ", find(listeners,
1310:                        listener2) == 1);
1311:                button.removeItemListener(listener2);
1312:                listeners = button.getListeners(ItemListener.class);
1313:                assertTrue("listener's array has the proper size ",
1314:                        listeners != null && listeners.length == 1);
1315:                assertTrue("listener's removed successfully ", find(listeners,
1316:                        listener3) == 1);
1317:                assertTrue("listener's removed successfully ", find(listeners,
1318:                        listener2) == 0);
1319:                button.removeItemListener(listener2);
1320:                listeners = button.getListeners(ItemListener.class);
1321:                assertTrue("listener's array has the proper size ",
1322:                        listeners != null && listeners.length == 1);
1323:                assertTrue("listener's removed successfully ", find(listeners,
1324:                        listener3) == 1);
1325:                assertTrue("listener's removed successfully ", find(listeners,
1326:                        listener2) == 0);
1327:                button.removeItemListener(listener3);
1328:                listeners = button.getListeners(ItemListener.class);
1329:                assertTrue("listener's array has the proper size ",
1330:                        listeners != null && listeners.length == 0);
1331:                assertTrue("listener's removed successfully ", find(listeners,
1332:                        listener3) == 0);
1333:            }
1334:
1335:            public void testAddItemListener() {
1336:                ItemListener listener1 = new ConcreteItemListener();
1337:                ItemListener listener2 = new ConcreteItemListener();
1338:                button.addItemListener(listener1);
1339:                EventListener[] listeners = button
1340:                        .getListeners(ItemListener.class);
1341:                assertTrue("listener's array has the proper size ",
1342:                        listeners != null && listeners.length == 1);
1343:                assertEquals("listener's added successfully ", listeners[0],
1344:                        listener1);
1345:                button.addItemListener(listener2);
1346:                listeners = button.getListeners(ItemListener.class);
1347:                assertTrue("listener's array has the proper size ",
1348:                        listeners != null && listeners.length == 2);
1349:                assertTrue("listener's added successfully ", find(listeners,
1350:                        listener1) == 1);
1351:                assertTrue("listener's added successfully ", find(listeners,
1352:                        listener2) == 1);
1353:                button.addItemListener(listener2);
1354:                listeners = button.getListeners(ItemListener.class);
1355:                assertTrue("listener's array has the proper size ",
1356:                        listeners != null && listeners.length == 3);
1357:                assertTrue("listener's added successfully ", find(listeners,
1358:                        listener1) == 1);
1359:                assertTrue("listener's added successfully ", find(listeners,
1360:                        listener2) == 2);
1361:            }
1362:
1363:            /**
1364:             * this method is being tested mostly with testAddItemListener()
1365:             * and testRemoveItemListener()
1366:             */
1367:            public void testGetItemListeners() {
1368:                EventListener[] listeners = button
1369:                        .getListeners(ItemListener.class);
1370:                assertTrue("listener's array has the proper size ",
1371:                        listeners != null && listeners.length == 0);
1372:            }
1373:
1374:            public void testFireItemStateChanged() {
1375:                Object item1 = "item1";
1376:                Object item2 = "item2";
1377:                ItemEvent event1 = new ItemEvent(button, 11, item1, 2);
1378:                ItemEvent event2 = new ItemEvent(button, 111, item2, 1);
1379:                ConcreteItemListener listener1 = new ConcreteItemListener();
1380:                ConcreteItemListener listener2 = new ConcreteItemListener();
1381:                button.addItemListener(listener1);
1382:                button.addItemListener(listener2);
1383:                button.fireItemStateChanged(event1);
1384:                assertEquals("event's ID ", ItemEvent.ITEM_STATE_CHANGED,
1385:                        listener1.eventHappened.getID());
1386:                assertEquals("event's item ", button, listener1.eventHappened
1387:                        .getItem());
1388:                assertEquals("event's source ", button, listener1.eventHappened
1389:                        .getSource());
1390:                assertEquals("event's StateChange ", ItemEvent.DESELECTED,
1391:                        listener1.eventHappened.getStateChange());
1392:                assertEquals("event's ID ", ItemEvent.ITEM_STATE_CHANGED,
1393:                        listener2.eventHappened.getID());
1394:                assertEquals("event's item ", button, listener2.eventHappened
1395:                        .getItem());
1396:                assertEquals("event's source ", button, listener2.eventHappened
1397:                        .getSource());
1398:                assertEquals("event's StateChange ", ItemEvent.DESELECTED,
1399:                        listener2.eventHappened.getStateChange());
1400:                button.fireItemStateChanged(event2);
1401:                assertEquals("event's ID ", ItemEvent.ITEM_STATE_CHANGED,
1402:                        listener1.eventHappened.getID());
1403:                assertEquals("event's item ", button, listener1.eventHappened
1404:                        .getItem());
1405:                assertEquals("event's source ", button, listener1.eventHappened
1406:                        .getSource());
1407:                assertEquals("event's StateChange ", ItemEvent.SELECTED,
1408:                        listener1.eventHappened.getStateChange());
1409:                assertEquals("event's ID ", ItemEvent.ITEM_STATE_CHANGED,
1410:                        listener2.eventHappened.getID());
1411:                assertEquals("event's item ", button, listener2.eventHappened
1412:                        .getItem());
1413:                assertEquals("event's source ", button, listener2.eventHappened
1414:                        .getSource());
1415:                assertEquals("event's StateChange ", ItemEvent.SELECTED,
1416:                        listener2.eventHappened.getStateChange());
1417:            }
1418:
1419:            public void testRemoveActionListener() {
1420:                final int startLength = button
1421:                        .getListeners(ActionListener.class).length;
1422:                ActionListener listener1 = new ConcreteActionListener();
1423:                ActionListener listener2 = new ConcreteActionListener();
1424:                ActionListener listener3 = new ConcreteActionListener();
1425:                button.addActionListener(listener1);
1426:                button.addActionListener(listener2);
1427:                button.addActionListener(listener2);
1428:                button.addActionListener(listener3);
1429:                EventListener[] listeners = button
1430:                        .getListeners(ActionListener.class);
1431:                assertTrue("listener's array has the proper size ",
1432:                        listeners != null
1433:                                && listeners.length == 4 + startLength);
1434:                button.removeActionListener(listener1);
1435:                listeners = button.getListeners(ActionListener.class);
1436:                assertEquals(listeners.length, 3 + startLength);
1437:                assertEquals(find(listeners, listener3), 1);
1438:                assertEquals(find(listeners, listener2), 2);
1439:                button.removeActionListener(listener2);
1440:                listeners = button.getListeners(ActionListener.class);
1441:                assertEquals(listeners.length, 2 + startLength);
1442:                assertEquals(find(listeners, listener3), 1);
1443:                assertEquals(find(listeners, listener2), 1);
1444:                button.removeActionListener(listener2);
1445:                listeners = button.getListeners(ActionListener.class);
1446:                assertTrue("listener's array has the proper size ",
1447:                        listeners != null
1448:                                && listeners.length == 1 + startLength);
1449:                assertTrue("listener's removed successfully ", find(listeners,
1450:                        listener3) == 1);
1451:                assertTrue("listener's removed successfully ", find(listeners,
1452:                        listener2) == 0);
1453:                button.removeActionListener(listener2);
1454:                listeners = button.getListeners(ActionListener.class);
1455:                assertTrue("listener's array has the proper size ",
1456:                        listeners != null
1457:                                && listeners.length == 1 + startLength);
1458:                assertTrue("listener's removed successfully ", find(listeners,
1459:                        listener3) == 1);
1460:                assertTrue("listener's removed successfully ", find(listeners,
1461:                        listener2) == 0);
1462:                button.removeActionListener(listener3);
1463:                listeners = button.getListeners(ActionListener.class);
1464:                assertTrue("listener's array has the proper size ",
1465:                        listeners != null
1466:                                && listeners.length == 0 + startLength);
1467:                assertTrue("listener's removed successfully ", find(listeners,
1468:                        listener3) == 0);
1469:            }
1470:
1471:            public void testAddActionListener() {
1472:                final int startLength = button
1473:                        .getListeners(ActionListener.class).length;
1474:                ActionListener listener1 = new ConcreteActionListener();
1475:                ActionListener listener2 = new ConcreteActionListener();
1476:                button.addActionListener(listener1);
1477:                EventListener[] listeners = button
1478:                        .getListeners(ActionListener.class);
1479:                assertEquals(listeners.length, 1 + startLength);
1480:                assertEquals(listeners[0], listener1);
1481:                button.addActionListener(listener2);
1482:                listeners = button.getListeners(ActionListener.class);
1483:                assertEquals(listeners.length, 2 + startLength);
1484:                assertEquals(find(listeners, listener1), 1);
1485:                assertEquals(find(listeners, listener2), 1);
1486:                button.addActionListener(listener2);
1487:                listeners = button.getListeners(ActionListener.class);
1488:                assertEquals(listeners.length, 3 + startLength);
1489:                assertEquals(find(listeners, listener1), 1);
1490:                assertEquals(find(listeners, listener2), 2);
1491:            }
1492:
1493:            /**
1494:             * this method is being tested mostly with testAddActionListener()
1495:             * and testRemoveActionListener()
1496:             */
1497:            public void testGetActionListeners() {
1498:                button.setUI(null);
1499:                EventListener[] listeners = button.getActionListeners();
1500:                assertEquals(listeners.length, 0);
1501:            }
1502:
1503:            public void testFireActionPerformed() {
1504:                String command1 = "command1";
1505:                String command2 = "command2";
1506:                String command3 = "command3";
1507:                ActionEvent event1 = new ActionEvent(button, 11, command1, 2);
1508:                ActionEvent event2 = new ActionEvent(button, 111, command2, 1);
1509:                ActionEvent event3 = new ActionEvent(button, 1111, null, 1);
1510:                ConcreteActionListener listener1 = new ConcreteActionListener();
1511:                ConcreteActionListener listener2 = new ConcreteActionListener();
1512:                button.setText(command3);
1513:                button.addActionListener(listener1);
1514:                button.addActionListener(listener2);
1515:                button.fireActionPerformed(event1);
1516:                assertEquals("event's source ", event1.getSource(),
1517:                        listener1.eventHappened.getSource());
1518:                assertEquals("event's command ", event1.getActionCommand(),
1519:                        listener1.eventHappened.getActionCommand());
1520:                assertEquals("event's ID ", ActionEvent.ACTION_PERFORMED,
1521:                        listener1.eventHappened.getID());
1522:                assertEquals("event's modifiers ", event1.getModifiers(),
1523:                        listener1.eventHappened.getModifiers());
1524:                assertEquals("event's source ", event1.getSource(),
1525:                        listener2.eventHappened.getSource());
1526:                assertEquals("event's command ", event1.getActionCommand(),
1527:                        listener2.eventHappened.getActionCommand());
1528:                assertEquals("event's ID ", ActionEvent.ACTION_PERFORMED,
1529:                        listener2.eventHappened.getID());
1530:                assertEquals("event's modifiers ", event1.getModifiers(),
1531:                        listener2.eventHappened.getModifiers());
1532:                button.fireActionPerformed(event2);
1533:                assertEquals("event's source ", event2.getSource(),
1534:                        listener1.eventHappened.getSource());
1535:                assertEquals("event's command ", event2.getActionCommand(),
1536:                        listener1.eventHappened.getActionCommand());
1537:                assertEquals("event's ID ", ActionEvent.ACTION_PERFORMED,
1538:                        listener1.eventHappened.getID());
1539:                assertEquals("event's modifiers ", event2.getModifiers(),
1540:                        listener1.eventHappened.getModifiers());
1541:                assertEquals("event's source ", event2.getSource(),
1542:                        listener2.eventHappened.getSource());
1543:                assertEquals("event's command ", event2.getActionCommand(),
1544:                        listener2.eventHappened.getActionCommand());
1545:                assertEquals("event's ID ", ActionEvent.ACTION_PERFORMED,
1546:                        listener2.eventHappened.getID());
1547:                assertEquals("event's modifiers ", event2.getModifiers(),
1548:                        listener2.eventHappened.getModifiers());
1549:                button.fireActionPerformed(event3);
1550:                assertEquals("event's source ", event2.getSource(),
1551:                        listener1.eventHappened.getSource());
1552:                assertEquals("event's command ", command3,
1553:                        listener1.eventHappened.getActionCommand());
1554:                assertEquals("event's ID ", ActionEvent.ACTION_PERFORMED,
1555:                        listener1.eventHappened.getID());
1556:                assertEquals("event's modifiers ", event2.getModifiers(),
1557:                        listener1.eventHappened.getModifiers());
1558:            }
1559:
1560:            public void testSetIconTextGap() {
1561:                PropertyChangeController listener1 = new PropertyChangeController();
1562:                PropertyChangeController listener2 = new PropertyChangeController();
1563:                int value1 = 20;
1564:                int value2 = 13;
1565:                button.addPropertyChangeListener(listener1);
1566:                button.addPropertyChangeListener(listener2);
1567:                button.setIconTextGap(value1);
1568:                listener1.checkPropertyFired(button, "iconTextGap",
1569:                        new Integer(4), new Integer(value1));
1570:                listener2.checkPropertyFired(button, "iconTextGap",
1571:                        new Integer(4), new Integer(value1));
1572:                listener1.reset();
1573:                listener2.reset();
1574:                button.setIconTextGap(value2);
1575:                listener1.checkPropertyFired(button, "iconTextGap",
1576:                        new Integer(value1), new Integer(value2));
1577:                listener2.checkPropertyFired(button, "iconTextGap",
1578:                        new Integer(value1), new Integer(value2));
1579:                listener1.reset();
1580:                listener2.reset();
1581:                button.setIconTextGap(value2);
1582:                assertFalse("event's not been fired ", listener1.isChanged());
1583:                assertFalse("event's not been fired ", listener2.isChanged());
1584:                listener1.reset();
1585:                listener2.reset();
1586:            }
1587:
1588:            public void testGetIconTextGap() {
1589:                int value1 = -100;
1590:                int value2 = 1;
1591:                int value3 = 100;
1592:                assertEquals("default IconTextGap", 4, button.getIconTextGap());
1593:                button.setIconTextGap(value1);
1594:                assertEquals("IconTextGap", value1, button.getIconTextGap());
1595:                button.setIconTextGap(value2);
1596:                assertEquals("IconTextGap", value2, button.getIconTextGap());
1597:                button.setIconTextGap(value3);
1598:                assertEquals("IconTextGap", value3, button.getIconTextGap());
1599:            }
1600:
1601:            public void testSetVerticalTextPosition() {
1602:                PropertyChangeController listener1 = new PropertyChangeController();
1603:                PropertyChangeController listener2 = new PropertyChangeController();
1604:                button.addPropertyChangeListener(listener1);
1605:                button.addPropertyChangeListener(listener2);
1606:                button.setVerticalTextPosition(SwingConstants.TOP);
1607:                listener1.checkPropertyFired(button, "verticalTextPosition",
1608:                        new Integer(SwingConstants.CENTER), new Integer(
1609:                                SwingConstants.TOP));
1610:                listener2.checkPropertyFired(button, "verticalTextPosition",
1611:                        new Integer(SwingConstants.CENTER), new Integer(
1612:                                SwingConstants.TOP));
1613:                listener1.reset();
1614:                listener2.reset();
1615:                button.setVerticalTextPosition(SwingConstants.BOTTOM);
1616:                listener1.checkPropertyFired(button, "verticalTextPosition",
1617:                        new Integer(SwingConstants.TOP), new Integer(
1618:                                SwingConstants.BOTTOM));
1619:                listener2.checkPropertyFired(button, "verticalTextPosition",
1620:                        new Integer(SwingConstants.TOP), new Integer(
1621:                                SwingConstants.BOTTOM));
1622:                listener1.reset();
1623:                listener2.reset();
1624:                button.setVerticalTextPosition(SwingConstants.BOTTOM);
1625:                assertFalse("event's not been fired ", listener1.isChanged());
1626:                assertFalse("event's not been fired ", listener2.isChanged());
1627:                listener1.reset();
1628:                listener2.reset();
1629:            }
1630:
1631:            public void testSetVerticalAlignment() {
1632:                PropertyChangeController listener1 = new PropertyChangeController();
1633:                PropertyChangeController listener2 = new PropertyChangeController();
1634:                button.addPropertyChangeListener(listener1);
1635:                button.addPropertyChangeListener(listener2);
1636:                button.setVerticalAlignment(SwingConstants.TOP);
1637:                listener1.checkPropertyFired(button, "verticalAlignment",
1638:                        new Integer(SwingConstants.CENTER), new Integer(
1639:                                SwingConstants.TOP));
1640:                listener2.checkPropertyFired(button, "verticalAlignment",
1641:                        new Integer(SwingConstants.CENTER), new Integer(
1642:                                SwingConstants.TOP));
1643:                listener1.reset();
1644:                listener2.reset();
1645:                button.setVerticalAlignment(SwingConstants.BOTTOM);
1646:                listener1.checkPropertyFired(button, "verticalAlignment",
1647:                        new Integer(SwingConstants.TOP), new Integer(
1648:                                SwingConstants.BOTTOM));
1649:                listener2.checkPropertyFired(button, "verticalAlignment",
1650:                        new Integer(SwingConstants.TOP), new Integer(
1651:                                SwingConstants.BOTTOM));
1652:                listener1.reset();
1653:                listener2.reset();
1654:                button.setVerticalAlignment(SwingConstants.BOTTOM);
1655:                assertFalse("event's not been fired ", listener1.isChanged());
1656:                assertFalse("event's not been fired ", listener2.isChanged());
1657:                listener1.reset();
1658:                listener2.reset();
1659:            }
1660:
1661:            public void testGetVerticalTextPosition() {
1662:                int value1 = SwingConstants.LEFT;
1663:                int value2 = SwingConstants.TOP;
1664:                int value3 = SwingConstants.BOTTOM;
1665:                assertEquals("default VerticalTextPosition",
1666:                        SwingConstants.CENTER, button.getVerticalTextPosition());
1667:                boolean thrown = false;
1668:                try {
1669:                    button.setVerticalTextPosition(value1);
1670:                } catch (IllegalArgumentException e) {
1671:                    thrown = true;
1672:                }
1673:                assertTrue("exception is thrown", thrown);
1674:                button.setVerticalTextPosition(value2);
1675:                assertEquals("VerticalTextPosition", value2, button
1676:                        .getVerticalTextPosition());
1677:                button.setVerticalTextPosition(value3);
1678:                assertEquals("VerticalTextPosition", value3, button
1679:                        .getVerticalTextPosition());
1680:            }
1681:
1682:            public void testGetVerticalAlignment() {
1683:                int value1 = SwingConstants.RIGHT;
1684:                int value2 = SwingConstants.TOP;
1685:                int value3 = SwingConstants.BOTTOM;
1686:                assertEquals("default VerticalAlignment",
1687:                        SwingConstants.CENTER, button.getVerticalAlignment());
1688:                boolean thrown = false;
1689:                try {
1690:                    button.setVerticalAlignment(value1);
1691:                } catch (IllegalArgumentException e) {
1692:                    thrown = true;
1693:                }
1694:                assertTrue("exception is thrown", thrown);
1695:                button.setVerticalAlignment(value2);
1696:                assertEquals("VerticalAlignment", value2, button
1697:                        .getVerticalAlignment());
1698:                button.setVerticalAlignment(value3);
1699:                assertEquals("VerticalAlignment", value3, button
1700:                        .getVerticalAlignment());
1701:            }
1702:
1703:            public void testSetHorizontalAlignment() {
1704:                button.setHorizontalAlignment(SwingConstants.CENTER);
1705:                PropertyChangeController listener1 = new PropertyChangeController();
1706:                PropertyChangeController listener2 = new PropertyChangeController();
1707:                button.addPropertyChangeListener(listener1);
1708:                button.addPropertyChangeListener(listener2);
1709:                button.setHorizontalAlignment(SwingConstants.LEFT);
1710:                listener1.checkLastPropertyFired(button, "horizontalAlignment",
1711:                        new Integer(SwingConstants.CENTER), new Integer(
1712:                                SwingConstants.LEFT));
1713:                listener2.checkLastPropertyFired(button, "horizontalAlignment",
1714:                        new Integer(SwingConstants.CENTER), new Integer(
1715:                                SwingConstants.LEFT));
1716:                listener1.reset();
1717:                listener2.reset();
1718:                button.setHorizontalAlignment(SwingConstants.RIGHT);
1719:                listener1.checkLastPropertyFired(button, "horizontalAlignment",
1720:                        new Integer(SwingConstants.LEFT), new Integer(
1721:                                SwingConstants.RIGHT));
1722:                listener2.checkLastPropertyFired(button, "horizontalAlignment",
1723:                        new Integer(SwingConstants.LEFT), new Integer(
1724:                                SwingConstants.RIGHT));
1725:                listener1.reset();
1726:                listener2.reset();
1727:                button.setHorizontalAlignment(SwingConstants.RIGHT);
1728:                assertFalse("event's not been fired ", listener1.isChanged());
1729:                assertFalse("event's not been fired ", listener2.isChanged());
1730:                listener1.reset();
1731:                listener2.reset();
1732:            }
1733:
1734:            public void testSetHorizontalTextPosition() {
1735:                PropertyChangeController listener1 = new PropertyChangeController();
1736:                PropertyChangeController listener2 = new PropertyChangeController();
1737:                button.addPropertyChangeListener(listener1);
1738:                button.addPropertyChangeListener(listener2);
1739:                button.setHorizontalTextPosition(SwingConstants.LEFT);
1740:                listener1.checkLastPropertyFired(button,
1741:                        "horizontalTextPosition", new Integer(
1742:                                SwingConstants.TRAILING), new Integer(
1743:                                SwingConstants.LEFT));
1744:                listener2.checkLastPropertyFired(button,
1745:                        "horizontalTextPosition", new Integer(
1746:                                SwingConstants.TRAILING), new Integer(
1747:                                SwingConstants.LEFT));
1748:                listener1.reset();
1749:                listener2.reset();
1750:                button.setHorizontalTextPosition(SwingConstants.RIGHT);
1751:                listener1.checkLastPropertyFired(button,
1752:                        "horizontalTextPosition", new Integer(
1753:                                SwingConstants.LEFT), new Integer(
1754:                                SwingConstants.RIGHT));
1755:                listener2.checkLastPropertyFired(button,
1756:                        "horizontalTextPosition", new Integer(
1757:                                SwingConstants.LEFT), new Integer(
1758:                                SwingConstants.RIGHT));
1759:                listener1.reset();
1760:                listener2.reset();
1761:                button.setHorizontalTextPosition(SwingConstants.RIGHT);
1762:                assertFalse("event's not been fired ", listener1.isChanged());
1763:                assertFalse("event's not been fired ", listener2.isChanged());
1764:                listener1.reset();
1765:                listener2.reset();
1766:            }
1767:
1768:            public void testGetHorizontalTextPosition() {
1769:                int value1 = SwingConstants.WEST;
1770:                int value2 = SwingConstants.LEFT;
1771:                int value3 = SwingConstants.TRAILING;
1772:                assertEquals("default HorizontalTextPosition",
1773:                        SwingConstants.TRAILING, button
1774:                                .getHorizontalTextPosition());
1775:                boolean thrown = false;
1776:                try {
1777:                    button.setHorizontalTextPosition(value1);
1778:                } catch (IllegalArgumentException e) {
1779:                    thrown = true;
1780:                }
1781:                assertTrue("exception is thrown", thrown);
1782:                button.setHorizontalTextPosition(value2);
1783:                assertEquals("HorizontalTextPosition", value2, button
1784:                        .getHorizontalTextPosition());
1785:                button.setHorizontalTextPosition(value3);
1786:                assertEquals("HorizontalTextPosition", value3, button
1787:                        .getHorizontalTextPosition());
1788:            }
1789:
1790:            public void testGetHorizontalAlignment() {
1791:                int value1 = SwingConstants.WEST;
1792:                int value2 = SwingConstants.RIGHT;
1793:                int value3 = SwingConstants.LEFT;
1794:                assertEquals("default HorizontalAlignment",
1795:                        SwingConstants.CENTER, button.getHorizontalAlignment());
1796:                boolean thrown = false;
1797:                try {
1798:                    button.setHorizontalAlignment(value1);
1799:                } catch (IllegalArgumentException e) {
1800:                    thrown = true;
1801:                }
1802:                assertTrue("exception is thrown", thrown);
1803:                button.setHorizontalAlignment(value2);
1804:                assertEquals("HorizontalAlignment", value2, button
1805:                        .getHorizontalAlignment());
1806:                button.setHorizontalAlignment(value3);
1807:                assertEquals("HorizontalAlignment", value3, button
1808:                        .getHorizontalAlignment());
1809:            }
1810:
1811:            protected void checkFiringEvents() {
1812:                ConcreteActionListener listener1 = new ConcreteActionListener(
1813:                        true);
1814:                ConcreteChangeListener listener2 = new ConcreteChangeListener(
1815:                        true);
1816:                ConcreteItemListener listener3 = new ConcreteItemListener(true);
1817:                PropertyChangeListener listener4 = new PropertyChangeController(
1818:                        true);
1819:                button.addActionListener(listener1);
1820:                button.addItemListener(listener3);
1821:                button.addChangeListener(listener2);
1822:                button.addPropertyChangeListener(listener4);
1823:            }
1824:
1825:            public void testSetMargin() {
1826:                Insets defaultMargin = new Insets(2, 14, 2, 14);
1827:                button.setMargin(defaultMargin);
1828:                Insets margin1 = new Insets(1, 1, 1, 1);
1829:                Insets margin2 = new Insets(2, 2, 2, 2);
1830:                PropertyChangeController listener1 = new PropertyChangeController();
1831:                PropertyChangeController listener2 = new PropertyChangeController();
1832:                button.addPropertyChangeListener(listener1);
1833:                button.addPropertyChangeListener(listener2);
1834:                button.setMargin(margin1);
1835:                listener1.checkPropertyFired(button, "margin", defaultMargin,
1836:                        margin1);
1837:                listener2.checkPropertyFired(button, "margin", defaultMargin,
1838:                        margin1);
1839:                listener1.reset();
1840:                listener2.reset();
1841:                button.setMargin(margin2);
1842:                listener1
1843:                        .checkPropertyFired(button, "margin", margin1, margin2);
1844:                listener2
1845:                        .checkPropertyFired(button, "margin", margin1, margin2);
1846:                listener1.reset();
1847:                listener2.reset();
1848:                button.setMargin(margin2);
1849:                assertFalse("event's not been fired ", listener1.isChanged());
1850:                assertFalse("event's not been fired ", listener2.isChanged());
1851:                listener1.reset();
1852:                listener2.reset();
1853:            }
1854:
1855:            public void testGetMargin() {
1856:                Insets margin1 = new Insets(1, 1, 1, 1);
1857:                Insets margin2 = new Insets(2, 2, 2, 2);
1858:                Insets margin3 = new Insets(3, 3, 3, 3);
1859:                button.setMargin(margin1);
1860:                assertEquals("Margin", margin1, button.getMargin());
1861:                button.setMargin(margin2);
1862:                assertEquals("Margin", margin2, button.getMargin());
1863:                button.setMargin(margin3);
1864:                assertEquals("Margin", margin3, button.getMargin());
1865:            }
1866:
1867:            public void testSetSelected() {
1868:                ConcreteItemListener listener1 = new ConcreteItemListener();
1869:                ConcreteItemListener listener2 = new ConcreteItemListener();
1870:                ConcreteChangeListener listener3 = new ConcreteChangeListener();
1871:                button.addItemListener(listener1);
1872:                button.addItemListener(listener2);
1873:                button.addChangeListener(listener3);
1874:                button.setSelected(true);
1875:                assertTrue("event's been fired ",
1876:                        listener1.eventHappened != null);
1877:                assertEquals("event's source ", button, listener1.eventHappened
1878:                        .getSource());
1879:                assertEquals("event's ID ", ItemEvent.ITEM_STATE_CHANGED,
1880:                        listener1.eventHappened.getID());
1881:                assertEquals("event's item ", button, listener1.eventHappened
1882:                        .getItem());
1883:                assertEquals("event's StateChange ", 1, listener1.eventHappened
1884:                        .getStateChange());
1885:                assertTrue("event's been fired ",
1886:                        listener2.eventHappened != null);
1887:                assertEquals("event's source ", button, listener2.eventHappened
1888:                        .getSource());
1889:                assertEquals("event's ID ", ItemEvent.ITEM_STATE_CHANGED,
1890:                        listener2.eventHappened.getID());
1891:                assertEquals("event's item ", button, listener2.eventHappened
1892:                        .getItem());
1893:                assertEquals("event's StateChange ", 1, listener2.eventHappened
1894:                        .getStateChange());
1895:                assertTrue("state event's been fired ",
1896:                        listener3.eventHappened != null);
1897:                assertEquals("state event fired properly ", ChangeEvent.class,
1898:                        listener3.eventHappened.getClass());
1899:                assertEquals("state event fired properly ", button,
1900:                        listener3.eventHappened.getSource());
1901:                listener1.eventHappened = null;
1902:                listener2.eventHappened = null;
1903:                listener3.eventHappened = null;
1904:                button.setSelected(false);
1905:                assertTrue("event's been fired ",
1906:                        listener1.eventHappened != null);
1907:                assertEquals("event's source ", button, listener1.eventHappened
1908:                        .getSource());
1909:                assertEquals("event's ID ", ItemEvent.ITEM_STATE_CHANGED,
1910:                        listener1.eventHappened.getID());
1911:                assertEquals("event's item ", button, listener1.eventHappened
1912:                        .getItem());
1913:                assertEquals("event's StateChange ", 2, listener1.eventHappened
1914:                        .getStateChange());
1915:                assertTrue("event's been fired ",
1916:                        listener2.eventHappened != null);
1917:                assertEquals("event's source ", button, listener2.eventHappened
1918:                        .getSource());
1919:                assertEquals("event's ID ", ItemEvent.ITEM_STATE_CHANGED,
1920:                        listener2.eventHappened.getID());
1921:                assertEquals("event's item ", button, listener2.eventHappened
1922:                        .getItem());
1923:                assertEquals("event's StateChange ", 2, listener2.eventHappened
1924:                        .getStateChange());
1925:                assertTrue("state event's been fired ",
1926:                        listener3.eventHappened != null);
1927:                assertEquals("state event fired properly ", ChangeEvent.class,
1928:                        listener3.eventHappened.getClass());
1929:                assertEquals("state event fired properly ", button,
1930:                        listener3.eventHappened.getSource());
1931:                listener1.eventHappened = null;
1932:                listener2.eventHappened = null;
1933:                listener3.eventHappened = null;
1934:                button.setSelected(false);
1935:                assertNull("event's not been fired ", listener1.eventHappened);
1936:                assertNull("event's not been fired ", listener2.eventHappened);
1937:                assertNull("event's not been fired ", listener3.eventHappened);
1938:                listener1.eventHappened = null;
1939:                listener2.eventHappened = null;
1940:                button.getModel().setSelected(true);
1941:                assertTrue("selected ", button.isSelected());
1942:                assertTrue("event's been fired ",
1943:                        listener1.eventHappened != null);
1944:                assertEquals("event's source ", button, listener1.eventHappened
1945:                        .getSource());
1946:                assertEquals("event's ID ", ItemEvent.ITEM_STATE_CHANGED,
1947:                        listener1.eventHappened.getID());
1948:                assertEquals("event's item ", button, listener1.eventHappened
1949:                        .getItem());
1950:                assertEquals("event's StateChange ", 1, listener1.eventHappened
1951:                        .getStateChange());
1952:                assertTrue("event's been fired ",
1953:                        listener2.eventHappened != null);
1954:                assertEquals("event's source ", button, listener2.eventHappened
1955:                        .getSource());
1956:                assertEquals("event's ID ", ItemEvent.ITEM_STATE_CHANGED,
1957:                        listener2.eventHappened.getID());
1958:                assertEquals("event's item ", button, listener2.eventHappened
1959:                        .getItem());
1960:                assertEquals("event's StateChange ", 1, listener2.eventHappened
1961:                        .getStateChange());
1962:                assertTrue("state event's been fired ",
1963:                        listener3.eventHappened != null);
1964:                assertEquals("state event fired properly ", ChangeEvent.class,
1965:                        listener3.eventHappened.getClass());
1966:                assertEquals("state event fired properly ", button,
1967:                        listener3.eventHappened.getSource());
1968:            }
1969:
1970:            public void testIsSelected() {
1971:                assertFalse("default Selected", button.isSelected());
1972:                button.setSelected(true);
1973:                assertTrue("Selected", button.isSelected());
1974:                button.setSelected(false);
1975:                assertFalse("Selected", button.isSelected());
1976:                button.setSelected(true);
1977:                assertTrue("Selected", button.isSelected());
1978:            }
1979:
1980:            public void testSetRolloverEnabled() {
1981:                PropertyChangeController listener1 = new PropertyChangeController();
1982:                PropertyChangeController listener2 = new PropertyChangeController();
1983:                button.addPropertyChangeListener(listener1);
1984:                button.addPropertyChangeListener(listener2);
1985:                button.setRolloverEnabled(true);
1986:                listener1.checkLastPropertyFired(button, "rolloverEnabled",
1987:                        Boolean.FALSE, Boolean.TRUE);
1988:                listener2.checkLastPropertyFired(button, "rolloverEnabled",
1989:                        Boolean.FALSE, Boolean.TRUE);
1990:                listener1.reset();
1991:                listener2.reset();
1992:                button.setRolloverEnabled(false);
1993:                listener1.checkLastPropertyFired(button, "rolloverEnabled",
1994:                        Boolean.TRUE, Boolean.FALSE);
1995:                listener2.checkLastPropertyFired(button, "rolloverEnabled",
1996:                        Boolean.TRUE, Boolean.FALSE);
1997:                listener1.reset();
1998:                listener2.reset();
1999:                button.setRolloverEnabled(false);
2000:                assertFalse("event's not been fired ", listener1.isChanged());
2001:                assertFalse("event's not been fired ", listener2.isChanged());
2002:                listener1.reset();
2003:                listener2.reset();
2004:            }
2005:
2006:            public void testIsRolloverEnabled() {
2007:                assertFalse("default RolloverEnabled", button
2008:                        .isRolloverEnabled());
2009:                button.setRolloverEnabled(true);
2010:                assertTrue("RolloverEnabled", button.isRolloverEnabled());
2011:                button.setRolloverEnabled(false);
2012:                assertFalse("RolloverEnabled", button.isRolloverEnabled());
2013:                button.setRolloverEnabled(true);
2014:                assertTrue("RolloverEnabled", button.isRolloverEnabled());
2015:            }
2016:
2017:            public void testSetFocusPainted() {
2018:                button.setFocusPainted(true);
2019:                PropertyChangeController listener1 = new PropertyChangeController();
2020:                PropertyChangeController listener2 = new PropertyChangeController();
2021:                button.addPropertyChangeListener(listener1);
2022:                button.addPropertyChangeListener(listener2);
2023:                button.setFocusPainted(false);
2024:                listener1.checkLastPropertyFired(button, "focusPainted",
2025:                        Boolean.TRUE, Boolean.FALSE);
2026:                listener2.checkLastPropertyFired(button, "focusPainted",
2027:                        Boolean.TRUE, Boolean.FALSE);
2028:                listener1.reset();
2029:                listener2.reset();
2030:                button.setFocusPainted(true);
2031:                listener1.checkLastPropertyFired(button, "focusPainted",
2032:                        Boolean.FALSE, Boolean.TRUE);
2033:                listener2.checkLastPropertyFired(button, "focusPainted",
2034:                        Boolean.FALSE, Boolean.TRUE);
2035:                listener1.reset();
2036:                listener2.reset();
2037:                button.setFocusPainted(true);
2038:                assertFalse("event's not been fired ", listener1.isChanged());
2039:                assertFalse("event's not been fired ", listener2.isChanged());
2040:                listener1.reset();
2041:                listener2.reset();
2042:            }
2043:
2044:            public void testIsFocusPainted() {
2045:                assertTrue("default FocusPainted", button.isFocusPainted());
2046:                button.setFocusPainted(false);
2047:                assertFalse("FocusPainted", button.isFocusPainted());
2048:                button.setFocusPainted(true);
2049:                assertTrue("FocusPainted", button.isFocusPainted());
2050:                button.setFocusPainted(false);
2051:                assertFalse("FocusPainted", button.isFocusPainted());
2052:            }
2053:
2054:            public void testSetContentAreaFilled() {
2055:                PropertyChangeController listener1 = new PropertyChangeController();
2056:                PropertyChangeController listener2 = new PropertyChangeController();
2057:                button.addPropertyChangeListener(listener1);
2058:                button.addPropertyChangeListener(listener2);
2059:                button.setContentAreaFilled(false);
2060:                listener1.checkLastPropertyFired(button, "contentAreaFilled",
2061:                        Boolean.TRUE, Boolean.FALSE);
2062:                listener2.checkLastPropertyFired(button, "contentAreaFilled",
2063:                        Boolean.TRUE, Boolean.FALSE);
2064:                listener1.reset();
2065:                listener2.reset();
2066:                button.setContentAreaFilled(true);
2067:                listener1.checkLastPropertyFired(button, "contentAreaFilled",
2068:                        Boolean.FALSE, Boolean.TRUE);
2069:                listener2.checkLastPropertyFired(button, "contentAreaFilled",
2070:                        Boolean.FALSE, Boolean.TRUE);
2071:                listener1.reset();
2072:                listener2.reset();
2073:                button.setContentAreaFilled(true);
2074:                assertFalse("event's not been fired ", listener1.isChanged());
2075:                assertFalse("event's not been fired ", listener2.isChanged());
2076:                listener1.reset();
2077:                listener2.reset();
2078:            }
2079:
2080:            public void testIsContentAreaFilled() {
2081:                assertTrue("default ContentAreaFilled", button
2082:                        .isContentAreaFilled());
2083:                button.setContentAreaFilled(false);
2084:                assertFalse("ContentAreaFilled", button.isContentAreaFilled());
2085:                button.setContentAreaFilled(true);
2086:                assertTrue("ContentAreaFilled", button.isContentAreaFilled());
2087:                button.setContentAreaFilled(false);
2088:                assertFalse("ContentAreaFilled", button.isContentAreaFilled());
2089:            }
2090:
2091:            public void testSetBorderPainted() {
2092:                PropertyChangeController listener1 = new PropertyChangeController();
2093:                PropertyChangeController listener2 = new PropertyChangeController();
2094:                button.addPropertyChangeListener(listener1);
2095:                button.addPropertyChangeListener(listener2);
2096:                button.setBorderPainted(false);
2097:                listener1.checkLastPropertyFired(button, "borderPainted",
2098:                        Boolean.TRUE, Boolean.FALSE);
2099:                listener1.checkLastPropertyFired(button, "borderPainted",
2100:                        Boolean.TRUE, Boolean.FALSE);
2101:                listener1.reset();
2102:                listener2.reset();
2103:                button.setBorderPainted(true);
2104:                listener1.checkLastPropertyFired(button, "borderPainted",
2105:                        Boolean.FALSE, Boolean.TRUE);
2106:                listener1.checkLastPropertyFired(button, "borderPainted",
2107:                        Boolean.FALSE, Boolean.TRUE);
2108:                listener1.reset();
2109:                listener2.reset();
2110:                button.setBorderPainted(true);
2111:                assertFalse("event's not been fired ", listener1.isChanged());
2112:                assertFalse("event's not been fired ", listener2.isChanged());
2113:                listener1.reset();
2114:                listener2.reset();
2115:            }
2116:
2117:            public void testIsBorderPainted() {
2118:                assertTrue("default BorderPainted", button.isBorderPainted());
2119:                button.setBorderPainted(false);
2120:                assertFalse("BorderPainted", button.isBorderPainted());
2121:                button.setBorderPainted(true);
2122:                assertTrue("BorderPainted", button.isBorderPainted());
2123:                button.setBorderPainted(false);
2124:                assertFalse("BorderPainted", button.isBorderPainted());
2125:            }
2126:
2127:            /*
2128:             * is being tested by testGetMultiClickThreshhold()
2129:             */
2130:            public void testSetMultiClickThreshhold() {
2131:            }
2132:
2133:            public void testGetMultiClickThreshhold() {
2134:                long value1 = 100l;
2135:                long value2 = 200l;
2136:                assertEquals("default MultiClickThreshhold", 0, button
2137:                        .getMultiClickThreshhold());
2138:                button.setMultiClickThreshhold(value1);
2139:                assertEquals("MultiClickThreshhold", value1, button
2140:                        .getMultiClickThreshhold());
2141:                button.setMultiClickThreshhold(value2);
2142:                assertEquals("MultiClickThreshhold", value2, button
2143:                        .getMultiClickThreshhold());
2144:                button.setMultiClickThreshhold(value2);
2145:                assertEquals("MultiClickThreshhold", value2, button
2146:                        .getMultiClickThreshhold());
2147:            }
2148:
2149:            public void testSetMnemonicint2() {
2150:                PropertyChangeController listener1 = new PropertyChangeController();
2151:                PropertyChangeController listener2 = new PropertyChangeController();
2152:                ConcreteChangeListener listener3 = new ConcreteChangeListener();
2153:                button.addPropertyChangeListener(listener1);
2154:                button.addPropertyChangeListener(listener2);
2155:                button.addChangeListener(listener3);
2156:                button.getModel().setMnemonic(KeyEvent.VK_C);
2157:                listener1.checkLastPropertyFired(button, "mnemonic",
2158:                        new Integer(0), new Integer(KeyEvent.VK_C));
2159:                listener2.checkLastPropertyFired(button, "mnemonic",
2160:                        new Integer(0), new Integer(KeyEvent.VK_C));
2161:                assertTrue("state event's been fired ",
2162:                        listener3.eventHappened != null);
2163:                assertEquals("state event fired properly ", ChangeEvent.class,
2164:                        listener3.eventHappened.getClass());
2165:                assertEquals("state event fired properly ", button,
2166:                        listener3.eventHappened.getSource());
2167:                listener1.reset();
2168:                listener2.reset();
2169:                listener3.eventHappened = null;
2170:            }
2171:
2172:            public void testSetMnemonicint1() {
2173:                PropertyChangeController listener1 = new PropertyChangeController();
2174:                PropertyChangeController listener2 = new PropertyChangeController();
2175:                ConcreteChangeListener listener3 = new ConcreteChangeListener();
2176:                button.addPropertyChangeListener(listener1);
2177:                button.addPropertyChangeListener(listener2);
2178:                button.addChangeListener(listener3);
2179:                button.setMnemonic(KeyEvent.VK_C);
2180:                listener1.checkLastPropertyFired(button, "mnemonic",
2181:                        new Integer(0), new Integer(KeyEvent.VK_C));
2182:                listener2.checkLastPropertyFired(button, "mnemonic",
2183:                        new Integer(0), new Integer(KeyEvent.VK_C));
2184:                assertTrue("state event's been fired ",
2185:                        listener3.eventHappened != null);
2186:                assertEquals("state event fired properly ", ChangeEvent.class,
2187:                        listener3.eventHappened.getClass());
2188:                assertEquals("state event fired properly ", button,
2189:                        listener3.eventHappened.getSource());
2190:                listener1.reset();
2191:                listener2.reset();
2192:                listener3.eventHappened = null;
2193:                button.setMnemonic(KeyEvent.VK_D);
2194:                listener1.checkLastPropertyFired(button, "mnemonic",
2195:                        new Integer(KeyEvent.VK_C), new Integer(KeyEvent.VK_D));
2196:                listener2.checkLastPropertyFired(button, "mnemonic",
2197:                        new Integer(KeyEvent.VK_C), new Integer(KeyEvent.VK_D));
2198:                assertTrue("state event's been fired ",
2199:                        listener3.eventHappened != null);
2200:                assertEquals("state event fired properly ", ChangeEvent.class,
2201:                        listener3.eventHappened.getClass());
2202:                assertEquals("state event fired properly ", button,
2203:                        listener3.eventHappened.getSource());
2204:                listener1.reset();
2205:                listener2.reset();
2206:                listener3.eventHappened = null;
2207:                button.setMnemonic(KeyEvent.VK_D);
2208:                assertFalse("event's not been fired ", listener1.isChanged());
2209:                assertFalse("event's not been fired ", listener2.isChanged());
2210:            }
2211:
2212:            public void testSetMnemonicchar() {
2213:                button.setMnemonic('c');
2214:                assertEquals("mnemonic", KeyEvent.VK_C, button.getMnemonic());
2215:                button.setMnemonic('f');
2216:                assertEquals("mnemonic", KeyEvent.VK_F, button.getMnemonic());
2217:                button.setMnemonic('-');
2218:                assertEquals("mnemonic", KeyEvent.VK_MINUS, button
2219:                        .getMnemonic());
2220:                button.setMnemonic('\u00FF');
2221:                assertEquals("mnemonic", 255, button.getMnemonic());
2222:                button.setMnemonic('\u01FF');
2223:                assertEquals("mnemonic", 511, button.getMnemonic());
2224:            }
2225:
2226:            public void testGetMnemonic() {
2227:                assertEquals("default mnemonic", 0, button.getMnemonic());
2228:                button.setMnemonic(KeyEvent.VK_C);
2229:                assertEquals("mnemonic", KeyEvent.VK_C, button.getMnemonic());
2230:                button.setMnemonic(KeyEvent.VK_F);
2231:                assertEquals("mnemonic", KeyEvent.VK_F, button.getMnemonic());
2232:            }
2233:
2234:            public void testSetDisplayedMnemonicIndex() {
2235:                PropertyChangeController listener1 = new PropertyChangeController();
2236:                ConcreteChangeListener listener2 = new ConcreteChangeListener();
2237:                assertEquals("MnemonicIndex", -1, button
2238:                        .getDisplayedMnemonicIndex());
2239:                button.setText("vroooom");
2240:                assertEquals("MnemonicIndex", -1, button
2241:                        .getDisplayedMnemonicIndex());
2242:                button.addPropertyChangeListener(listener1);
2243:                button.addChangeListener(listener2);
2244:                button.setMnemonic(KeyEvent.VK_O);
2245:                listener1.checkPropertyFired(button, "mnemonic",
2246:                        new Integer(0), new Integer(KeyEvent.VK_O));
2247:                listener1.checkPropertyFired(button, "displayedMnemonicIndex",
2248:                        new Integer(-1), new Integer(2));
2249:                assertTrue("state event's been fired ",
2250:                        listener2.eventHappened != null);
2251:                assertEquals("state event fired properly ", ChangeEvent.class,
2252:                        listener2.eventHappened.getClass());
2253:                assertEquals("state event fired properly ", button,
2254:                        listener2.eventHappened.getSource());
2255:                listener1.reset();
2256:                listener2.eventHappened = null;
2257:                button.setDisplayedMnemonicIndex(5);
2258:                listener1.checkPropertyFired(button, "displayedMnemonicIndex",
2259:                        new Integer(2), new Integer(5));
2260:                assertNull("state event's not been fired ",
2261:                        listener2.eventHappened);
2262:                listener1.reset();
2263:                button.setDisplayedMnemonicIndex(5);
2264:                assertFalse("state event's not been fired ", listener1
2265:                        .isChanged());
2266:                assertNull("state event's not been fired ",
2267:                        listener2.eventHappened);
2268:                boolean thrown = false;
2269:                try {
2270:                    button.setDisplayedMnemonicIndex(7);
2271:                } catch (IllegalArgumentException e) {
2272:                    thrown = true;
2273:                }
2274:                assertTrue("exception's bees thrown", thrown);
2275:            }
2276:
2277:            public void testGetDisplayedMnemonicIndex() {
2278:                assertEquals("MnemonicIndex", -1, button
2279:                        .getDisplayedMnemonicIndex());
2280:                button.setText("vroooom");
2281:                assertEquals("MnemonicIndex", -1, button
2282:                        .getDisplayedMnemonicIndex());
2283:                button.setMnemonic(KeyEvent.VK_O);
2284:                assertEquals("MnemonicIndex", 2, button
2285:                        .getDisplayedMnemonicIndex());
2286:                button.setDisplayedMnemonicIndex(5);
2287:                assertEquals("MnemonicIndex", 5, button
2288:                        .getDisplayedMnemonicIndex());
2289:                button.setDisplayedMnemonicIndex(6);
2290:                assertEquals("MnemonicIndex", 6, button
2291:                        .getDisplayedMnemonicIndex());
2292:                button.setDisplayedMnemonicIndex(-1);
2293:                assertEquals("MnemonicIndex", -1, button
2294:                        .getDisplayedMnemonicIndex());
2295:            }
2296:
2297:            public void testGetAlignmentXY() {
2298:                assertEquals("alignmentX ", button.getAlignmentX(), 0.5f, 1e-5);
2299:                assertEquals("alignmentY ", button.getAlignmentY(), 0.5f, 1e-5);
2300:            }
2301:
2302:            public void testDoClick() {
2303:                TestButtonModel model = new TestButtonModel();
2304:                button.setModel(model);
2305:                ConcreteAction action = new ConcreteAction();
2306:                button.setAction(action);
2307:                String name = "namename";
2308:                button.setText(name);
2309:                ConcreteActionListener listener = new ConcreteActionListener();
2310:                button.addActionListener(listener);
2311:                button.doClick(0);
2312:                assertTrue(model.wasArmed);
2313:                assertTrue(model.wasPressed);
2314:                assertNotNull(listener.eventHappened);
2315:                assertNotNull(action.eventHappened);
2316:                assertEquals(name, listener.eventHappened.getActionCommand());
2317:                if (!isHarmony()) {
2318:                    model.wasArmed = false;
2319:                    model.wasPressed = false;
2320:                    action.eventHappened = null;
2321:                    listener.eventHappened = null;
2322:                    button.doClick(10);
2323:                    assertTrue(model.wasArmed);
2324:                    assertTrue(model.wasPressed);
2325:                    assertNotNull(listener.eventHappened);
2326:                    assertNotNull(action.eventHappened);
2327:                    assertEquals(name, listener.eventHappened
2328:                            .getActionCommand());
2329:                }
2330:            }
2331:
2332:            /**
2333:             * Regression test for H4655: setMargin(null) causes to default margin
2334:             * */
2335:            public void testH4655() {
2336:
2337:                JRadioButton rb = new JRadioButton();
2338:                Insets newInsets = new Insets(10, 10, 10, 10);
2339:                Insets defaultInsets = rb.getMargin();
2340:
2341:                rb.setMargin(null);
2342:                assertEquals(defaultInsets, rb.getMargin());
2343:                rb.setMargin(newInsets);
2344:                assertEquals(newInsets, rb.getMargin());
2345:                rb.setMargin(null);
2346:                assertEquals(defaultInsets, rb.getMargin());
2347:            }
2348:
2349:            protected int find(final Object[] array, final Object value) {
2350:                int found = 0;
2351:                if (array != null) {
2352:                    for (int i = 0; i < array.length; i++) {
2353:                        if (array[i].equals(value)) {
2354:                            found++;
2355:                        }
2356:                    }
2357:                }
2358:                return found;
2359:            }
2360:
2361:            protected ImageIcon createNewIcon() {
2362:                return new ImageIcon(new BufferedImage(20, 20,
2363:                        BufferedImage.TYPE_INT_RGB));
2364:            }
2365:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.