01: package org.uispec4j.interception.toolkit;
02:
03: import org.uispec4j.Window;
04: import org.uispec4j.interception.handlers.InterceptionHandler;
05: import org.uispec4j.utils.UnitTestCase;
06:
07: import javax.swing.*;
08: import java.awt.*;
09:
10: public class UISpecToolkitTest extends UnitTestCase {
11:
12: public void testInitUISpecToolkit() throws Exception {
13: UISpecToolkit.setUp();
14: assertUISpecToolkitHasBeenSetup();
15: }
16:
17: public void testRedundantInit() throws Exception {
18: UISpecToolkit.setUp();
19: UISpecToolkit.setUp();
20: assertUISpecToolkitHasBeenSetup();
21: }
22:
23: public void testTearDownUISpecToolkit() throws Exception {
24: UISpecToolkit.setUp();
25:
26: MockHandler handler = new MockHandler();
27: UISpecDisplay.instance().add(handler);
28:
29: // Force creation of a Frame peer
30: JFrame frame = new JFrame();
31: frame.addNotify();
32: }
33:
34: public void testTheAwtToolkitPropertyIsSetWithTheDefaultToolkit()
35: throws Exception {
36: System.getProperties().remove(UISpecToolkit.SYSTEM_PROPERTY);
37: UISpecToolkit.setUp();
38:
39: assertUISpecToolkitHasBeenSetup();
40: UISpecToolkit.restoreAwtToolkit();
41: assertTrue(System.getProperty(UISpecToolkit.SYSTEM_PROPERTY)
42: .indexOf("uispec4j") < 0);
43: }
44:
45: private void assertUISpecToolkitHasBeenSetup() {
46: Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
47:
48: assertSame("The UISpecToolkit should be setup",
49: UISpecToolkit.class, defaultToolkit.getClass());
50: assertFalse(
51: "The UISpecToolkit should contain the default toolkit",
52: UISpecToolkit.class.getName().equals(
53: ((UISpecToolkit) defaultToolkit)
54: .getUnderlyingToolkit().getClass()
55: .getName()));
56: }
57:
58: private static class MockHandler implements InterceptionHandler {
59: String call = "";
60:
61: public void process(Window window) {
62: this .call += "process(...)";
63: }
64: }
65: }
|