01: package org.uispec4j.finder;
02:
03: import org.uispec4j.TestUtils;
04:
05: import javax.swing.*;
06: import java.awt.*;
07:
08: public class CollectionComponentMatchersTest extends
09: PanelComponentFinderTestCase {
10: private Component component1;
11: private Component component2;
12: private Component component3;
13: private Component component4;
14:
15: protected void setUp() throws Exception {
16: super .setUp();
17: component1 = addComponent(JButton.class, "some text");
18: component2 = addComponent(JButton.class, "other text");
19: component3 = addComponent(JButton.class, "nothing");
20: component4 = addComponent(JTextField.class, "last text");
21: }
22:
23: public void testIntersectionMatcher() throws Exception {
24: ComponentMatcher matcher = ComponentMatchers
25: .intersection(new ComponentMatcher[] {
26: ComponentMatchers
27: .displayedNameSubstring("text"),
28: ComponentMatchers.fromClass(JButton.class) });
29:
30: TestUtils.assertSwingComponentsEquals(new Component[] {
31: component1, component2 }, panel
32: .getSwingComponents(matcher));
33: }
34:
35: public void testUnionComponentMatcher() throws Exception {
36: ComponentMatcher matcher = ComponentMatchers
37: .union(new ComponentMatcher[] {
38: ComponentMatchers
39: .displayedNameSubstring("text"),
40: ComponentMatchers.fromClass(JButton.class) });
41:
42: TestUtils.assertSwingComponentsEquals(new Component[] {
43: component1, component2, component3, component4 }, panel
44: .getSwingComponents(matcher));
45: }
46:
47: public void testNegatedComponentMatcher() throws Exception {
48: ComponentMatcher matcher = ComponentMatchers
49: .not(ComponentMatchers.displayedNameSubstring("text"));
50: TestUtils.assertSwingComponentsEquals(
51: new Component[] { component3 }, panel
52: .getSwingComponents(matcher));
53: }
54: }
|