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 04.05.2005
0021:
0022: */package javax.swing;
0023:
0024: import java.awt.Dimension;
0025: import java.awt.Frame;
0026: import java.awt.image.BufferedImage;
0027: import javax.accessibility.AccessibleRole;
0028: import javax.swing.plaf.OptionPaneUI;
0029:
0030: public class JOptionPaneTest extends SwingTestCase {
0031: JOptionPane pane = null;
0032:
0033: /*
0034: * @see TestCase#setUp()
0035: */
0036: @Override
0037: protected void setUp() throws Exception {
0038: super .setUp();
0039: pane = new JOptionPane();
0040: }
0041:
0042: public void testGetAccessibleContext() {
0043: boolean assertedValue = (pane.getAccessibleContext() != null && pane
0044: .getAccessibleContext()
0045: .getClass()
0046: .getName()
0047: .equals("javax.swing.JOptionPane$AccessibleJOptionPane"));
0048: assertTrue("AccessibleContext created properly ", assertedValue);
0049: assertEquals("AccessibleRole", AccessibleRole.OPTION_PANE, pane
0050: .getAccessibleContext().getAccessibleRole());
0051: }
0052:
0053: public void testParamString() {
0054: assertTrue("ParamString returns a string ",
0055: pane.toString() != null);
0056: }
0057:
0058: public void testGetUIClassID() {
0059: assertEquals("UI class ID", "OptionPaneUI", pane.getUIClassID());
0060: }
0061:
0062: public void testUpdateUI() {
0063: OptionPaneUI ui = new OptionPaneUI() {
0064: @Override
0065: public void selectInitialValue(JOptionPane arg0) {
0066: }
0067:
0068: @Override
0069: public boolean containsCustomComponents(JOptionPane arg0) {
0070: return false;
0071: }
0072: };
0073: pane.setUI(ui);
0074: assertEquals(ui, pane.getUI());
0075: pane.updateUI();
0076: assertNotSame(ui, pane.getUI());
0077: }
0078:
0079: /*
0080: * Class under test for void JOptionPane()
0081: */
0082: public void testJOptionPane() {
0083: assertEquals("message", "JOptionPane message", pane
0084: .getMessage());
0085: assertEquals("message type", JOptionPane.PLAIN_MESSAGE, pane
0086: .getMessageType());
0087: assertEquals("option type", JOptionPane.DEFAULT_OPTION, pane
0088: .getOptionType());
0089: assertNull("icon", pane.getIcon());
0090: assertTrue("options", pane.getOptions() == null
0091: || pane.getOptions().length == 0);
0092: assertNull("initial value", pane.getInitialValue());
0093: assertEquals("input value", JOptionPane.UNINITIALIZED_VALUE,
0094: pane.getInputValue());
0095: assertEquals(1, pane.getPropertyChangeListeners().length);
0096: }
0097:
0098: /*
0099: * Class under test for void JOptionPane(Object)
0100: */
0101: public void testJOptionPaneObject() {
0102: String message = "message";
0103: pane = new JOptionPane(message);
0104: assertEquals("message", message, pane.getMessage());
0105: assertEquals("message type", JOptionPane.PLAIN_MESSAGE, pane
0106: .getMessageType());
0107: assertEquals("option type", JOptionPane.DEFAULT_OPTION, pane
0108: .getOptionType());
0109: assertNull("icon", pane.getIcon());
0110: assertTrue("options", pane.getOptions() == null
0111: || pane.getOptions().length == 0);
0112: assertNull("initial value", pane.getInitialValue());
0113: assertEquals("input value", JOptionPane.UNINITIALIZED_VALUE,
0114: pane.getInputValue());
0115: }
0116:
0117: /*
0118: * Class under test for void JOptionPane(Object, int)
0119: */
0120: public void testJOptionPaneObjectint() {
0121: String message = "message";
0122: int messageType1 = JOptionPane.ERROR_MESSAGE;
0123: int messageType2 = -100;
0124: pane = new JOptionPane(message, messageType1);
0125: assertEquals("message", message, pane.getMessage());
0126: assertEquals("message type", messageType1, pane
0127: .getMessageType());
0128: assertEquals("option type", JOptionPane.DEFAULT_OPTION, pane
0129: .getOptionType());
0130: assertNull("icon", pane.getIcon());
0131: assertTrue("options", pane.getOptions() == null
0132: || pane.getOptions().length == 0);
0133: assertNull("initial value", pane.getInitialValue());
0134: assertEquals("input value", JOptionPane.UNINITIALIZED_VALUE,
0135: pane.getInputValue());
0136: boolean thrown = false;
0137: try {
0138: pane = new JOptionPane(message, messageType2);
0139: } catch (RuntimeException e) {
0140: thrown = true;
0141: }
0142: assertTrue("exception thrown", thrown);
0143: }
0144:
0145: /*
0146: * Class under test for void JOptionPane(Object, int, int)
0147: */
0148: public void testJOptionPaneObjectintint() {
0149: String message = "message";
0150: int messageType1 = JOptionPane.ERROR_MESSAGE;
0151: int messageType2 = -100;
0152: int optionType1 = JOptionPane.CANCEL_OPTION;
0153: int optionType2 = -100;
0154: pane = new JOptionPane(message, messageType1, optionType1);
0155: assertEquals("message", message, pane.getMessage());
0156: assertEquals("message type", messageType1, pane
0157: .getMessageType());
0158: assertEquals("option type", optionType1, pane.getOptionType());
0159: assertNull("icon", pane.getIcon());
0160: assertTrue("options", pane.getOptions() == null
0161: || pane.getOptions().length == 0);
0162: assertNull("initial value", pane.getInitialValue());
0163: assertEquals("input value", JOptionPane.UNINITIALIZED_VALUE,
0164: pane.getInputValue());
0165: boolean thrown = false;
0166: try {
0167: pane = new JOptionPane(message, messageType2, optionType1);
0168: } catch (RuntimeException e) {
0169: thrown = true;
0170: }
0171: assertTrue("exception thrown", thrown);
0172: thrown = false;
0173: try {
0174: pane = new JOptionPane(message, messageType1, optionType2);
0175: } catch (RuntimeException e) {
0176: thrown = true;
0177: }
0178: assertTrue("exception thrown", thrown);
0179: }
0180:
0181: /*
0182: * Class under test for void JOptionPane(Object, int, int, Icon)
0183: */
0184: public void testJOptionPaneObjectintintIcon() {
0185: String message = "message";
0186: Icon icon1 = new ImageIcon();
0187: Icon icon2 = null;
0188: int messageType1 = JOptionPane.ERROR_MESSAGE;
0189: int messageType2 = -100;
0190: int optionType1 = JOptionPane.CANCEL_OPTION;
0191: int optionType2 = -100;
0192: pane = new JOptionPane(message, messageType1, optionType1,
0193: icon1);
0194: assertEquals("message", message, pane.getMessage());
0195: assertEquals("message type", messageType1, pane
0196: .getMessageType());
0197: assertEquals("option type", optionType1, pane.getOptionType());
0198: assertEquals("icon", icon1, pane.getIcon());
0199: assertTrue("options", pane.getOptions() == null
0200: || pane.getOptions().length == 0);
0201: assertNull("initial value", pane.getInitialValue());
0202: assertEquals("input value", JOptionPane.UNINITIALIZED_VALUE,
0203: pane.getInputValue());
0204: boolean thrown = false;
0205: try {
0206: pane = new JOptionPane(message, messageType2, optionType1,
0207: icon1);
0208: } catch (RuntimeException e) {
0209: thrown = true;
0210: }
0211: assertTrue("exception's been thrown", thrown);
0212: thrown = false;
0213: try {
0214: pane = new JOptionPane(message, messageType1, optionType2,
0215: icon1);
0216: } catch (RuntimeException e) {
0217: thrown = true;
0218: }
0219: assertTrue("exception's been thrown", thrown);
0220: thrown = false;
0221: try {
0222: pane = new JOptionPane(message, messageType1, optionType1,
0223: icon2);
0224: } catch (RuntimeException e) {
0225: thrown = true;
0226: }
0227: assertFalse("exception's not been thrown", thrown);
0228: }
0229:
0230: /*
0231: * Class under test for void JOptionPane(Object, int, int, Icon, Object[])
0232: */
0233: public void testJOptionPaneObjectintintIconObjectArray() {
0234: String message = "message";
0235: Icon icon1 = new ImageIcon();
0236: Icon icon2 = null;
0237: int messageType1 = JOptionPane.ERROR_MESSAGE;
0238: int messageType2 = -100;
0239: int optionType1 = JOptionPane.CANCEL_OPTION;
0240: int optionType2 = -100;
0241: Object[] options1 = new Object[] { new JPanel(), "message" };
0242: Object[] options2 = new Object[] { new InputMap(),
0243: new ActionMap() };
0244: pane = new JOptionPane(message, messageType1, optionType1,
0245: icon1, options1);
0246: assertEquals("message", message, pane.getMessage());
0247: assertEquals("message type", messageType1, pane
0248: .getMessageType());
0249: assertEquals("option type", optionType1, pane.getOptionType());
0250: assertEquals("icon", icon1, pane.getIcon());
0251: assertEquals("options", options1.length,
0252: pane.getOptions().length);
0253: assertEquals("options", options1[0], pane.getOptions()[0]);
0254: assertEquals("options", options1[1], pane.getOptions()[1]);
0255: assertNull("initial value", pane.getInitialValue());
0256: assertEquals("input value", JOptionPane.UNINITIALIZED_VALUE,
0257: pane.getInputValue());
0258: boolean thrown = false;
0259: try {
0260: pane = new JOptionPane(message, messageType2, optionType1,
0261: icon1, options1);
0262: } catch (RuntimeException e) {
0263: thrown = true;
0264: }
0265: assertTrue("exception's been thrown", thrown);
0266: thrown = false;
0267: try {
0268: pane = new JOptionPane(message, messageType1, optionType2,
0269: icon1, options1);
0270: } catch (RuntimeException e) {
0271: thrown = true;
0272: }
0273: assertTrue("exception's been thrown", thrown);
0274: thrown = false;
0275: try {
0276: pane = new JOptionPane(message, messageType1, optionType1,
0277: icon2, options1);
0278: } catch (RuntimeException e) {
0279: thrown = true;
0280: }
0281: assertFalse("exception's not been thrown", thrown);
0282: thrown = false;
0283: try {
0284: pane = new JOptionPane(message, messageType1, optionType1,
0285: icon1, options2);
0286: } catch (RuntimeException e) {
0287: thrown = true;
0288: }
0289: assertFalse("exception's not been thrown", thrown);
0290: }
0291:
0292: /*
0293: * Class under test for void JOptionPane(Object, int, int, Icon, Object[], Object)
0294: */
0295: public void testJOptionPaneObjectintintIconObjectArrayObject() {
0296: String message = "message";
0297: Icon icon1 = new ImageIcon();
0298: Icon icon2 = null;
0299: int messageType1 = JOptionPane.ERROR_MESSAGE;
0300: int messageType2 = -100;
0301: int optionType1 = JOptionPane.CANCEL_OPTION;
0302: int optionType2 = -100;
0303: Object initialSelection = "asdasd";
0304: Object[] options1 = new Object[] { new JPanel(),
0305: initialSelection };
0306: Object[] options2 = new Object[] { new InputMap(),
0307: initialSelection };
0308: pane = new JOptionPane(message, messageType1, optionType1,
0309: icon1, options1, initialSelection);
0310: assertEquals("message", message, pane.getMessage());
0311: assertEquals("message type", messageType1, pane
0312: .getMessageType());
0313: assertEquals("option type", optionType1, pane.getOptionType());
0314: assertEquals("icon", icon1, pane.getIcon());
0315: assertEquals("options", options1.length,
0316: pane.getOptions().length);
0317: assertEquals("options", options1[0], pane.getOptions()[0]);
0318: assertEquals("options", options1[1], pane.getOptions()[1]);
0319: assertEquals("initial value", initialSelection, pane
0320: .getInitialValue());
0321: assertEquals("input value", JOptionPane.UNINITIALIZED_VALUE,
0322: pane.getInputValue());
0323: boolean thrown = false;
0324: try {
0325: pane = new JOptionPane(message, messageType2, optionType1,
0326: icon1, options1, initialSelection);
0327: } catch (RuntimeException e) {
0328: thrown = true;
0329: }
0330: assertTrue("exception's been thrown", thrown);
0331: thrown = false;
0332: try {
0333: pane = new JOptionPane(message, messageType1, optionType2,
0334: icon1, options1, initialSelection);
0335: } catch (RuntimeException e) {
0336: thrown = true;
0337: }
0338: assertTrue("exception's been thrown", thrown);
0339: thrown = false;
0340: try {
0341: pane = new JOptionPane(message, messageType1, optionType1,
0342: icon2, options1, initialSelection);
0343: } catch (RuntimeException e) {
0344: thrown = true;
0345: }
0346: assertFalse("exception's not been thrown", thrown);
0347: pane = new JOptionPane(message, messageType1, optionType1,
0348: icon1, options2, null);
0349: assertEquals("message", message, pane.getMessage());
0350: assertEquals("message type", messageType1, pane
0351: .getMessageType());
0352: assertEquals("option type", optionType1, pane.getOptionType());
0353: assertEquals("icon", icon1, pane.getIcon());
0354: assertEquals("options", options1.length,
0355: pane.getOptions().length);
0356: assertEquals("options", options2[0], pane.getOptions()[0]);
0357: assertEquals("options", options2[1], pane.getOptions()[1]);
0358: assertNull("initial value", pane.getInitialValue());
0359: pane = new JOptionPane(message, messageType1, optionType1,
0360: icon1, null, initialSelection);
0361: assertEquals("message", message, pane.getMessage());
0362: assertEquals("message type", messageType1, pane
0363: .getMessageType());
0364: assertEquals("option type", optionType1, pane.getOptionType());
0365: assertEquals("icon", icon1, pane.getIcon());
0366: assertEquals("initial value", initialSelection, pane
0367: .getInitialValue());
0368: }
0369:
0370: /*
0371: * Class under test for String showInputDialog(Object)
0372: */
0373: public void testShowInputDialogObject() {
0374: //TODO Implement showInputDialog().
0375: }
0376:
0377: /*
0378: * Class under test for String showInputDialog(Object, Object)
0379: */
0380: public void testShowInputDialogObjectObject() {
0381: //TODO Implement showInputDialog().
0382: }
0383:
0384: /*
0385: * Class under test for String showInputDialog(Component, Object)
0386: */
0387: public void testShowInputDialogComponentObject() {
0388: //TODO Implement showInputDialog().
0389: }
0390:
0391: /*
0392: * Class under test for String showInputDialog(Component, Object, Object)
0393: */
0394: public void testShowInputDialogComponentObjectObject() {
0395: //TODO Implement showInputDialog().
0396: }
0397:
0398: /*
0399: * Class under test for String showInputDialog(Component, Object, String, int)
0400: */
0401: public void testShowInputDialogComponentObjectStringint() {
0402: //TODO Implement showInputDialog().
0403: }
0404:
0405: /*
0406: * Class under test for Object showInputDialog(Component, Object, String, int, Icon, Object[], Object)
0407: */
0408: public void testShowInputDialogComponentObjectStringintIconObjectArrayObject() {
0409: //TODO Implement showInputDialog().
0410: }
0411:
0412: /*
0413: * Class under test for void showMessageDialog(Component, Object)
0414: */
0415: public void testShowMessageDialogComponentObject() {
0416: //TODO Implement showMessageDialog().
0417: }
0418:
0419: /*
0420: * Class under test for void showMessageDialog(Component, Object, String, int)
0421: */
0422: public void testShowMessageDialogComponentObjectStringint() {
0423: //TODO Implement showMessageDialog().
0424: }
0425:
0426: /*
0427: * Class under test for void showMessageDialog(Component, Object, String, int, Icon)
0428: */
0429: public void testShowMessageDialogComponentObjectStringintIcon() {
0430: //TODO Implement showMessageDialog().
0431: }
0432:
0433: /*
0434: * Class under test for int showConfirmDialog(Component, Object)
0435: */
0436: public void testShowConfirmDialogComponentObject() {
0437: //TODO Implement showConfirmDialog().
0438: }
0439:
0440: /*
0441: * Class under test for int showConfirmDialog(Component, Object, String, int)
0442: */
0443: public void testShowConfirmDialogComponentObjectStringint() {
0444: //TODO Implement showConfirmDialog().
0445: }
0446:
0447: /*
0448: * Class under test for int showConfirmDialog(Component, Object, String, int, int)
0449: */
0450: public void testShowConfirmDialogComponentObjectStringintint() {
0451: //TODO Implement showConfirmDialog().
0452: }
0453:
0454: /*
0455: * Class under test for int showConfirmDialog(Component, Object, String, int, int, Icon)
0456: */
0457: public void testShowConfirmDialogComponentObjectStringintintIcon() {
0458: //TODO Implement showConfirmDialog().
0459: }
0460:
0461: public void testShowOptionDialog() {
0462: //TODO Implement showOptionDialog().
0463: }
0464:
0465: public void testCreateInternalFrame() {
0466: JDesktopPane deskTop = new JDesktopPane();
0467: JFrame frame = new JFrame();
0468: JPanel panel = new JPanel();
0469: String title = "title-title";
0470: JInternalFrame iFrame = null;
0471: panel.setPreferredSize(new Dimension(300, 300));
0472: boolean thrown = false;
0473: try {
0474: iFrame = pane.createInternalFrame(panel, title);
0475: } catch (RuntimeException e) {
0476: assertEquals(
0477: "message",
0478: "JOptionPane: parentComponent does not have a valid parent",
0479: e.getMessage());
0480: thrown = true;
0481: }
0482: assertTrue("runtime exception's been thrown", thrown);
0483: frame.getContentPane().add(panel);
0484: iFrame = pane.createInternalFrame(panel, title);
0485: assertEquals("title", title, iFrame.getTitle());
0486: assertEquals("parent", panel.getParent(), iFrame.getParent());
0487: assertEquals("pane", pane, ((JPanel) iFrame.getRootPane()
0488: .getLayeredPane().getComponent(0)).getComponent(0));
0489: deskTop.add(panel);
0490: iFrame = pane.createInternalFrame(panel, title);
0491: assertEquals("title", title, iFrame.getTitle());
0492: assertEquals("parent", deskTop, iFrame.getParent());
0493: assertEquals("pane", pane,
0494: ((JPanel) ((JLayeredPane) ((JRootPane) iFrame
0495: .getComponent(0)).getComponent(1))
0496: .getComponent(0)).getComponent(0));
0497: frame.dispose();
0498: }
0499:
0500: public void testCreateDialog() {
0501: JFrame frame = new JFrame();
0502: JPanel panel = new JPanel();
0503: String title = "title-title";
0504: panel.setPreferredSize(new Dimension(300, 300));
0505: frame.getContentPane().add(panel);
0506: JDialog dialog = pane.createDialog(panel, title);
0507: assertEquals("title", title, dialog.getTitle());
0508: assertFalse("resizable", dialog.isResizable());
0509: assertEquals("pane", pane,
0510: ((JPanel) ((JLayeredPane) ((JRootPane) dialog
0511: .getComponent(0)).getComponent(1))
0512: .getComponent(0)).getComponent(0));
0513: assertTrue(dialog.isModal());
0514: frame.dispose();
0515: }
0516:
0517: /*
0518: * Class under test for void showInternalMessageDialog(Component, Object)
0519: */
0520: public void testShowInternalMessageDialogComponentObject() {
0521: //TODO Implement showInternalMessageDialog().
0522: // JFrame frame = new JFrame();
0523: // JPanel panel = new JPanel();
0524: // panel.setPreferredSize(new Dimension(300, 300));
0525: // frame.getContentPane().add(panel);
0526: // frame.pack();
0527: // frame.setVisible(true);
0528: // JOptionPane.showInternalMessageDialog(frame.getContentPane(), "Bom shankar!");
0529: }
0530:
0531: /*
0532: * Class under test for void showInternalMessageDialog(Component, Object, String, int)
0533: */
0534: public void testShowInternalMessageDialogComponentObjectStringint() {
0535: //TODO Implement showInternalMessageDialog().
0536: }
0537:
0538: /*
0539: * Class under test for void showInternalMessageDialog(Component, Object, String, int, Icon)
0540: */
0541: public void testShowInternalMessageDialogComponentObjectStringintIcon() {
0542: //TODO Implement showInternalMessageDialog().
0543: }
0544:
0545: /*
0546: * Class under test for int showInternalConfirmDialog(Component, Object)
0547: */
0548: public void testShowInternalConfirmDialogComponentObject() {
0549: //TODO Implement showInternalConfirmDialog().
0550: }
0551:
0552: /*
0553: * Class under test for int showInternalConfirmDialog(Component, Object, String, int)
0554: */
0555: public void testShowInternalConfirmDialogComponentObjectStringint() {
0556: //TODO Implement showInternalConfirmDialog().
0557: }
0558:
0559: /*
0560: * Class under test for int showInternalConfirmDialog(Component, Object, String, int, int)
0561: */
0562: public void testShowInternalConfirmDialogComponentObjectStringintint() {
0563: //TODO Implement showInternalConfirmDialog().
0564: }
0565:
0566: /*
0567: * Class under test for int showInternalConfirmDialog(Component, Object, String, int, int, Icon)
0568: */
0569: public void testShowInternalConfirmDialogComponentObjectStringintintIcon() {
0570: //TODO Implement showInternalConfirmDialog().
0571: }
0572:
0573: public void testShowInternalOptionDialog() {
0574: //TODO Implement showInternalOptionDialog().
0575: }
0576:
0577: /*
0578: * Class under test for String showInternalInputDialog(Component, Object)
0579: */
0580: public void testShowInternalInputDialogComponentObject() {
0581: //TODO Implement showInternalInputDialog().
0582: }
0583:
0584: /*
0585: * Class under test for String showInternalInputDialog(Component, Object, String, int)
0586: */
0587: public void testShowInternalInputDialogComponentObjectStringint() {
0588: //TODO Implement showInternalInputDialog().
0589: }
0590:
0591: /*
0592: * Class under test for Object showInternalInputDialog(Component, Object, String, int, Icon, Object[], Object)
0593: */
0594: public void testShowInternalInputDialogComponentObjectStringintIconObjectArrayObject() {
0595: //TODO Implement showInternalInputDialog().
0596: }
0597:
0598: public void testGetFrameForComponent() {
0599: Frame defaultFrame = JOptionPane.getRootFrame();
0600: JPanel panel = new JPanel();
0601: JFrame frame = new JFrame();
0602: JFrame rootFrame = new JFrame();
0603: assertEquals("frame", defaultFrame, JOptionPane
0604: .getFrameForComponent(null));
0605: assertEquals("frame", defaultFrame, JOptionPane
0606: .getFrameForComponent(panel));
0607: frame.getContentPane().add(panel);
0608: assertEquals("frame", frame, JOptionPane
0609: .getFrameForComponent(panel));
0610: assertEquals("frame", frame, JOptionPane
0611: .getFrameForComponent(frame));
0612: JOptionPane.setRootFrame(rootFrame);
0613: assertEquals("frame", rootFrame, JOptionPane
0614: .getFrameForComponent(null));
0615: assertEquals("frame", frame, JOptionPane
0616: .getFrameForComponent(panel));
0617: frame.dispose();
0618: rootFrame.dispose();
0619: }
0620:
0621: public void testGetDesktopPaneForComponent() {
0622: JPanel panel = new JPanel();
0623: JDesktopPane frame = new JDesktopPane();
0624: assertNull("frame", JOptionPane
0625: .getDesktopPaneForComponent(null));
0626: assertNull("frame", JOptionPane
0627: .getDesktopPaneForComponent(panel));
0628: frame.add(panel);
0629: assertEquals("frame", frame, JOptionPane
0630: .getDesktopPaneForComponent(panel));
0631: }
0632:
0633: public void testSetRootFrame() {
0634: Frame frame1 = new Frame();
0635: Frame frame2 = new JFrame();
0636: JOptionPane.setRootFrame(frame1);
0637: assertEquals("root frame ", frame1, JOptionPane.getRootFrame());
0638: JOptionPane.setRootFrame(frame2);
0639: assertEquals("root frame ", frame2, JOptionPane.getRootFrame());
0640: JOptionPane.setRootFrame(null);
0641: frame1.dispose();
0642: frame2.dispose();
0643: }
0644:
0645: public void testGetRootFrame() {
0646: Frame frame1 = JOptionPane.getRootFrame();
0647: frame1.add(new JPanel());
0648: frame1.add(new JPanel());
0649: frame1.add(new JPanel());
0650: Frame frame2 = JOptionPane.getRootFrame();
0651: assertNotNull("root frame is not null", frame1);
0652: assertTrue("root frame is shared", frame1 == frame2);
0653: }
0654:
0655: /**
0656: * is beinng tested in BasicOptionPaneUITest
0657: */
0658: public void testSetUIOptionPaneUI() {
0659: }
0660:
0661: public void testGetUI() {
0662: assertTrue("ui is returned ", pane.getUI() != null);
0663: }
0664:
0665: public void testSetMessage() {
0666: PropertyChangeController listener1 = new PropertyChangeController();
0667: String message1 = "message1";
0668: String message2 = "message2";
0669: pane.addPropertyChangeListener(listener1);
0670: pane.setMessage(message1);
0671: listener1.checkPropertyFired(pane, "message",
0672: "JOptionPane message", message1);
0673: assertEquals("message", message1, pane.getMessage());
0674: listener1.reset();
0675: pane.setMessage(message2);
0676: listener1.checkPropertyFired(pane, "message", message1,
0677: message2);
0678: assertEquals("message", message2, pane.getMessage());
0679: listener1.reset();
0680: pane.setMessage(message2);
0681: assertFalse("event's not been fired ", listener1.isChanged());
0682: listener1.reset();
0683: }
0684:
0685: public void testGetMessage() {
0686: assertEquals("message", "JOptionPane message", pane
0687: .getMessage());
0688: }
0689:
0690: public void testSetIcon() {
0691: Icon icon1 = new ImageIcon(new BufferedImage(20, 20,
0692: BufferedImage.TYPE_BYTE_GRAY));
0693: Icon icon2 = new ImageIcon(new BufferedImage(20, 20,
0694: BufferedImage.TYPE_BYTE_GRAY));
0695: PropertyChangeController listener1 = new PropertyChangeController();
0696: pane.addPropertyChangeListener(listener1);
0697: pane.setIcon(icon1);
0698: listener1.checkPropertyFired(pane, "icon", null, icon1);
0699: assertEquals("icon", icon1, pane.getIcon());
0700: listener1.reset();
0701: pane.setIcon(icon2);
0702: listener1.checkPropertyFired(pane, "icon", icon1, icon2);
0703: assertEquals("icon", icon2, pane.getIcon());
0704: listener1.reset();
0705: pane.setIcon(icon2);
0706: assertFalse("event's not been fired ", listener1.isChanged());
0707: listener1.reset();
0708: pane.setIcon(null);
0709: listener1.checkPropertyFired(pane, "icon", icon2, null);
0710: assertNull("icon", pane.getIcon());
0711: listener1.reset();
0712: }
0713:
0714: public void testGetIcon() {
0715: assertNull("icon", pane.getIcon());
0716: }
0717:
0718: public void testSetValue() {
0719: JButton button1 = new JButton("1");
0720: JButton button2 = new JButton("2");
0721: PropertyChangeController listener1 = new PropertyChangeController();
0722: pane.addPropertyChangeListener(listener1);
0723: pane.setValue(button1);
0724: listener1.checkPropertyFired(pane, "value",
0725: JOptionPane.UNINITIALIZED_VALUE, button1);
0726: assertEquals("value", button1, pane.getValue());
0727: listener1.reset();
0728: pane.setValue(button2);
0729: listener1.checkPropertyFired(pane, "value", button1, button2);
0730: assertEquals("value", button2, pane.getValue());
0731: }
0732:
0733: public void testGetValue() {
0734: assertEquals("value", JOptionPane.UNINITIALIZED_VALUE, pane
0735: .getValue());
0736: }
0737:
0738: public void testSetOptions() {
0739: Object options2[] = new Object[] { new JButton("1"),
0740: new ImageIcon(), "asdasd" };
0741: Object options22[] = options2.clone();
0742: Object options3[] = new Object[] { "asd", new InputMap(),
0743: new JPanel() };
0744: Object options32[] = options3.clone();
0745: PropertyChangeController listener1 = new PropertyChangeController();
0746: pane.addPropertyChangeListener(listener1);
0747: pane.setOptions(options2);
0748: listener1.checkPropertyFired(pane, "options", null, options2);
0749: assertTrue("unique", options2 != pane.getOptions());
0750: assertEquals("options", options22.length,
0751: pane.getOptions().length);
0752: assertEquals("options", options22[0], pane.getOptions()[0]);
0753: assertEquals("options", options22[1], pane.getOptions()[1]);
0754: assertEquals("options", options22[2], pane.getOptions()[2]);
0755: pane.setOptions(options3);
0756: listener1.checkPropertyFired(pane, "options", options2,
0757: options3);
0758: assertEquals("options", options32.length,
0759: pane.getOptions().length);
0760: assertEquals("options", options32[0], pane.getOptions()[0]);
0761: assertEquals("options", options32[1], pane.getOptions()[1]);
0762: assertEquals("options", options32[2], pane.getOptions()[2]);
0763: listener1.reset();
0764: pane.setOptions(options3);
0765: assertFalse("event's not been fired ", listener1.isChanged());
0766: }
0767:
0768: public void testGetOptions() {
0769: assertTrue("options", pane.getOptions() == null
0770: || pane.getOptions().length == 0);
0771:
0772: assertNull(new JOptionPane().getOptions());
0773: }
0774:
0775: public void testSetInitialValue() {
0776: JButton button1 = new JButton("1");
0777: JButton button2 = new JButton("2");
0778: pane.setWantsInput(false);
0779: PropertyChangeController listener1 = new PropertyChangeController();
0780: pane.addPropertyChangeListener(listener1);
0781: pane.setInitialValue(button1);
0782: listener1.checkPropertyFired(pane, "initialValue", null,
0783: button1);
0784: assertEquals("InitialValue", button1, pane.getInitialValue());
0785: pane.setWantsInput(true);
0786: listener1.reset();
0787: pane.setInitialValue(button2);
0788: listener1.checkPropertyFired(pane, "initialValue", button1,
0789: button2);
0790: assertEquals("InitialValue", button2, pane.getInitialValue());
0791: }
0792:
0793: public void testGetInitialValue() {
0794: assertNull("InitialValue", pane.getInitialValue());
0795: }
0796:
0797: public void testSetMessageType() {
0798: PropertyChangeController listener1 = new PropertyChangeController();
0799: pane.addPropertyChangeListener(listener1);
0800: pane.setMessageType(JOptionPane.ERROR_MESSAGE);
0801: listener1.checkPropertyFired(pane, "messageType", new Integer(
0802: JOptionPane.PLAIN_MESSAGE), new Integer(
0803: JOptionPane.ERROR_MESSAGE));
0804: assertEquals("message type", JOptionPane.ERROR_MESSAGE, pane
0805: .getMessageType());
0806: listener1.reset();
0807: pane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
0808: listener1.checkPropertyFired(pane, "messageType", new Integer(
0809: JOptionPane.ERROR_MESSAGE), new Integer(
0810: JOptionPane.INFORMATION_MESSAGE));
0811: assertEquals("message type", JOptionPane.INFORMATION_MESSAGE,
0812: pane.getMessageType());
0813: listener1.reset();
0814: boolean thrown = false;
0815: try {
0816: pane.setMessageType(100);
0817: } catch (RuntimeException e) {
0818: thrown = true;
0819: }
0820: assertTrue("exception is thrown", thrown);
0821: pane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
0822: assertFalse("event's not been fired ", listener1.isChanged());
0823: listener1.reset();
0824: }
0825:
0826: public void testGetMessageType() {
0827: assertEquals("message type", JOptionPane.PLAIN_MESSAGE, pane
0828: .getMessageType());
0829: }
0830:
0831: public void testSetOptionType() {
0832: PropertyChangeController listener1 = new PropertyChangeController();
0833: pane.addPropertyChangeListener(listener1);
0834: pane.setOptionType(JOptionPane.CANCEL_OPTION);
0835: listener1.checkPropertyFired(pane, "optionType", new Integer(
0836: JOptionPane.CLOSED_OPTION), new Integer(
0837: JOptionPane.CANCEL_OPTION));
0838: assertEquals("option type", JOptionPane.CANCEL_OPTION, pane
0839: .getOptionType());
0840: listener1.reset();
0841: pane.setOptionType(JOptionPane.OK_OPTION);
0842: listener1.checkPropertyFired(pane, "optionType", new Integer(
0843: JOptionPane.CANCEL_OPTION), new Integer(
0844: JOptionPane.OK_OPTION));
0845: assertEquals("option type", JOptionPane.OK_OPTION, pane
0846: .getOptionType());
0847: listener1.reset();
0848: boolean thrown = false;
0849: try {
0850: pane.setOptionType(100);
0851: } catch (RuntimeException e) {
0852: thrown = true;
0853: }
0854: assertTrue("exception is thrown", thrown);
0855: pane.setOptionType(JOptionPane.OK_OPTION);
0856: assertFalse("event's not been fired ", listener1.isChanged());
0857: listener1.reset();
0858: }
0859:
0860: public void testGetOptionType() {
0861: assertEquals("option type", JOptionPane.CLOSED_OPTION, pane
0862: .getOptionType());
0863: }
0864:
0865: public void testSetSelectionValues() {
0866: Object buttons2[] = new Object[] { new JButton("1"),
0867: new JButton("2") };
0868: Object buttons3[] = new Object[] { new JButton("1"),
0869: new JButton("2") };
0870: PropertyChangeController listener1 = new PropertyChangeController();
0871: pane.addPropertyChangeListener(listener1);
0872: pane.setSelectionValues(buttons2);
0873: listener1.checkPropertyFired(pane, "selectionValues", null,
0874: buttons2);
0875: listener1.checkPropertyFired(pane, "wantsInput", Boolean.FALSE,
0876: Boolean.TRUE);
0877: assertEquals("SelectionValues", buttons2, pane
0878: .getSelectionValues());
0879: assertTrue("SelectionValues", buttons2 == pane
0880: .getSelectionValues());
0881: assertTrue("wantsInput", pane.getWantsInput());
0882: pane.setWantsInput(false);
0883: listener1.reset();
0884: pane.setSelectionValues(buttons3);
0885: listener1.checkPropertyFired(pane, "selectionValues", buttons2,
0886: buttons3);
0887: listener1.checkPropertyFired(pane, "wantsInput", Boolean.FALSE,
0888: Boolean.TRUE);
0889: assertEquals("SelectionValues", buttons3, pane
0890: .getSelectionValues());
0891: assertTrue("SelectionValues", buttons3 == pane
0892: .getSelectionValues());
0893: assertTrue("wantsInput", pane.getWantsInput());
0894: pane.setWantsInput(false);
0895: listener1.reset();
0896: pane.setSelectionValues(buttons3);
0897: listener1.checkLastPropertyFired(pane, "wantsInput",
0898: Boolean.FALSE, Boolean.TRUE);
0899: assertEquals("SelectionValues", buttons3, pane
0900: .getSelectionValues());
0901: assertTrue("SelectionValues", buttons3 == pane
0902: .getSelectionValues());
0903: assertTrue("wantsInput", pane.getWantsInput());
0904: pane = new JOptionPane();
0905: pane.setWantsInput(false);
0906: pane.setSelectionValues(null);
0907: assertFalse(pane.getWantsInput());
0908: }
0909:
0910: public void testGetSelectionValues() {
0911: Object buttons2[] = new Object[] { new JButton("1"),
0912: new JButton("2") };
0913: Object buttons3[] = new Object[] { new JButton("1"),
0914: new JButton("2") };
0915: assertNull("SelectionValues", pane.getSelectionValues());
0916: pane.setSelectionValues(buttons2);
0917: assertEquals("SelectionValues", buttons2, pane
0918: .getSelectionValues());
0919: assertTrue("SelectionValues", buttons2 == pane
0920: .getSelectionValues());
0921: pane.setSelectionValues(buttons3);
0922: assertEquals("SelectionValues", buttons3, pane
0923: .getSelectionValues());
0924: assertTrue("SelectionValues", buttons3 == pane
0925: .getSelectionValues());
0926: }
0927:
0928: public void testSetInitialSelectionValue() {
0929: Object str1 = "String1";
0930: Object str2 = "String2";
0931: pane.setWantsInput(false);
0932: PropertyChangeController listener1 = new PropertyChangeController();
0933: pane.addPropertyChangeListener(listener1);
0934: pane.setInitialSelectionValue(str1);
0935: listener1.checkPropertyFired(pane, "initialSelectionValue",
0936: null, str1);
0937: pane.setWantsInput(true);
0938: listener1.reset();
0939: pane.setInitialSelectionValue(str2);
0940: listener1.checkPropertyFired(pane, "initialSelectionValue",
0941: str1, str2);
0942: }
0943:
0944: public void testGetInitialSelectionValue() {
0945: JButton button1 = new JButton("1");
0946: JButton button2 = new JButton("2");
0947: assertNull("InitialSelectionValue", pane
0948: .getInitialSelectionValue());
0949: pane.setWantsInput(false);
0950: pane.setInitialSelectionValue(button1);
0951: assertEquals("InitialSelectionValue", button1, pane
0952: .getInitialSelectionValue());
0953: pane.setWantsInput(true);
0954: pane.setInitialSelectionValue(button2);
0955: assertEquals("InitialSelectionValue", button2, pane
0956: .getInitialSelectionValue());
0957: }
0958:
0959: public void testSetInputValue() {
0960: PropertyChangeController listener1 = new PropertyChangeController();
0961: JButton button1 = new JButton("1");
0962: JButton button2 = new JButton("2");
0963: pane.addPropertyChangeListener(listener1);
0964: pane.setInputValue(button1);
0965: listener1.checkPropertyFired(pane, "inputValue",
0966: JOptionPane.UNINITIALIZED_VALUE, button1);
0967: assertEquals("input value", button1, pane.getInputValue());
0968: listener1.reset();
0969: pane.setInputValue(button2);
0970: listener1.checkPropertyFired(pane, "inputValue", button1,
0971: button2);
0972: assertEquals("input value", button2, pane.getInputValue());
0973: listener1.reset();
0974: pane.setInputValue(button2);
0975: assertFalse("event's not been fired ", listener1.isChanged());
0976: }
0977:
0978: public void testGetInputValue() {
0979: assertEquals("input value", JOptionPane.UNINITIALIZED_VALUE,
0980: pane.getInputValue());
0981: }
0982:
0983: public void testGetMaxCharactersPerLineCount() {
0984: assertEquals("num characters", Integer.MAX_VALUE, pane
0985: .getMaxCharactersPerLineCount());
0986: }
0987:
0988: public void testSelectInitialValue() {
0989: //TODO Implement selectInitialValue().
0990: }
0991:
0992: public void testSetWantsInput() {
0993: PropertyChangeController listener1 = new PropertyChangeController();
0994: pane.addPropertyChangeListener(listener1);
0995: pane.setWantsInput(true);
0996: listener1.checkPropertyFired(pane, "wantsInput", Boolean.FALSE,
0997: Boolean.TRUE);
0998: assertTrue("wants input", pane.getWantsInput());
0999: listener1.reset();
1000: pane.setWantsInput(false);
1001: listener1.checkPropertyFired(pane, "wantsInput", Boolean.TRUE,
1002: Boolean.FALSE);
1003: assertFalse("wants input", pane.getWantsInput());
1004: listener1.reset();
1005: pane.setWantsInput(false);
1006: assertFalse("event's not been fired ", listener1.isChanged());
1007: listener1.reset();
1008: }
1009:
1010: public void testGetWantsInput() {
1011: assertFalse("wants input", pane.getWantsInput());
1012: }
1013: }
|