001: package abbot.tester;
002:
003: import java.awt.*;
004:
005: import javax.swing.*;
006: import javax.swing.event.*;
007:
008: import junit.extensions.abbot.*;
009:
010: /** Unit test to verify the JInternalFrameTester class.<p> */
011:
012: public class JInternalFrameTesterTest extends ComponentTestFixture {
013:
014: private JInternalFrameTester tester = new JInternalFrameTester();
015: private JInternalFrame frame;
016:
017: public void testNormalizeIcon() {
018: tester.actionIconify(frame);
019: try {
020: tester.actionNormalize(frame);
021: fail("Normalizing an icon should fail");
022: } catch (ActionFailedException e) {
023: }
024: }
025:
026: public void testDeiconifyFrame() {
027: tester.actionDeiconify(frame);
028: }
029:
030: public void testMaximizeIcon() {
031: Dimension size = frame.getSize();
032: tester.actionIconify(frame);
033: tester.actionMaximize(frame);
034: assertTrue("Frame not maximized", !size.equals(frame.getSize()));
035: }
036:
037: public void testMaximizeNormalize() {
038: Dimension size = frame.getSize();
039: tester.actionMaximize(frame);
040: assertTrue("Frame not maximized", !size.equals(frame.getSize()));
041: tester.actionNormalize(frame);
042: assertEquals("Frame not restored", size, frame.getSize());
043: }
044:
045: public void testIconifyDeiconify() {
046: tester.actionIconify(frame);
047: assertTrue("Frame not iconified", frame.isIcon());
048: tester.actionDeiconify(frame);
049: assertTrue("Frame still iconified", !frame.isIcon());
050: }
051:
052: public void testMove() {
053: Point loc = new Point(100, 100);
054: tester.actionMove(frame, loc.x, loc.y);
055: assertEquals("Frame not moved", loc, frame.getLocation());
056: }
057:
058: public void testResize() {
059: Dimension size = new Dimension(200, 200);
060: tester.actionResize(frame, size.width, size.height);
061: assertEquals("Frame not resized", size, frame.getSize());
062: }
063:
064: private boolean gotClosing = false;
065:
066: public void testClose() {
067: frame.addInternalFrameListener(new InternalFrameAdapter() {
068: public void internalFrameClosing(InternalFrameEvent ev) {
069: gotClosing = true;
070: }
071: });
072: tester.actionClose(frame);
073: assertTrue("No INTERNAL_FRAME_CLOSING event generated",
074: gotClosing);
075: }
076:
077: protected void setUp() throws Exception {
078: JDesktopPane dtpane = new JDesktopPane();
079: frame = new JInternalFrame(getName(), true, true, true, true);
080: frame.getContentPane().add(new JLabel(getName()));
081:
082: dtpane.add(frame);
083: showFrame(dtpane, new Dimension(400, 400));
084: frame.setLocation(10, 10);
085: frame.setSize(300, 300);
086: EventQueue.invokeAndWait(new Runnable() {
087: public void run() {
088: frame.show();
089: }
090: });
091: }
092:
093: /** Create a new test case with the given name. */
094: public JInternalFrameTesterTest(String name) {
095: super (name);
096: }
097:
098: public static void main(String[] args) {
099: RepeatHelper.runTests(args, JInternalFrameTesterTest.class);
100: }
101: }
|