01: package abbot.tester;
02:
03: import java.awt.BorderLayout;
04: import java.awt.Frame;
05: import java.awt.Window;
06: import javax.swing.JButton;
07: import javax.swing.JLabel;
08: import javax.swing.JPanel;
09: import javax.swing.JToolBar;
10: import javax.swing.SwingConstants;
11: import javax.swing.SwingUtilities;
12: import junit.extensions.abbot.*;
13:
14: public class JToolBarTesterTest extends ComponentTestFixture {
15: public static void main(String[] args) {
16: RepeatHelper.runTests(args, JToolBarTesterTest.class);
17: }
18:
19: private JToolBar bar;
20: private JPanel dock;
21: private JLabel contents;
22: private JToolBarTester tester;
23:
24: protected void setUp() {
25: bar = new JToolBar();
26: bar.add(new JButton(getName()));
27: tester = new JToolBarTester();
28: dock = new JPanel(new BorderLayout());
29: dock.add(contents = new JLabel(getName()), BorderLayout.CENTER);
30: dock.add(bar, BorderLayout.NORTH);
31: }
32:
33: public void testActionFloatLocation() {
34: Frame f = showFrame(dock);
35: int x = f.getX() + f.getWidth();
36: int y = f.getY() + f.getHeight();
37: tester.actionFloat(bar, x, y);
38: Window w = SwingUtilities.getWindowAncestor(bar);
39: assertTrue("Not floated", tester.isFloating(bar));
40: assertTrue("Floated in wrong location", w.getBounds().contains(
41: x, y));
42: }
43:
44: public void testActionFloat() {
45: Frame f = showFrame(dock);
46: tester.actionFloat(bar);
47: assertTrue("Bar should be floating", tester.isFloating(bar));
48:
49: tester.actionUnfloat(bar);
50: assertEquals("Bar should not be floating", f, SwingUtilities
51: .getWindowAncestor(bar));
52: }
53:
54: // sporadic linux (1.4.2) failures
55: public void testActionUnfloatLocation() {
56: Frame f = showFrame(dock);
57: int x = f.getX() + f.getWidth();
58: int y = f.getY() + f.getHeight();
59:
60: tester.actionFloat(bar, x, y);
61: tester.actionUnfloat(bar, BorderLayout.SOUTH);
62: assertEquals("Wrong orientation after SOUTH drop",
63: SwingConstants.HORIZONTAL, bar.getOrientation());
64: assertTrue("Not docked SOUTH: bar y=" + bar.getY() + " vs. "
65: + contents.getY(), bar.getY() > contents.getY());
66:
67: tester.actionFloat(bar, x, y);
68: tester.actionUnfloat(bar, BorderLayout.WEST);
69: assertEquals("Wrong orientation after WEST drop",
70: SwingConstants.VERTICAL, bar.getOrientation());
71: assertTrue("Not docked WEST: bar x=" + bar.getX() + " vs. "
72: + contents.getX(), bar.getX() < contents.getX());
73:
74: tester.actionFloat(bar, x, y);
75: tester.actionUnfloat(bar, BorderLayout.NORTH);
76: assertEquals("Wrong orientation after NORTH drop",
77: SwingConstants.HORIZONTAL, bar.getOrientation());
78: assertTrue("Not docked NORTH: bar y=" + bar.getY() + " vs. "
79: + contents.getY(), bar.getY() < contents.getY());
80:
81: tester.actionFloat(bar, x, y);
82: tester.actionUnfloat(bar, BorderLayout.EAST);
83: assertEquals("Wrong orientation after EAST drop",
84: SwingConstants.VERTICAL, bar.getOrientation());
85: assertTrue("Not docked EAST: bar x=" + bar.getX() + " vs. "
86: + contents.getX(), bar.getX() > contents.getX());
87:
88: }
89: }
|