Clover Coverage Report - FEST Swing 1.2
Coverage timestamp: Tue Jun 1 2010 15:19:25 PDT
../../../../img/srcFileCovDistChart4.png 97% of files have more coverage
46   315   25   1.84
0   109   0.54   25
25     1  
1    
 
  JPanelFixture       Line # 39 46 0% 25 48 32.4% 0.32394367
 
No Tests
 
1    /*
2    * Created on Nov 1, 2007
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5    * the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10    * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11    * specific language governing permissions and limitations under the License.
12    *
13    * Copyright @2007-2010 the original author or authors.
14    */
15    package org.fest.swing.fixture;
16   
17    import java.awt.Point;
18    import java.util.regex.Pattern;
19   
20    import javax.swing.JPanel;
21   
22    import org.fest.swing.core.*;
23    import org.fest.swing.driver.JComponentDriver;
24    import org.fest.swing.exception.ComponentLookupException;
25    import org.fest.swing.exception.WaitTimedOutError;
26    import org.fest.swing.timing.Timeout;
27   
28    /**
29    * Understands functional testing of <code>{@link JPanel}</code>s:
30    * <ul>
31    * <li>user input simulation</li>
32    * <li>state verification</li>
33    * <li>property value query</li>
34    * </ul>
35    *
36    * @author Alex Ruiz
37    * @author Yvonne Wang
38    */
 
39    public class JPanelFixture extends ContainerFixture<JPanel> implements CommonComponentFixture, JComponentFixture,
40    JPopupMenuInvokerFixture {
41   
42    private JComponentDriver driver;
43   
44    /**
45    * Creates a new <code>{@link JPanelFixture}</code>.
46    * @param robot performs simulation of user events on a <code>JPanel</code>.
47    * @param panelName the name of the <code>JPanel</code> to find using the given <code>Robot</code>.
48    * @throws NullPointerException if <code>robot</code> is <code>null</code>.
49    * @throws ComponentLookupException if a matching <code>JPanel</code> could not be found.
50    * @throws ComponentLookupException if more than one matching <code>JPanel</code> is found.
51    */
 
52  1 toggle public JPanelFixture(Robot robot, String panelName) {
53  1 super(robot, panelName, JPanel.class);
54  1 createDriver();
55    }
56   
57    /**
58    * Creates a new <code>{@link JPanelFixture}</code>.
59    * @param robot performs simulation of user events on the given <code>JPanel</code>.
60    * @param target the <code>JPanel</code> to be managed by this fixture.
61    * @throws NullPointerException if <code>robot</code> is <code>null</code>.
62    * @throws NullPointerException if <code>target</code> is <code>null</code>.
63    */
 
64  10 toggle public JPanelFixture(Robot robot, JPanel target) {
65  10 super(robot, target);
66  10 createDriver();
67    }
68   
 
69  11 toggle private void createDriver() {
70  11 driver(new JComponentDriver(robot));
71    }
72   
73    /**
74    * Sets the <code>{@link JComponentDriver}</code> to be used by this fixture.
75    * @param newDriver the new <code>JComponentDriver</code>.
76    * @throws NullPointerException if the given driver is <code>null</code>.
77    */
 
78  18 toggle protected final void driver(JComponentDriver newDriver) {
79  18 validateNotNull(newDriver);
80  17 driver = newDriver;
81    }
82   
83    /**
84    * Simulates a user clicking this fixture's <code>{@link JPanel}</code>.
85    * @return this fixture.
86    */
 
87  0 toggle public JPanelFixture click() {
88  0 driver.click(target);
89  0 return this;
90    }
91   
92    /**
93    * Simulates a user clicking this fixture's <code>{@link JPanel}</code>.
94    * @param button the button to click.
95    * @return this fixture.
96    */
 
97  0 toggle public JPanelFixture click(MouseButton button) {
98  0 driver.click(target, button);
99  0 return this;
100    }
101   
102    /**
103    * Simulates a user clicking this fixture's <code>{@link JPanel}</code>.
104    * @param mouseClickInfo specifies the button to click and the times the button should be clicked.
105    * @return this fixture.
106    * @throws NullPointerException if the given <code>MouseClickInfo</code> is <code>null</code>.
107    */
 
108  0 toggle public JPanelFixture click(MouseClickInfo mouseClickInfo) {
109  0 driver.click(target, mouseClickInfo);
110  0 return this;
111    }
112   
113    /**
114    * Simulates a user right-clicking this fixture's <code>{@link JPanel}</code>.
115    * @return this fixture.
116    */
 
117  0 toggle public JPanelFixture rightClick() {
118  0 driver.rightClick(target);
119  0 return this;
120    }
121   
122    /**
123    * Simulates a user double-clicking this fixture's <code>{@link JPanel}</code>.
124    * @return this fixture.
125    */
 
126  0 toggle public JPanelFixture doubleClick() {
127  0 driver.doubleClick(target);
128  0 return this;
129    }
130   
131    /**
132    * Gives input focus to this fixture's <code>{@link JPanel}</code>.
133    * @return this fixture.
134    */
 
135  0 toggle public JPanelFixture focus() {
136  0 driver.focus(target);
137  0 return this;
138    }
139   
140    /**
141    * Simulates a user pressing given key with the given modifiers on this fixture's <code>{@link JPanel}</code>.
142    * Modifiers is a mask from the available <code>{@link java.awt.event.InputEvent}</code> masks.
143    * @param keyPressInfo specifies the key and modifiers to press.
144    * @return this fixture.
145    * @throws NullPointerException if the given <code>KeyPressInfo</code> is <code>null</code>.
146    * @throws IllegalArgumentException if the given code is not a valid key code.
147    * @see KeyPressInfo
148    */
 
149  0 toggle public JPanelFixture pressAndReleaseKey(KeyPressInfo keyPressInfo) {
150  0 driver.pressAndReleaseKey(target, keyPressInfo);
151  0 return this;
152    }
153   
154    /**
155    * Simulates a user pressing and releasing the given keys on the <code>{@link JPanel}</code> managed by this
156    * fixture.
157    * @param keyCodes one or more codes of the keys to press.
158    * @return this fixture.
159    * @throws NullPointerException if the given array of codes is <code>null</code>.
160    * @throws IllegalArgumentException if any of the given code is not a valid key code.
161    * @see java.awt.event.KeyEvent
162    */
 
163  0 toggle public JPanelFixture pressAndReleaseKeys(int... keyCodes) {
164  0 driver.pressAndReleaseKeys(target, keyCodes);
165  0 return this;
166    }
167   
168    /**
169    * Simulates a user pressing the given key on this fixture's <code>{@link JPanel}</code>.
170    * @param keyCode the code of the key to press.
171    * @return this fixture.
172    * @throws IllegalArgumentException if any of the given code is not a valid key code.
173    * @see java.awt.event.KeyEvent
174    */
 
175  0 toggle public JPanelFixture pressKey(int keyCode) {
176  0 driver.pressKey(target, keyCode);
177  0 return this;
178    }
179   
180    /**
181    * Simulates a user releasing the given key on this fixture's <code>{@link JPanel}</code>.
182    * @param keyCode the code of the key to release.
183    * @return this fixture.
184    * @throws IllegalArgumentException if any of the given code is not a valid key code.
185    * @see java.awt.event.KeyEvent
186    */
 
187  0 toggle public JPanelFixture releaseKey(int keyCode) {
188  0 driver.releaseKey(target, keyCode);
189  0 return this;
190    }
191   
192    /**
193    * Asserts that this fixture's <code>{@link JPanel}</code> has input focus.
194    * @return this fixture.
195    * @throws AssertionError if this fixture's <code>JPanel</code> does not have input focus.
196    */
 
197  0 toggle public JPanelFixture requireFocused() {
198  0 driver.requireFocused(target);
199  0 return this;
200    }
201   
202    /**
203    * Asserts that this fixture's <code>{@link JPanel}</code> is enabled.
204    * @return this fixture.
205    * @throws AssertionError if this fixture's <code>JPanel</code> is disabled.
206    */
 
207  0 toggle public JPanelFixture requireEnabled() {
208  0 driver.requireEnabled(target);
209  0 return this;
210    }
211   
212    /**
213    * Asserts that this fixture's <code>{@link JPanel}</code> is enabled.
214    * @param timeout the time this fixture will wait for the component to be enabled.
215    * @return this fixture.
216    * @throws WaitTimedOutError if this fixture's <code>JPanel</code> is never enabled.
217    */
 
218  0 toggle public JPanelFixture requireEnabled(Timeout timeout) {
219  0 driver.requireEnabled(target, timeout);
220  0 return this;
221    }
222   
223    /**
224    * Asserts that this fixture's <code>{@link JPanel}</code> is disabled.
225    * @return this fixture.
226    * @throws AssertionError if this fixture's <code>JPanel</code> is enabled.
227    */
 
228  0 toggle public JPanelFixture requireDisabled() {
229  0 driver.requireDisabled(target);
230  0 return this;
231    }
232   
233    /**
234    * Asserts that this fixture's <code>{@link JPanel}</code> is visible.
235    * @return this fixture.
236    * @throws AssertionError if this fixture's <code>JPanel</code> is not visible.
237    */
 
238  0 toggle public JPanelFixture requireVisible() {
239  0 driver.requireVisible(target);
240  0 return this;
241    }
242   
243    /**
244    * Asserts that this fixture's <code>{@link JPanel}</code> is not visible.
245    * @return this fixture.
246    * @throws AssertionError if this fixture's <code>JPanel</code> is visible.
247    */
 
248  0 toggle public JPanelFixture requireNotVisible() {
249  0 driver.requireNotVisible(target);
250  0 return this;
251    }
252   
253    /**
254    * Asserts that the toolTip in this fixture's <code>{@link JPanel}</code> matches the given value.
255    * @param expected the given value. It can be a regular expression.
256    * @return this fixture.
257    * @throws AssertionError if the toolTip in this fixture's <code>JPanel</code> does not match the given value.
258    * @since 1.2
259    */
 
260  1 toggle public JPanelFixture requireToolTip(String expected) {
261  1 driver.requireToolTip(target, expected);
262  1 return this;
263    }
264   
265    /**
266    * Asserts that the toolTip in this fixture's <code>{@link JPanel}</code> matches the given regular expression
267    * pattern.
268    * @param pattern the regular expression pattern to match.
269    * @return this fixture.
270    * @throws NullPointerException if the given regular expression pattern is <code>null</code>.
271    * @throws AssertionError if the toolTip in this fixture's <code>JPanel</code> does not match the given regular
272    * expression.
273    * @since 1.2
274    */
 
275  1 toggle public JPanelFixture requireToolTip(Pattern pattern) {
276  1 driver.requireToolTip(target, pattern);
277  1 return this;
278    }
279   
280    /**
281    * Returns the client property stored in this fixture's <code>{@link JPanel}</code>, under the given key.
282    * @param key the key to use to retrieve the client property.
283    * @return the value of the client property stored under the given key, or <code>null</code> if the property was
284    * not found.
285    * @throws NullPointerException if the given key is <code>null</code>.
286    * @since 1.2
287    */
 
288  1 toggle public Object clientProperty(Object key) {
289  1 return driver.clientProperty(target, key);
290    }
291   
292    /**
293    * Shows a pop-up menu using this fixture's <code>{@link JPanel}</code> as the invoker of the pop-up menu.
294    * @return a fixture that manages the displayed pop-up menu.
295    * @throws IllegalStateException if this fixture's <code>JPanel</code> is disabled.
296    * @throws IllegalStateException if this fixture's <code>JPanel</code> is not showing on the screen.
297    * @throws ComponentLookupException if a pop-up menu cannot be found.
298    */
 
299  1 toggle public JPopupMenuFixture showPopupMenu() {
300  1 return new JPopupMenuFixture(robot, driver.invokePopupMenu(target));
301    }
302   
303    /**
304    * Shows a pop-up menu at the given point using this fixture's <code>{@link JPanel}</code> as the invoker of the
305    * pop-up menu.
306    * @param p the given point where to show the pop-up menu.
307    * @return a fixture that manages the displayed pop-up menu.
308    * @throws IllegalStateException if this fixture's <code>JPanel</code> is disabled.
309    * @throws IllegalStateException if this fixture's <code>JPanel</code> is not showing on the screen.
310    * @throws ComponentLookupException if a pop-up menu cannot be found.
311    */
 
312  1 toggle public JPopupMenuFixture showPopupMenuAt(Point p) {
313  1 return new JPopupMenuFixture(robot, driver.invokePopupMenu(target, p));
314    }
315    }