|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ResolverFixture.java | 66.7% | 93.1% | 100% | 91.3% |
|
1 |
package junit.extensions.abbot;
|
|
2 |
|
|
3 |
import java.awt.Component;
|
|
4 |
import java.awt.Window;
|
|
5 |
import java.util.Iterator;
|
|
6 |
|
|
7 |
import junit.framework.TestCase;
|
|
8 |
import abbot.Log;
|
|
9 |
import abbot.finder.AWTHierarchy;
|
|
10 |
import abbot.finder.BasicFinder;
|
|
11 |
import abbot.finder.ComponentFinder;
|
|
12 |
import abbot.finder.Hierarchy;
|
|
13 |
import abbot.finder.Matcher;
|
|
14 |
import abbot.finder.TestHierarchy;
|
|
15 |
import abbot.script.Resolver;
|
|
16 |
import abbot.script.Script;
|
|
17 |
|
|
18 |
/** Simple wrapper for testing objects which require a Resolver. */
|
|
19 |
|
|
20 |
public class ResolverFixture extends TestCase { |
|
21 |
|
|
22 |
/** Simple matcher that may be used to verify that a specific component is
|
|
23 |
found by a given ComponentFinder.
|
|
24 |
*/
|
|
25 |
protected class ComponentMatcher implements Matcher { |
|
26 |
private Component component;
|
|
27 | 3 |
public ComponentMatcher(Component c) {
|
28 | 3 |
component = c; |
29 |
} |
|
30 | 79 |
public boolean matches(Component c) { |
31 | 79 |
return c == component;
|
32 |
} |
|
33 |
} |
|
34 |
|
|
35 |
private Hierarchy hierarchy;
|
|
36 |
private ComponentFinder finder;
|
|
37 |
private Resolver resolver;
|
|
38 |
|
|
39 |
/** Obtain a consistent hierarchy. */
|
|
40 | 95 |
protected Hierarchy getHierarchy() { return hierarchy; } |
41 |
|
|
42 |
/** Provide for derived classes to provide their own Hierarchy. */
|
|
43 | 515 |
protected Hierarchy createHierarchy() {
|
44 | 515 |
return new TestHierarchy(); |
45 |
} |
|
46 |
|
|
47 |
/** Obtain a component finder to look up components. */
|
|
48 | 559 |
protected ComponentFinder getFinder() { return finder; } |
49 |
|
|
50 |
/** Obtain a consistent resolver. */
|
|
51 | 780 |
protected Resolver getResolver() { return resolver; } |
52 |
|
|
53 |
/** Fixture setup is performed here, to avoid problems should a derived
|
|
54 |
class define its own setUp and neglect to invoke the superclass
|
|
55 |
method.
|
|
56 |
*/
|
|
57 | 523 |
protected void fixtureSetUp() throws Throwable { |
58 | 523 |
hierarchy = createHierarchy(); |
59 |
|
|
60 | 523 |
finder = new BasicFinder(hierarchy);
|
61 |
// FIXME kind of a hack, but Script is the only implementation of
|
|
62 |
// Resolver we've got at the moment.
|
|
63 | 523 |
resolver = new Script(hierarchy);
|
64 |
} |
|
65 |
|
|
66 |
/** Fixture teardown is performed here, to avoid problems should a derived
|
|
67 |
class define its own tearDown and neglect to invoke the superclass
|
|
68 |
method.
|
|
69 |
*/
|
|
70 | 523 |
protected void fixtureTearDown() throws Throwable { |
71 | 523 |
Iterator iter = hierarchy.getRoots().iterator(); |
72 | 523 |
while (iter.hasNext()) {
|
73 | 477 |
hierarchy.dispose((Window)iter.next()); |
74 |
} |
|
75 |
// Explicitly set these null, since the test fixture instance may
|
|
76 |
// be kept around by the test runner
|
|
77 | 523 |
hierarchy = null;
|
78 | 523 |
resolver = null;
|
79 | 523 |
finder = null;
|
80 |
} |
|
81 |
|
|
82 |
/** Override the default <code>junit.framework.TestCase#RunBare()</code>
|
|
83 |
to ensure proper test harness setup and teardown that won't
|
|
84 |
likely be accidentally overridden by a derived class.
|
|
85 |
*/
|
|
86 | 523 |
public void runBare() throws Throwable { |
87 | 523 |
Log.log("setting up fixture: " + getName());
|
88 | 523 |
Throwable exception = null;
|
89 | 523 |
fixtureSetUp(); |
90 | 523 |
try {
|
91 | 523 |
super.runBare();
|
92 |
} |
|
93 |
catch(Throwable e) {
|
|
94 | 6 |
exception = e; |
95 |
} |
|
96 |
finally {
|
|
97 | 523 |
Log.log("tearing down fixture: " + getName());
|
98 | 523 |
try {
|
99 | 523 |
fixtureTearDown(); |
100 |
} |
|
101 |
catch(Throwable tearingDown) {
|
|
102 | 0 |
if (exception == null) |
103 | 0 |
exception = tearingDown; |
104 |
} |
|
105 |
} |
|
106 | 523 |
if (exception != null) |
107 | 6 |
throw exception;
|
108 |
} |
|
109 |
|
|
110 |
/** Construct a test case with the given name. */
|
|
111 | 406 |
public ResolverFixture(String name) {
|
112 | 406 |
super(name);
|
113 |
} |
|
114 |
|
|
115 |
/** Default Constructor. The name will be automatically set from the
|
|
116 |
selected test method.
|
|
117 |
*/
|
|
118 | 117 |
public ResolverFixture() { }
|
119 |
} |
|
120 |
|
|