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