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
66   446   37   1.78
0   151   0.56   37
37     1  
1    
 
  JOptionPaneFixture       Line # 39 66 0% 37 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Oct 20, 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 static org.fest.swing.fixture.ComponentFixtureValidator.notNullRobot;
19   
20    import java.util.regex.Pattern;
21   
22    import javax.swing.JOptionPane;
23   
24    import org.fest.swing.core.*;
25    import org.fest.swing.driver.JOptionPaneDriver;
26    import org.fest.swing.exception.ComponentLookupException;
27    import org.fest.swing.timing.Timeout;
28   
29    /**
30    * Understands functional testing of <code>{@link JOptionPane}</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 Alex Ruiz
38    */
 
39    public class JOptionPaneFixture extends ContainerFixture<JOptionPane> implements CommonComponentFixture {
40   
41    private JOptionPaneDriver driver;
42   
43    /**
44    * Creates a new <code>{@link JOptionPaneFixture}</code>.
45    * @param robot finds a showing {@code JOptionPane}, which will be managed by this fixture.
46    * @throws NullPointerException if <code>robot</code> is <code>null</code>.
47    * @throws ComponentLookupException if a showing {@code JOptionPane} could not be found.
48    * @throws ComponentLookupException if more than one showing {@code JOptionPane} is found.
49    */
 
50  1 toggle public JOptionPaneFixture(Robot robot) {
51  1 this(robot, findShowingOptionPane(robot));
52    }
53   
 
54  1 toggle private static JOptionPane findShowingOptionPane(Robot robot) {
55  1 notNullRobot(robot);
56  1 return robot.finder().findByType(JOptionPane.class, true);
57    }
58   
59    /**
60    * Creates a new <code>{@link JOptionPaneFixture}</code>.
61    * @param robot performs simulation of user events on the given {@code JOptionPane}.
62    * @param target the {@code JOptionPane} to be managed by this fixture.
63    * @throws NullPointerException if <code>robot</code> is <code>null</code>.
64    * @throws IllegalArgumentException if <code>target</code> is <code>null</code>.
65    */
 
66  46 toggle public JOptionPaneFixture(Robot robot, JOptionPane target) {
67  46 super(robot, target);
68  46 driver(new JOptionPaneDriver(robot));
69    }
70   
71    /**
72    * Sets the <code>{@link JOptionPaneDriver}</code> to be used by this fixture.
73    * @param newDriver the new <code>JOptionPaneDriver</code>.
74    * @throws NullPointerException if the given driver is <code>null</code>.
75    */
 
76  80 toggle protected final void driver(JOptionPaneDriver newDriver) {
77  80 validateNotNull(newDriver);
78  79 driver = newDriver;
79    }
80   
81    /**
82    * Returns the title of this fixture's <code>{@link JOptionPane}</code>.
83    * @return the title of this fixture's {@code JOptionPane}.
84    * @since 1.2
85    */
 
86  1 toggle public String title() {
87  1 return driver.title(target);
88    }
89   
90    /**
91    * Returns a fixture wrapping the "OK" button in this fixture's <code>{@link JOptionPane}</code>. This method is
92    * locale-independent and platform-independent.
93    * @return a fixture wrapping the "OK" button.
94    * @throws ComponentLookupException if the a "OK" button cannot be found.
95    */
 
96  1 toggle public JButtonFixture okButton() {
97  1 return new JButtonFixture(robot, driver.okButton(target));
98    }
99   
100    /**
101    * Returns a fixture wrapping the "Cancel" button in this fixture's <code>{@link JOptionPane}</code>. This method is
102    * locale-independent and platform-independent.
103    * @return a fixture wrapping the "Cancel" button.
104    * @throws ComponentLookupException if the a "Cancel" button cannot be found.
105    */
 
106  1 toggle public JButtonFixture cancelButton() {
107  1 return new JButtonFixture(robot, driver.cancelButton(target));
108    }
109   
110    /**
111    * Returns a fixture wrapping the "Yes" button in this fixture's <code>{@link JOptionPane}</code>. This method is
112    * locale-independent and platform-independent.
113    * @return a fixture wrapping the "Yes" button.
114    * @throws ComponentLookupException if the a "Yes" button cannot be found.
115    */
 
116  1 toggle public JButtonFixture yesButton() {
117  1 return new JButtonFixture(robot, driver.yesButton(target));
118    }
119   
120    /**
121    * Returns a fixture wrapping the "No" button in this fixture's <code>{@link JOptionPane}</code>. This method is
122    * locale-independent and platform-independent.
123    * @return a fixture wrapping the "No" button.
124    * @throws ComponentLookupException if the a "No" button cannot be found.
125    */
 
126  1 toggle public JButtonFixture noButton() {
127  1 return new JButtonFixture(robot, driver.noButton(target));
128    }
129   
130    /**
131    * Finds and returns a fixture wrapping a button (this fixture's <code>{@link JOptionPane}</code>) matching the
132    * given text.
133    * @param text the text of the button to find. It can be a regular expression.
134    * @return a fixture wrapping a button matching the given text.
135    * @throws ComponentLookupException if the a button with the given text cannot be found.
136    */
 
137  1 toggle public JButtonFixture buttonWithText(String text) {
138  1 return new JButtonFixture(robot, driver.buttonWithText(target, text));
139    }
140   
141    /**
142    * Finds and returns a fixture wrapping a button (this fixture's <code>{@link JOptionPane}</code>) matching the
143    * given text.
144    * @param pattern the regular expression pattern to match.
145    * @return a fixture wrapping a button matching the given regular expression pattern.
146    * @throws NullPointerException if the given regular expression pattern is <code>null</code>.
147    * @throws ComponentLookupException if the a button with the given text cannot be found.
148    * @since 1.2
149    */
 
150  1 toggle public JButtonFixture buttonWithText(Pattern pattern) {
151  1 return new JButtonFixture(robot, driver.buttonWithText(target, pattern));
152    }
153   
154    /**
155    * Simulates a user clicking this fixture's <code>{@link JOptionPane}</code>.
156    * @return this fixture.
157    * @throws IllegalStateException if this fixture's {@code JOptionPane} is disabled.
158    * @throws IllegalStateException if this fixture's {@code JOptionPane} is not showing on the screen.
159    */
 
160  1 toggle public JOptionPaneFixture click() {
161  1 driver.click(target);
162  1 return this;
163    }
164   
165    /**
166    * Simulates a user clicking this fixture's <code>{@link JOptionPane}</code>.
167    * @param button the button to click.
168    * @throws NullPointerException if the given <code>MouseButton</code> is <code>null</code>.
169    * @throws IllegalStateException if this fixture's {@code JOptionPane} is disabled.
170    * @throws IllegalStateException if this fixture's {@code JOptionPane} is not showing on the screen.
171    * @return this fixture.
172    */
 
173  1 toggle public JOptionPaneFixture click(MouseButton button) {
174  1 driver.click(target, button);
175  1 return this;
176    }
177   
178    /**
179    * Simulates a user clicking this fixture's <code>{@link JOptionPane}</code>.
180    * @param mouseClickInfo specifies the button to click and the times the button should be clicked.
181    * @return this fixture.
182    * @throws NullPointerException if the given <code>MouseClickInfo</code> is <code>null</code>.
183    * @throws IllegalStateException if this fixture's {@code JOptionPane} is disabled.
184    * @throws IllegalStateException if this fixture's {@code JOptionPane} is not showing on the screen.
185    */
 
186  1 toggle public JOptionPaneFixture click(MouseClickInfo mouseClickInfo) {
187  1 driver.click(target, mouseClickInfo);
188  1 return this;
189    }
190   
191    /**
192    * Simulates a user right-clicking this fixture's <code>{@link JOptionPane}</code>.
193    * @return this fixture.
194    * @throws IllegalStateException if this fixture's {@code JOptionPane} is disabled.
195    * @throws IllegalStateException if this fixture's {@code JOptionPane} is not showing on the screen.
196    */
 
197  1 toggle public JOptionPaneFixture rightClick() {
198  1 driver.rightClick(target);
199  1 return this;
200    }
201   
202    /**
203    * Simulates a user double-clicking this fixture's <code>{@link JOptionPane}</code>.
204    * @return this fixture.
205    * @throws IllegalStateException if this fixture's {@code JOptionPane} is disabled.
206    * @throws IllegalStateException if this fixture's {@code JOptionPane} is not showing on the screen.
207    */
 
208  1 toggle public JOptionPaneFixture doubleClick() {
209  1 driver.doubleClick(target);
210  1 return this;
211    }
212   
213    /**
214    * Gives input focus to this fixture's <code>{@link JOptionPane}</code>.
215    * @return this fixture.
216    * @throws IllegalStateException if this fixture's {@code JOptionPane} is disabled.
217    * @throws IllegalStateException if this fixture's {@code JOptionPane} is not showing on the screen.
218    */
 
219  1 toggle public JOptionPaneFixture focus() {
220  1 driver.focus(target);
221  1 return this;
222    }
223   
224    /**
225    * Asserts that this fixture's <code>{@link JOptionPane}</code> is displaying an error message.
226    * @return this fixture.
227    */
 
228  1 toggle public JOptionPaneFixture requireErrorMessage() {
229  1 driver.requireErrorMessage(target);
230  1 return this;
231    }
232   
233    /**
234    * Asserts that this fixture's <code>{@link JOptionPane}</code> is displaying an information
235    * message.
236    * @return this fixture.
237    */
 
238  2 toggle public JOptionPaneFixture requireInformationMessage() {
239  2 driver.requireInformationMessage(target);
240  2 return this;
241    }
242   
243    /**
244    * Asserts that this fixture's <code>{@link JOptionPane}</code> is displaying a warning message.
245    * @return this fixture.
246    */
 
247  1 toggle public JOptionPaneFixture requireWarningMessage() {
248  1 driver.requireWarningMessage(target);
249  1 return this;
250    }
251   
252    /**
253    * Asserts that this fixture's <code>{@link JOptionPane}</code> is displaying a question.
254    * @return this fixture.
255    */
 
256  1 toggle public JOptionPaneFixture requireQuestionMessage() {
257  1 driver.requireQuestionMessage(target);
258  1 return this;
259    }
260   
261    /**
262    * Asserts that this fixture's <code>{@link JOptionPane}</code> is displaying a plain message.
263    * @return this fixture.
264    */
 
265  1 toggle public JOptionPaneFixture requirePlainMessage() {
266  1 driver.requirePlainMessage(target);
267  1 return this;
268    }
269   
270    /**
271    * Simulates a user pressing given key with the given modifiers on this fixture's <code>{@link JOptionPane}</code>.
272    * Modifiers is a mask from the available <code>{@link java.awt.event.InputEvent}</code> masks.
273    * @param keyPressInfo specifies the key and modifiers to press.
274    * @return this fixture.
275    * @throws NullPointerException if the given <code>KeyPressInfo</code> is <code>null</code>.
276    * @throws IllegalArgumentException if the given code is not a valid key code.
277    * @see KeyPressInfo
278    */
 
279  1 toggle public JOptionPaneFixture pressAndReleaseKey(KeyPressInfo keyPressInfo) {
280  1 driver.pressAndReleaseKey(target, keyPressInfo);
281  1 return this;
282    }
283   
284    /**
285    * Simulates a user pressing and releasing the given keys this fixture's <code>{@link JOptionPane}</code>. This method
286    * does not affect the current focus.
287    * @param keyCodes one or more codes of the keys to press.
288    * @return this fixture.
289    * @throws NullPointerException if the given array of codes is <code>null</code>.
290    * @throws IllegalArgumentException if any of the given code is not a valid key code.
291    * @see java.awt.event.KeyEvent
292    */
 
293  1 toggle public JOptionPaneFixture pressAndReleaseKeys(int... keyCodes) {
294  1 driver.pressAndReleaseKeys(target, keyCodes);
295  1 return this;
296    }
297   
298    /**
299    * Simulates a user pressing the given key on this fixture's <code>{@link JOptionPane}</code>.
300    * @param keyCode the code of the key to press.
301    * @return this fixture.
302    * @throws IllegalArgumentException if any of the given code is not a valid key code.
303    * @see java.awt.event.KeyEvent
304    */
 
305  1 toggle public JOptionPaneFixture pressKey(int keyCode) {
306  1 driver.pressKey(target, keyCode);
307  1 return this;
308    }
309   
310    /**
311    * Simulates a user releasing the given key on this fixture's <code>{@link JOptionPane}</code>.
312    * @param keyCode the code of the key to release.
313    * @return this fixture.
314    * @throws IllegalArgumentException if any of the given code is not a valid key code.
315    * @see java.awt.event.KeyEvent
316    */
 
317  1 toggle public JOptionPaneFixture releaseKey(int keyCode) {
318  1 driver.releaseKey(target, keyCode);
319  1 return this;
320    }
321   
322    /**
323    * Asserts that the title of this fixture's <code>{@link JOptionPane}</code> matches the given value.
324    * @param title the title to match. It can be a regular expression.
325    * @return this fixture.
326    * @throws AssertionError if this fixture's </code>JOptionPaneFixture</code> does not have the given title.
327    */
 
328  1 toggle public JOptionPaneFixture requireTitle(String title) {
329  1 driver.requireTitle(target, title);
330  1 return this;
331    }
332   
333    /**
334    * Asserts that the title of this fixture's <code>{@link JOptionPane}</code> matches the given regular expression
335    * pattern.
336    * @param pattern the regular expression pattern to match.
337    * @return this fixture.
338    * @throws NullPointerException if the given regular expression is <code>null</code>.
339    * @throws AssertionError if this fixture's </code>JOptionPaneFixture</code> does not have the given title.
340    * @since 1.2
341    */
 
342  1 toggle public JOptionPaneFixture requireTitle(Pattern pattern) {
343  1 driver.requireTitle(target, pattern);
344  1 return this;
345    }
346   
347    /**
348    * Asserts that the message of this fixture's <code>{@link JOptionPane}</code> matches the given value.
349    * @param message the message to verify. If it is a <code>String</code>, it can be specified as a regular expression.
350    * @return this fixture.
351    * @throws AssertionError if the message in this fixture's </code>JOptionPaneFixture</code> is not equal to or does
352    * not match the given message.
353    */
 
354  4 toggle public JOptionPaneFixture requireMessage(Object message) {
355  4 driver.requireMessage(target, message);
356  4 return this;
357    }
358   
359    /**
360    * Asserts that the message of this fixture's <code>{@link JOptionPane}</code> matches the given regular expression
361    * pattern. If the message in the {@code JOptionPane} is not a <code>String</code>, this method will use the
362    * <code>toString</code> representation of such message.
363    * @param pattern the regular expression to match.
364    * @return this fixture.
365    * @throws NullPointerException if the given regular expression pattern is <code>null</code>.
366    * @throws AssertionError if the message in this fixture's </code>JOptionPaneFixture</code> does not match the given
367    * regular expression pattern.
368    * @since 1.2
369    */
 
370  1 toggle public JOptionPaneFixture requireMessage(Pattern pattern) {
371  1 driver.requireMessage(target, pattern);
372  1 return this;
373    }
374   
375    /**
376    * Asserts that this fixture's <code>{@link JOptionPane}</code> has the given options.
377    * @param options the options to verify.
378    * @return this fixture.
379    * @throws AssertionError if this fixture's </code>JOptionPaneFixture</code> does not have the given options.
380    */
 
381  1 toggle public JOptionPaneFixture requireOptions(Object[] options) {
382  1 driver.requireOptions(target, options);
383  1 return this;
384    }
385   
386    /**
387    * Asserts that this fixture's <code>{@link JOptionPane}</code> has input focus.
388    * @return this fixture.
389    * @throws AssertionError if this fixture's {@code JOptionPane} does not have input focus.
390    */
 
391  1 toggle public JOptionPaneFixture requireFocused() {
392  1 driver.requireFocused(target);
393  1 return this;
394    }
395   
396    /**
397    * Asserts that this fixture's <code>{@link JOptionPane}</code> is enabled.
398    * @return this fixture.
399    * @throws AssertionError if this fixture's {@code JOptionPane} is disabled.
400    */
 
401  1 toggle public JOptionPaneFixture requireEnabled() {
402  1 driver.requireEnabled(target);
403  1 return this;
404    }
405   
406    /**
407    * Asserts that this fixture's <code>{@link JOptionPane}</code> is enabled.
408    * @param timeout the time this fixture will wait for the component to be enabled.
409    * @return this fixture.
410    * @throws org.fest.swing.exception.WaitTimedOutError if this fixture's {@code JOptionPane} is never enabled.
411    */
 
412  1 toggle public JOptionPaneFixture requireEnabled(Timeout timeout) {
413  1 driver.requireEnabled(target, timeout);
414  1 return this;
415    }
416   
417    /**
418    * Asserts that this fixture's <code>{@link JOptionPane}</code> is disabled.
419    * @return this fixture.
420    * @throws AssertionError if this fixture's {@code JOptionPane} is enabled.
421    */
 
422  1 toggle public JOptionPaneFixture requireDisabled() {
423  1 driver.requireDisabled(target);
424  1 return this;
425    }
426   
427    /**
428    * Asserts that this fixture's <code>{@link JOptionPane}</code> is visible.
429    * @return this fixture.
430    * @throws AssertionError if this fixture's {@code JOptionPane} is not visible.
431    */
 
432  1 toggle public JOptionPaneFixture requireVisible() {
433  1 driver.requireVisible(target);
434  1 return this;
435    }
436   
437    /**
438    * Asserts that this fixture's <code>{@link JOptionPane}</code> is not visible.
439    * @return this fixture.
440    * @throws AssertionError if this fixture's {@code JOptionPane} is visible.
441    */
 
442  1 toggle public JOptionPaneFixture requireNotVisible() {
443  1 driver.requireNotVisible(target);
444  1 return this;
445    }
446    }