01: package org.uispec4j.finder;
02:
03: import org.uispec4j.Button;
04: import org.uispec4j.TextBox;
05:
06: import javax.swing.JButton;
07: import javax.swing.JTextField;
08: import java.awt.Component;
09:
10: public class PanelContainsComponentTest extends
11: PanelComponentFinderTestCase {
12: private JButton button;
13:
14: private static final ComponentMatcher CUSTOM_MATCHER = new ComponentMatcher() {
15: public boolean matches(Component component) {
16: String name = component.getName();
17: return (name != null) && name.startsWith("custom");
18: }
19: };
20:
21: protected void setUp() throws Exception {
22: super .setUp();
23: button = (JButton) addComponent(JButton.class, "button1");
24: }
25:
26: public void testContainsComponentByClass() throws Exception {
27: assertFalse(panel.containsUIComponent(TextBox.class));
28: assertFalse(panel.containsSwingComponent(JTextField.class));
29:
30: assertTrue(panel.containsUIComponent(Button.class));
31: assertTrue(panel.containsSwingComponent(JButton.class));
32:
33: assertFalse(panel.containsUIComponent(JButton.class));
34: assertFalse(panel.containsSwingComponent(Button.class));
35:
36: addComponent(JButton.class, "button2");
37: assertTrue(panel.containsUIComponent(Button.class));
38: assertTrue(panel.containsSwingComponent(JButton.class));
39: }
40:
41: public void testContainsComponentByName() throws Exception {
42: assertFalse(panel.containsUIComponent(Button.class, "unknown"));
43: assertFalse(panel.containsSwingComponent(JTextField.class,
44: "button"));
45:
46: assertTrue(panel.containsUIComponent(Button.class, "button1"));
47: assertTrue(panel.containsUIComponent(Button.class, "button"));
48: assertTrue(panel.containsSwingComponent(JButton.class,
49: "button1"));
50: assertTrue(panel
51: .containsSwingComponent(JButton.class, "button"));
52:
53: addComponent(JButton.class, "button2");
54: assertTrue(panel.containsUIComponent(Button.class, "button"));
55: assertTrue(panel
56: .containsSwingComponent(JButton.class, "button"));
57: }
58:
59: public void testContainsComponentWithCustomComponentMatcher()
60: throws Exception {
61: assertFalse(panel.containsComponent(CUSTOM_MATCHER));
62:
63: button.setName("custom button");
64: assertTrue(panel.containsComponent(CUSTOM_MATCHER));
65:
66: Component textField = addComponent(JTextField.class, "text");
67: assertTrue(panel.containsComponent(CUSTOM_MATCHER));
68:
69: textField.setName("custom text");
70: assertTrue(panel.containsComponent(CUSTOM_MATCHER));
71: }
72: }
|