01: package abbot.tester;
02:
03: import java.awt.*;
04: import java.awt.event.*;
05:
06: import javax.swing.JLabel;
07: import javax.swing.JFrame;
08:
09: import junit.extensions.abbot.*;
10:
11: /** Unit test to verify the FrameTester class.<p> */
12:
13: public class FrameTesterTest extends ComponentTestFixture {
14:
15: private FrameTester tester;
16:
17: private static final int DX = 300;
18: private static final int DY = 240;
19:
20: /** Create a new test case with the given name. */
21: public FrameTesterTest(String name) {
22: super (name);
23: }
24:
25: protected void setUp() {
26: tester = new FrameTester();
27: }
28:
29: public void testMoveBy() {
30: Frame frame = showFrame(new JLabel(getName()));
31: Point loc = frame.getLocationOnScreen();
32: loc.x += DX;
33: loc.y += DY;
34: tester.actionMoveBy(frame, DX, DY);
35: assertEquals("Frame not moved to the desired location", loc,
36: frame.getLocationOnScreen());
37:
38: // FIXME +/- coords
39: // FIXME scale 5, 10, 50, 100, 500
40: }
41:
42: public void testNoResize() {
43: Frame frame = showFrame(new JLabel(getName()));
44: frame.setResizable(false);
45: Dimension size = frame.getSize();
46: size.width += DX;
47: size.height += DY;
48: try {
49: tester.actionResizeBy(frame, DX, DY);
50: fail("Resizing of non-resizable frames should not be allowed");
51: } catch (ActionFailedException e) {
52: }
53: }
54:
55: // FIXME intermittent failure on linux 1.4.2_04
56: public void testResizeBy() {
57: Frame frame = showFrame(new JLabel(getName()));
58: Dimension size = frame.getSize();
59: size.width += DX;
60: size.height += DY;
61: tester.actionResizeBy(frame, DX, DY);
62: assertEquals("Frame not resized to the desired size", size,
63: frame.getSize());
64: }
65:
66: private boolean gotClose = false;
67:
68: public void testClose() {
69: JFrame frame = new JFrame(getName());
70: frame.getContentPane().add(new JLabel(getName()));
71: frame.addWindowListener(new WindowAdapter() {
72: public void windowClosing(WindowEvent ev) {
73: gotClose = true;
74: }
75: });
76: showWindow(frame);
77: tester.actionClose(frame);
78: assertTrue("No WINDOW_CLOSING event generated", gotClose);
79: }
80:
81: public static void main(String[] args) {
82: RepeatHelper.runTests(args, FrameTesterTest.class);
83: }
84: }
|