01: package abbot.editor;
02:
03: import java.awt.*;
04: import javax.swing.*;
05: import java.util.*;
06:
07: import junit.extensions.abbot.*;
08: import abbot.finder.matchers.*;
09:
10: public class ComponentBrowserTest extends ResolverFixture {
11:
12: private ComponentBrowser browser;
13:
14: protected void setUp() {
15: browser = new ComponentBrowser(getResolver(), getHierarchy());
16: }
17:
18: protected void tearDown() {
19: Container c = browser.getParent();
20: if (c != null)
21: c.remove(browser);
22: browser = null;
23: }
24:
25: public void testPreserveComponentSelection() throws Throwable {
26: JFrame frame = new JFrame(getName());
27: final JLabel label = new JLabel(getName());
28: frame.getContentPane().add(label);
29: showFrame(browser);
30: SwingUtilities.invokeAndWait(new Runnable() {
31: public void run() {
32: browser.setSelectedComponent(label);
33: }
34: });
35: assertEquals("Wrong selected component", label, browser
36: .getSelectedComponent());
37: browser.refresh();
38: assertEquals("Wrong selected component after reload", label,
39: browser.getSelectedComponent());
40: }
41:
42: public void testUncompactOnSelectCompactedComponent()
43: throws Exception {
44: ArrayList data = new ArrayList();
45: for (int i = 0; i < 100; i++) {
46: data.add("Row " + i);
47: }
48: JList list = new JList(data.toArray());
49: JScrollPane sp = new JScrollPane(list);
50: showFrame(sp);
51: JScrollBar sb = (JScrollBar) getFinder().find(
52: new ClassMatcher(JScrollBar.class));
53: browser.setCompactDisplay(true);
54: browser.setSelectedComponent(sb);
55: assertTrue(
56: "Browser should un-compact when selected component is compacted",
57: !browser.isCompactDisplay());
58: }
59:
60: public ComponentBrowserTest(String name) {
61: super (name);
62: }
63:
64: public static void main(String[] args) {
65: TestHelper.runTests(args, ComponentBrowserTest.class);
66: }
67: }
|