01: package org.uispec4j.interception;
02:
03: import org.uispec4j.Window;
04: import org.uispec4j.TextBox;
05:
06: import javax.swing.*;
07: import java.util.Arrays;
08:
09: public class MainClassAdapterTest extends InterceptionTestCase {
10: public void test() throws Exception {
11: MainClassAdapter adapter = new MainClassAdapter(MyClass.class,
12: new String[] { "a", "b" });
13: Window window = adapter.getMainWindow();
14: TextBox textBox = window.getTextBox();
15: assertTrue(textBox.textEquals("[a, b]"));
16: }
17:
18: public void testReusesTheInterceptedWindowOnSubsequentCalls()
19: throws Exception {
20: MyClass.callCount = 0;
21:
22: MainClassAdapter adapter = new MainClassAdapter(MyClass.class,
23: new String[] { "a", "b" });
24: Window window1 = adapter.getMainWindow();
25: Window window2 = adapter.getMainWindow();
26: assertSame(window1, window2);
27: assertEquals(1, MyClass.callCount);
28:
29: adapter.reset();
30: Window window3 = adapter.getMainWindow();
31: assertNotSame(window1, window3);
32: assertEquals(2, MyClass.callCount);
33: }
34:
35: public void testNoMain() throws Exception {
36: try {
37: new MainClassAdapter(MainClassAdapterTest.class,
38: new String[] { "a", "b" });
39: } catch (RuntimeException e) {
40: assertEquals(
41: "Class org.uispec4j.interception.MainClassAdapterTest has no method: public static void main(String[])",
42: e.getMessage());
43: }
44: }
45:
46: private static class MyClass {
47: public static int callCount = 0;
48:
49: public static void main(String[] args) {
50: callCount++;
51: JFrame frame = new JFrame();
52: frame.getContentPane().add(
53: new JLabel(Arrays.asList(args).toString()));
54: frame.setVisible(true);
55: }
56: }
57: }
|