|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
AbstractTestCase.java | 75% | 92% | 90.9% | 90% |
|
1 |
package junit.extensions.jfcunit;
|
|
2 |
|
|
3 |
import javax.swing.JDialog;
|
|
4 |
import javax.swing.JFrame;
|
|
5 |
|
|
6 |
import junit.extensions.jfcunit.tools.JFCUtilities;
|
|
7 |
import java.awt.Window;
|
|
8 |
|
|
9 |
/**
|
|
10 |
* An abstract class to be used for testing the jfcUnit framework.
|
|
11 |
*
|
|
12 |
* @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
|
|
13 |
*/
|
|
14 |
public class AbstractTestCase extends JFCTestCase { |
|
15 |
/**
|
|
16 |
* The frame which is used to contain the tested objects.
|
|
17 |
*/
|
|
18 |
private Window m_window;
|
|
19 |
|
|
20 |
/**
|
|
21 |
* Sleep time between events.
|
|
22 |
*/
|
|
23 |
private long m_sleepTimer = 100L; |
|
24 |
|
|
25 |
/**
|
|
26 |
* Constructor.
|
|
27 |
*
|
|
28 |
* @param name Name of the test case.
|
|
29 |
*/
|
|
30 | 355 |
public AbstractTestCase(final String name) {
|
31 | 355 |
super(name);
|
32 | 355 |
setLockWait(25L); |
33 |
} |
|
34 |
|
|
35 |
/**
|
|
36 |
* Tear down the test.
|
|
37 |
*
|
|
38 |
* @exception Exception An instance of java.lang.Exception can be thrown
|
|
39 |
*/
|
|
40 | 355 |
protected void tearDown() throws Exception { |
41 | 355 |
TestHelper.disposeWindow(m_window, this);
|
42 | 355 |
super.tearDown();
|
43 |
} |
|
44 |
|
|
45 |
/**
|
|
46 |
* Set the sleep time between events for the test.
|
|
47 |
*
|
|
48 |
* @param sleepTimer time for awt thread processing
|
|
49 |
* before next event is sent.
|
|
50 |
*/
|
|
51 | 120 |
protected void setSleepTimer(final long sleepTimer) { |
52 | 120 |
this.m_sleepTimer = sleepTimer;
|
53 |
} |
|
54 |
|
|
55 |
/**
|
|
56 |
* Get the sleep time between events.
|
|
57 |
*
|
|
58 |
* @return the sleep time between events.
|
|
59 |
*/
|
|
60 | 634 |
protected long getSleepTimer() { |
61 | 634 |
return m_sleepTimer;
|
62 |
} |
|
63 |
|
|
64 |
/**
|
|
65 |
* A method which can be used to create a <code>JFrame</code>
|
|
66 |
* and set some common default values on it.
|
|
67 |
*
|
|
68 |
* @param title The title of the JFrame to be created.
|
|
69 |
* @return A JFrame with some default parameters.
|
|
70 |
*/
|
|
71 | 232 |
protected JFrame createJFrame(final String title) {
|
72 | 232 |
JFrame jFrame; |
73 | 232 |
if (title == null) { |
74 | 2 |
jFrame = new JFrame();
|
75 |
} else {
|
|
76 | 230 |
jFrame = new JFrame(title);
|
77 |
} |
|
78 | 232 |
return jFrame;
|
79 |
} |
|
80 |
|
|
81 |
/**
|
|
82 |
* A method which can be used to create a <code>JDialog</code>
|
|
83 |
* and set some common default values on it.
|
|
84 |
*
|
|
85 |
* @param owner Owner of the dialog.
|
|
86 |
* @param title The title of the JFrame to be created.
|
|
87 |
* @return A JDialog with some default parameters.
|
|
88 |
*/
|
|
89 | 4 |
protected JDialog createJDialog(final JFrame owner, final String title) {
|
90 | 4 |
JDialog jDialog; |
91 | 4 |
if (title == null) { |
92 | 0 |
jDialog = new JDialog(owner);
|
93 |
} else {
|
|
94 | 4 |
jDialog = new JDialog(owner, title);
|
95 |
} |
|
96 | 4 |
return jDialog;
|
97 |
} |
|
98 |
|
|
99 |
/**
|
|
100 |
* A method which is used to pack the specified <code>JFrame</code>,
|
|
101 |
* center it on the screen, and then show it.
|
|
102 |
*
|
|
103 |
* @param jFrame The <code>JFrame</code> to be shown.
|
|
104 |
*/
|
|
105 | 181 |
protected void packAndShow(final JFrame jFrame) { |
106 | 181 |
jFrame.pack(); |
107 |
/* This does'nt seem to work. This code is to set a minimum size on the frame
|
|
108 |
* so as to show the title completely.
|
|
109 |
Dimension dim = jFrame.getSize();
|
|
110 |
FontMetrics metrics = jFrame.getFontMetrics(jFrame.getFont());
|
|
111 |
double minWidth = metrics.getStringBounds(jFrame.getTitle(), jFrame.getGraphics()).getWidth();
|
|
112 |
if (dim.getWidth() < minWidth) {
|
|
113 |
Dimension minDim = new Dimension((int) minWidth, (int) dim.getHeight());
|
|
114 |
jFrame.getLayeredPane().setMinimumSize(minDim);
|
|
115 |
}
|
|
116 |
*/
|
|
117 | 181 |
JFCUtilities.center(jFrame); |
118 | 181 |
jFrame.setVisible(true);
|
119 |
} |
|
120 |
|
|
121 |
/**
|
|
122 |
* A method which is used to pack the specified <code>JDialog</code>,
|
|
123 |
* center it on the screen, and then show it.
|
|
124 |
*
|
|
125 |
* @param jDialog The <code>JDialog</code> to be shown.
|
|
126 |
*/
|
|
127 | 11 |
protected void packAndShow(final JDialog jDialog) { |
128 | 11 |
jDialog.pack(); |
129 |
/* This does'nt seem to work. This code is to set a minimum size on the frame
|
|
130 |
* so as to show the title completely.
|
|
131 |
Dimension dim = jDialog.getSize();
|
|
132 |
FontMetrics metrics = jDialog.getFontMetrics(jDialog.getFont());
|
|
133 |
double minWidth = metrics.getStringBounds(jDialog.getTitle(), jDialog.getGraphics()).getWidth();
|
|
134 |
if (dim.getWidth() < minWidth) {
|
|
135 |
Dimension minDim = new Dimension((int) minWidth, (int) dim.getHeight());
|
|
136 |
jDialog.getLayeredPane().setMinimumSize(minDim);
|
|
137 |
}
|
|
138 |
*/
|
|
139 | 11 |
JFCUtilities.center(jDialog); |
140 | 11 |
jDialog.setVisible(true);
|
141 |
} |
|
142 |
|
|
143 |
/**
|
|
144 |
* Get the frame.
|
|
145 |
* @return The frame.
|
|
146 |
*/
|
|
147 | 454 |
protected JFrame getFrame() {
|
148 | 454 |
return (JFrame) m_window;
|
149 |
} |
|
150 |
|
|
151 |
/**
|
|
152 |
* Get the window as a Dialog.
|
|
153 |
* @return JDialog
|
|
154 |
*/
|
|
155 | 0 |
protected JDialog getDialog() {
|
156 | 0 |
return (JDialog) m_window;
|
157 |
} |
|
158 |
|
|
159 |
/**
|
|
160 |
* Set the frame.
|
|
161 |
* @param window Frame to be used.
|
|
162 |
*/
|
|
163 | 192 |
protected void setWindow(final Window window) { |
164 | 192 |
m_window = window; |
165 |
} |
|
166 |
} |
|
167 |
|
|