Clover Coverage Report - FEST Swing 1.2
Coverage timestamp: Tue Jun 1 2010 15:19:25 PDT
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
59   410   32   1.84
0   135   0.54   32
32     1  
1    
 
  JCheckBoxFixture       Line # 38 59 0% 32 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Jun 10, 2007
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with 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
10    * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11    * or implied. See the License for the specific language governing permissions and limitations under
12    * the License.
13    *
14    * Copyright @2007-2010 the original author or authors.
15    */
16    package org.fest.swing.fixture;
17   
18    import java.awt.Point;
19    import java.util.regex.Pattern;
20   
21    import javax.swing.JCheckBox;
22   
23    import org.fest.swing.core.*;
24    import org.fest.swing.driver.AbstractButtonDriver;
25    import org.fest.swing.exception.ComponentLookupException;
26    import org.fest.swing.timing.Timeout;
27   
28    /**
29    * Understands functional testing of <code>{@link JCheckBox}</code>es:
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    */
 
38    public class JCheckBoxFixture extends ComponentFixture<JCheckBox> implements CommonComponentFixture,
39    JComponentFixture, JPopupMenuInvokerFixture, TextDisplayFixture, TwoStateButtonFixture {
40   
41    private AbstractButtonDriver driver;
42   
43    /**
44    * Creates a new <code>{@link JCheckBoxFixture}</code>.
45    * @param robot performs simulation of user events on the given <code>JCheckBox</code>.
46    * @param target the <code>JCheckBox</code> to be managed by this fixture.
47    * @throws NullPointerException if <code>robot</code> is <code>null</code>.
48    * @throws NullPointerException if <code>target</code> is <code>null</code>.
49    */
 
50  32 toggle public JCheckBoxFixture(Robot robot, JCheckBox target) {
51  32 super(robot, target);
52  32 createDriver();
53    }
54   
55    /**
56    * Creates a new <code>{@link JCheckBoxFixture}</code>.
57    * @param robot performs simulation of user events on a <code>JCheckBox</code>.
58    * @param checkBoxName the name of the <code>JCheckBox</code> to find using the given <code>Robot</code>.
59    * @throws NullPointerException if <code>robot</code> is <code>null</code>.
60    * @throws ComponentLookupException if a matching <code>JCheckBox</code> could not be found.
61    * @throws ComponentLookupException if more than one matching <code>JCheckBox</code> is found.
62    */
 
63  1 toggle public JCheckBoxFixture(Robot robot, String checkBoxName) {
64  1 super(robot, checkBoxName, JCheckBox.class);
65  1 createDriver();
66    }
67   
 
68  33 toggle private void createDriver() {
69  33 driver(new AbstractButtonDriver(robot));
70    }
71   
72    /**
73    * Sets the <code>{@link AbstractButtonDriver}</code> to be used by this fixture.
74    * @param newDriver the new <code>AbstractButtonDriver</code>.
75    * @throws NullPointerException if the given driver is <code>null</code>.
76    */
 
77  62 toggle protected final void driver(AbstractButtonDriver newDriver) {
78  62 validateNotNull(newDriver);
79  61 driver = newDriver;
80    }
81   
82    /**
83    * Returns the text of this fixture's <code>{@link JCheckBox}</code>.
84    * @return the text of this fixture's <code>JCheckBox</code>.
85    */
 
86  1 toggle public String text() {
87  1 return driver.textOf(target);
88    }
89   
90    /**
91    * Checks (or selects) this fixture's <code>{@link JCheckBox}</code> only it is not already checked.
92    * @return this fixture.
93    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is disabled.
94    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is not showing on the screen.
95    */
 
96  1 toggle public JCheckBoxFixture check() {
97  1 driver.select(target);
98  1 return this;
99    }
100   
101    /**
102    * Unchecks this fixture's <code>{@link JCheckBox}</code> only if it is checked.
103    * @return this fixture.
104    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is disabled.
105    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is not showing on the screen.
106    */
 
107  1 toggle public JCheckBoxFixture uncheck() {
108  1 driver.unselect(target);
109  1 return this;
110    }
111   
112    /**
113    * Simulates a user clicking this fixture's <code>{@link JCheckBox}</code>.
114    * @return this fixture.
115    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is disabled.
116    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is not showing on the screen.
117    */
 
118  1 toggle public JCheckBoxFixture click() {
119  1 driver.click(target);
120  1 return this;
121    }
122   
123    /**
124    * Simulates a user clicking this fixture's <code>{@link JCheckBox}</code>.
125    * @param button the button to click.
126    * @return this fixture.
127    * @throws NullPointerException if the given <code>MouseButton</code> is <code>null</code>.
128    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is disabled.
129    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is not showing on the screen.
130    */
 
131  1 toggle public JCheckBoxFixture click(MouseButton button) {
132  1 driver.click(target, button);
133  1 return this;
134    }
135   
136    /**
137    * Simulates a user clicking this fixture's <code>{@link JCheckBox}</code>.
138    * @param mouseClickInfo specifies the button to click and the times the button should be clicked.
139    * @return this fixture.
140    * @throws NullPointerException if the given <code>MouseClickInfo</code> is <code>null</code>.
141    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is disabled.
142    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is not showing on the screen.
143    */
 
144  1 toggle public JCheckBoxFixture click(MouseClickInfo mouseClickInfo) {
145  1 driver.click(target, mouseClickInfo);
146  1 return this;
147    }
148   
149    /**
150    * Simulates a user double-clicking this fixture's <code>{@link JCheckBox}</code>.
151    * @return this fixture.
152    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is disabled.
153    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is not showing on the screen.
154    */
 
155  1 toggle public JCheckBoxFixture doubleClick() {
156  1 driver.doubleClick(target);
157  1 return this;
158    }
159   
160    /**
161    * Simulates a user right-clicking this fixture's <code>{@link JCheckBox}</code>.
162    * @return this fixture.
163    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is disabled.
164    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is not showing on the screen.
165    */
 
166  1 toggle public JCheckBoxFixture rightClick() {
167  1 driver.rightClick(target);
168  1 return this;
169    }
170   
171    /**
172    * Gives input focus to this fixture's <code>{@link JCheckBox}</code>.
173    * @return this fixture.
174    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is disabled.
175    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is not showing on the screen.
176    */
 
177  1 toggle public JCheckBoxFixture focus() {
178  1 driver.focus(target);
179  1 return this;
180    }
181   
182    /**
183    * Simulates a user pressing given key with the given modifiers on this fixture's <code>{@link JCheckBox}</code>.
184    * Modifiers is a mask from the available <code>{@link java.awt.event.InputEvent}</code> masks.
185    * @param keyPressInfo specifies the key and modifiers to press.
186    * @return this fixture.
187    * @throws NullPointerException if the given <code>KeyPressInfo</code> is <code>null</code>.
188    * @throws IllegalArgumentException if the given code is not a valid key code.
189    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is disabled.
190    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is not showing on the screen.
191    * @see KeyPressInfo
192    */
 
193  1 toggle public JCheckBoxFixture pressAndReleaseKey(KeyPressInfo keyPressInfo) {
194  1 driver.pressAndReleaseKey(target, keyPressInfo);
195  1 return this;
196    }
197   
198    /**
199    * Simulates a user pressing and releasing the given keys on this fixture's <code>{@link JCheckBox}</code>.
200    * @param keyCodes one or more codes of the keys to press.
201    * @return this fixture.
202    * @throws NullPointerException if the given array of codes is <code>null</code>.
203    * @throws IllegalArgumentException if any of the given code is not a valid key code.
204    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is disabled.
205    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is not showing on the screen.
206    * @see java.awt.event.KeyEvent
207    */
 
208  1 toggle public JCheckBoxFixture pressAndReleaseKeys(int... keyCodes) {
209  1 driver.pressAndReleaseKeys(target, keyCodes);
210  1 return this;
211    }
212   
213    /**
214    * Simulates a user pressing the given key on this fixture's <code>{@link JCheckBox}</code>.
215    * @param keyCode the code of the key to press.
216    * @return this fixture.
217    * @throws IllegalArgumentException if any of the given code is not a valid key code.
218    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is disabled.
219    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is not showing on the screen.
220    * @see java.awt.event.KeyEvent
221    */
 
222  1 toggle public JCheckBoxFixture pressKey(int keyCode) {
223  1 driver.pressKey(target, keyCode);
224  1 return this;
225    }
226   
227    /**
228    * Simulates a user releasing the given key on this fixture's <code>{@link JCheckBox}</code>.
229    * @param keyCode the code of the key to release.
230    * @return this fixture.
231    * @throws IllegalArgumentException if any of the given code is not a valid key code.
232    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is disabled.
233    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is not showing on the screen.
234    * @see java.awt.event.KeyEvent
235    */
 
236  1 toggle public JCheckBoxFixture releaseKey(int keyCode) {
237  1 driver.releaseKey(target, keyCode);
238  1 return this;
239    }
240   
241    /**
242    * Asserts that this fixture's <code>{@link JCheckBox}</code> has input focus.
243    * @return this fixture.
244    * @throws AssertionError if this fixture's <code>JCheckBox</code> does not have input focus.
245    */
 
246  1 toggle public JCheckBoxFixture requireFocused() {
247  1 driver.requireFocused(target);
248  1 return this;
249    }
250   
251    /**
252    * Asserts that this fixture's <code>{@link JCheckBox}</code> is enabled.
253    * @return this fixture.
254    * @throws AssertionError if this fixture's <code>JCheckBox</code> is disabled.
255    */
 
256  1 toggle public JCheckBoxFixture requireEnabled() {
257  1 driver.requireEnabled(target);
258  1 return this;
259    }
260   
261    /**
262    * Asserts that this fixture's <code>{@link JCheckBox}</code> is enabled.
263    * @param timeout the time this fixture will wait for the component to be enabled.
264    * @return this fixture.
265    * @throws org.fest.swing.exception.WaitTimedOutError if this fixture's <code>JCheckBox</code> is never enabled.
266    */
 
267  1 toggle public JCheckBoxFixture requireEnabled(Timeout timeout) {
268  1 driver.requireEnabled(target, timeout);
269  1 return this;
270    }
271   
272    /**
273    * Asserts that this fixture's <code>{@link JCheckBox}</code> is disabled.
274    * @return this fixture.
275    * @throws AssertionError if this fixture's <code>JCheckBox</code> is enabled.
276    */
 
277  1 toggle public JCheckBoxFixture requireDisabled() {
278  1 driver.requireDisabled(target);
279  1 return this;
280    }
281   
282    /**
283    * Verifies that this fixture's <code>{@link JCheckBox}</code> is selected.
284    * @return this fixture.
285    * @throws AssertionError if the <code>JCheckBox</code> managed by this fixture is not selected.
286    */
 
287  1 toggle public JCheckBoxFixture requireSelected() {
288  1 driver.requireSelected(target);
289  1 return this;
290    }
291   
292    /**
293    * Verifies that this fixture's <code>{@link JCheckBox}</code> is not selected.
294    * @return this fixture.
295    * @throws AssertionError if the <code>JCheckBox</code> managed by this fixture is selected.
296    */
 
297  1 toggle public JCheckBoxFixture requireNotSelected() {
298  1 driver.requireNotSelected(target);
299  1 return this;
300    }
301   
302    /**
303    * Asserts that this fixture's <code>{@link JCheckBox}</code> is visible.
304    * @return this fixture.
305    * @throws AssertionError if this fixture's <code>JCheckBox</code> is not visible.
306    */
 
307  1 toggle public JCheckBoxFixture requireVisible() {
308  1 driver.requireVisible(target);
309  1 return this;
310    }
311   
312    /**
313    * Asserts that this fixture's <code>{@link JCheckBox}</code> is not visible.
314    * @return this fixture.
315    * @throws AssertionError if this fixture's <code>JCheckBox</code> is visible.
316    */
 
317  1 toggle public JCheckBoxFixture requireNotVisible() {
318  1 driver.requireNotVisible(target);
319  1 return this;
320    }
321   
322    /**
323    * Asserts that the text of this fixture's <code>{@link JCheckBox}</code> is equal to or matches the specified
324    * <code>String</code>.
325    * @param expected the text to match. It can be a regular expression.
326    * @return this fixture.
327    * @throws AssertionError if the text of the target JCheckBox is not equal to or does not match the given one.
328    */
 
329  1 toggle public JCheckBoxFixture requireText(String expected) {
330  1 driver.requireText(target, expected);
331  1 return this;
332    }
333   
334    /**
335    * Asserts that the text of this fixture's <code>{@link JCheckBox}</code> matches the given regular expression pattern.
336    * @param pattern the regular expression pattern to match.
337    * @return this fixture.
338    * @throws NullPointerException if the given regular expression pattern is <code>null</code>.
339    * @throws AssertionError if the text of the target <code>JCheckBox</code> does not match the given regular expression
340    * pattern.
341    * @since 1.2
342    */
 
343  1 toggle public JCheckBoxFixture requireText(Pattern pattern) {
344  1 driver.requireText(target, pattern);
345  1 return this;
346    }
347   
348    /**
349    * Asserts that the toolTip in this fixture's <code>{@link JCheckBox}</code> matches the given value.
350    * @param expected the given value. It can be a regular expression.
351    * @return this fixture.
352    * @throws AssertionError if the toolTip in this fixture's <code>JCheckBox</code> does not match the given value.
353    * @since 1.2
354    */
 
355  1 toggle public JCheckBoxFixture requireToolTip(String expected) {
356  1 driver.requireToolTip(target, expected);
357  1 return this;
358    }
359   
360    /**
361    * Asserts that the toolTip in this fixture's <code>{@link JCheckBox}</code> matches the given regular expression
362    * pattern.
363    * @param pattern the regular expression pattern to match.
364    * @return this fixture.
365    * @throws NullPointerException if the given regular expression pattern is <code>null</code>.
366    * @throws AssertionError if the toolTip in this fixture's <code>JCheckBox</code> does not match the given regular
367    * expression.
368    * @since 1.2
369    */
 
370  1 toggle public JCheckBoxFixture requireToolTip(Pattern pattern) {
371  1 driver.requireToolTip(target, pattern);
372  1 return this;
373    }
374   
375    /**
376    * Returns the client property stored in this fixture's <code>{@link JCheckBox}</code>, under the given key.
377    * @param key the key to use to retrieve the client property.
378    * @return the value of the client property stored under the given key, or <code>null</code> if the property was
379    * not found.
380    * @throws NullPointerException if the given key is <code>null</code>.
381    * @since 1.2
382    */
 
383  1 toggle public Object clientProperty(Object key) {
384  1 return driver.clientProperty(target, key);
385    }
386   
387    /**
388    * Shows a pop-up menu using this fixture's <code>{@link JCheckBox}</code> as the invoker of the pop-up menu.
389    * @return a fixture that manages the displayed pop-up menu.
390    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is disabled.
391    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is not showing on the screen.
392    * @throws ComponentLookupException if a pop-up menu cannot be found.
393    */
 
394  1 toggle public JPopupMenuFixture showPopupMenu() {
395  1 return new JPopupMenuFixture(robot, driver.invokePopupMenu(target));
396    }
397   
398    /**
399    * Shows a pop-up menu at the given point using this fixture's <code>{@link JCheckBox}</code> as the invoker of the
400    * pop-up menu.
401    * @param p the given point where to show the pop-up menu.
402    * @return a fixture that manages the displayed pop-up menu.
403    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is disabled.
404    * @throws IllegalStateException if this fixture's <code>JCheckBox</code> is not showing on the screen.
405    * @throws ComponentLookupException if a pop-up menu cannot be found.
406    */
 
407  1 toggle public JPopupMenuFixture showPopupMenuAt(Point p) {
408  1 return new JPopupMenuFixture(robot, driver.invokePopupMenu(target, p));
409    }
410    }