01: package org.uispec4j.finder;
02:
03: import org.uispec4j.Panel;
04: import org.uispec4j.utils.UnitTestCase;
05:
06: import javax.swing.JPanel;
07: import java.awt.Component;
08: import java.lang.reflect.Constructor;
09: import java.util.ArrayList;
10: import java.util.List;
11:
12: public abstract class PanelComponentFinderTestCase extends UnitTestCase {
13: protected JPanel jPanel;
14: protected Panel panel;
15: protected List components = new ArrayList();
16:
17: protected void setUp() throws Exception {
18: super .setUp();
19: jPanel = new JPanel();
20: jPanel.setName("myPanel");
21: panel = new Panel(jPanel);
22: }
23:
24: protected Component addComponent(Class awtComponentclass,
25: String name) throws Exception {
26: Component component = createComponent(awtComponentclass, name);
27: components.add(component);
28: jPanel.add(component);
29: return component;
30: }
31:
32: private Component createComponent(Class awtComponentclass,
33: String name) throws Exception {
34: Component component;
35: try {
36: Constructor constructor = awtComponentclass
37: .getConstructor(new Class[] { String.class });
38: component = (Component) constructor
39: .newInstance(new Object[] { name });
40: } catch (NoSuchMethodException e) {
41: component = (Component) awtComponentclass.newInstance();
42: }
43: component.setName(name);
44: return component;
45: }
46: }
|