1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.grinder.tools.tcpproxy;
24
25 import java.awt.Component;
26 import java.awt.event.WindowEvent;
27 import javax.swing.JButton;
28
29 import net.grinder.testutility.RandomStubFactory;
30
31 import junit.framework.TestCase;
32
33
34
35
36
37
38
39 public class TestTCPProxyConsole extends TestCase {
40
41 public void testConstructor() throws Exception {
42 final RandomStubFactory<TCPProxyEngine> engineStubFactory =
43 RandomStubFactory.create(TCPProxyEngine.class);
44
45 final UpdatableCommentSource commentSource =
46 new CommentSourceImplementation();
47
48 final TCPProxyConsole console =
49 new TCPProxyConsole(engineStubFactory.getStub(), commentSource);
50
51 console.dispose();
52
53 engineStubFactory.assertNoMoreCalls();
54 }
55
56 public void testButton() throws Exception {
57 final RandomStubFactory<TCPProxyEngine> engineStubFactory =
58 RandomStubFactory.create(TCPProxyEngine.class);
59
60 final UpdatableCommentSource commentSource =
61 new CommentSourceImplementation();
62
63 final TCPProxyConsole console =
64 new TCPProxyConsole(engineStubFactory.getStub(), commentSource);
65
66 JButton stopButton = null;
67
68 final Component[] components = console.getContentPane().getComponents();
69 for (int i=0; i<components.length; ++i) {
70 if (components[i] instanceof JButton) {
71 final JButton b = (JButton)components[i];
72 if ("Stop".equals(b.getText())) {
73 stopButton = (JButton)components[i];
74 }
75 }
76 }
77
78 assertNotNull(stopButton);
79
80 if (stopButton != null) {
81 stopButton.doClick();
82 }
83 engineStubFactory.assertSuccess("stop");
84 engineStubFactory.assertNoMoreCalls();
85
86 console.dispatchEvent(new WindowEvent(console, WindowEvent.WINDOW_CLOSING));
87 engineStubFactory.assertSuccess("stop");
88 engineStubFactory.assertNoMoreCalls();
89
90 console.dispose();
91
92 engineStubFactory.assertNoMoreCalls();
93
94
95 }
96 }