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