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
41   311   22   1.86
0   97   0.54   22
22     1  
1    
 
  JPopupMenuFixture       Line # 37 41 0% 22 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Sep 5, 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 javax.swing.JMenuItem;
19    import javax.swing.JPopupMenu;
20   
21    import org.fest.swing.core.*;
22    import org.fest.swing.driver.JPopupMenuDriver;
23    import org.fest.swing.exception.ComponentLookupException;
24    import org.fest.swing.exception.WaitTimedOutError;
25    import org.fest.swing.timing.Timeout;
26   
27    /**
28    * Understands functional testing of <code>{@link JPopupMenu}</code>s:
29    * <ul>
30    * <li>user input simulation</li>
31    * <li>state verification</li>
32    * <li>property value query</li>
33    * </ul>
34    *
35    * @author Yvonne Wang
36    */
 
37    public class JPopupMenuFixture extends ComponentFixture<JPopupMenu> implements CommonComponentFixture {
38   
39    private JPopupMenuDriver driver;
40    private final JMenuItemFinder menuItemFinder;
41   
42    /**
43    * Creates a new <code>{@link JPopupMenuFixture}</code>.
44    * @param robot performs simulation of user events on the given <code>JPopupMenu</code>.
45    * @param target the <code>JPopupMenu</code> to be managed by this fixture.
46    * @throws NullPointerException if <code>robot</code> is <code>null</code>.
47    * @throws NullPointerException if <code>target</code> is <code>null</code>.
48    */
 
49  74 toggle public JPopupMenuFixture(Robot robot, JPopupMenu target) {
50  74 super(robot, target);
51  74 menuItemFinder = new JMenuItemFinder(robot, target);
52  74 driver(new JPopupMenuDriver(robot));
53    }
54   
55    /**
56    * Sets the <code>{@link JPopupMenuDriver}</code> to be used by this fixture.
57    * @param newDriver the new <code>JPopupMenuDriver</code>.
58    * @throws NullPointerException if the given driver is <code>null</code>.
59    */
 
60  94 toggle protected final void driver(JPopupMenuDriver newDriver) {
61  94 validateNotNull(newDriver);
62  93 driver = newDriver;
63    }
64   
65    /**
66    * Finds a <code>{@link JMenuItem}</code>, contained in this fixture's <code>{@link JPopupMenu}</code>,
67    * which name matches the specified one.
68    * @param name the name to match.
69    * @return a fixture that manages the <code>JMenuItem</code> found.
70    * @throws ComponentLookupException if a <code>JMenuItem</code> having a matching name could not be found.
71    * @throws ComponentLookupException if more than one <code>JMenuItem</code> having a matching name is found.
72    */
 
73  1 toggle public JMenuItemFixture menuItem(String name) {
74  1 return new JMenuItemFixture(robot, driver.menuItem(target, name));
75    }
76   
77    /**
78    * Finds a <code>{@link JMenuItem}</code>, contained in this fixture's <code>{@link JPopupMenu}</code>,
79    * that matches the specified search criteria.
80    * @param matcher contains the search criteria for finding a <code>JMenuItem</code>.
81    * @return a fixture that manages the <code>JMenuItem</code> found.
82    * @throws ComponentLookupException if a <code>JMenuItem</code> that matches the given search criteria could not be
83    * found.
84    * @throws ComponentLookupException if more than one <code>JMenuItem</code> that matches the given search criteria is
85    * found.
86    */
 
87  1 toggle public JMenuItemFixture menuItem(GenericTypeMatcher<? extends JMenuItem> matcher) {
88  1 return new JMenuItemFixture(robot, driver.menuItem(target, matcher));
89    }
90   
91    /**
92    * Finds a <code>{@link JMenuItem}</code> in this fixture's <code>{@link JPopupMenu}</code>, which path matches
93    * the given one.
94    * <p>
95    * For example, if we are looking for the menu with text "New" contained under the menu with text "File", we can
96    * simply call
97    *
98    * <pre>
99    * JPopupMenuFixture popupMenu = tree.showPopupMenu();
100    * JMenuItemFixture menuItem = popupMenu.<strong>menuItemWithPath(&quot;File&quot;, &quot;Menu&quot;)</strong>;
101    * </pre>
102    *
103    * </p>
104    * @param path the path of the menu to find.
105    * @return a fixture that manages the <code>JMenuItem</code> found.
106    * @throws ComponentLookupException if a <code>JMenuItem</code> under the given path could not be found.
107    * @throws AssertionError if the <code>Component</code> found under the given path is not a <code>JMenuItem</code>.
108    */
 
109  2 toggle public JMenuItemFixture menuItemWithPath(String... path) {
110  2 return new JMenuItemFixture(robot, menuItemFinder.menuItemWithPath(path));
111    }
112   
113    /**
114    * Returns the contents of this fixture's <code>{@link JPopupMenu}</code>.
115    * @return a <code>String</code> array representing the contents of this fixture's <code>JPopupMenu</code>.
116    */
 
117  1 toggle public String[] menuLabels() {
118  1 return driver.menuLabelsOf(target);
119    }
120   
121    /**
122    * Simulates a user clicking this fixture's <code>{@link JPopupMenu}</code>.
123    * @return this fixture.
124    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is disabled.
125    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is not showing on the screen.
126    */
 
127  1 toggle public JPopupMenuFixture click() {
128  1 driver.click(target);
129  1 return this;
130    }
131   
132    /**
133    * Simulates a user clicking this fixture's <code>{@link JPopupMenu}</code>.
134    * @param button the button to click.
135    * @return this fixture.
136    * @throws NullPointerException if the given <code>MouseButton</code> is <code>null</code>.
137    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is disabled.
138    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is not showing on the screen.
139    */
 
140  1 toggle public JPopupMenuFixture click(MouseButton button) {
141  1 driver.click(target, button);
142  1 return this;
143    }
144   
145    /**
146    * Simulates a user clicking this fixture's <code>{@link JPopupMenu}</code>.
147    * @param mouseClickInfo specifies the button to click and the times the button should be clicked.
148    * @return this fixture.
149    * @throws NullPointerException if the given <code>MouseClickInfo</code> is <code>null</code>.
150    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is disabled.
151    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is not showing on the screen.
152    */
 
153  1 toggle public JPopupMenuFixture click(MouseClickInfo mouseClickInfo) {
154  1 driver.click(target, mouseClickInfo);
155  1 return this;
156    }
157   
158    /**
159    * Simulates a user right-clicking this fixture's <code>{@link JPopupMenu}</code>.
160    * @return this fixture.
161    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is disabled.
162    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is not showing on the screen.
163    */
 
164  1 toggle public JPopupMenuFixture rightClick() {
165  1 driver.rightClick(target);
166  1 return this;
167    }
168   
169    /**
170    * Simulates a user double-clicking this fixture's <code>{@link JPopupMenu}</code>.
171    * @return this fixture.
172    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is disabled.
173    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is not showing on the screen.
174    */
 
175  1 toggle public JPopupMenuFixture doubleClick() {
176  1 driver.doubleClick(target);
177  1 return this;
178    }
179   
180    /**
181    * Gives input focus to this fixture's <code>{@link JPopupMenu}</code>.
182    * @return this fixture.
183    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is disabled.
184    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is not showing on the screen.
185    */
 
186  1 toggle public JPopupMenuFixture focus() {
187  1 driver.focus(target);
188  1 return this;
189    }
190   
191    /**
192    * Simulates a user pressing given key with the given modifiers on this fixture's <code>{@link JPopupMenu}</code>.
193    * Modifiers is a mask from the available <code>{@link java.awt.event.InputEvent}</code> masks.
194    * @param keyPressInfo specifies the key and modifiers to press.
195    * @return this fixture.
196    * @throws NullPointerException if the given <code>KeyPressInfo</code> is <code>null</code>.
197    * @throws IllegalArgumentException if the given code is not a valid key code.
198    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is disabled.
199    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is not showing on the screen.
200    * @see KeyPressInfo
201    */
 
202  1 toggle public JPopupMenuFixture pressAndReleaseKey(KeyPressInfo keyPressInfo) {
203  1 driver.pressAndReleaseKey(target, keyPressInfo);
204  1 return this;
205    }
206   
207    /**
208    * Simulates a user pressing and releasing the given keys on this fixture's <code>{@link JPopupMenu}</code>. This
209    * method does not affect the current focus.
210    * @param keyCodes one or more codes of the keys to press.
211    * @return this fixture.
212    * @throws NullPointerException if the given array of codes is <code>null</code>.
213    * @throws IllegalArgumentException if any of the given code is not a valid key code.
214    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is disabled.
215    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is not showing on the screen.
216    * @see java.awt.event.KeyEvent
217    */
 
218  1 toggle public JPopupMenuFixture pressAndReleaseKeys(int... keyCodes) {
219  1 driver.pressAndReleaseKeys(target, keyCodes);
220  1 return this;
221    }
222   
223    /**
224    * Simulates a user pressing the given key on this fixture's <code>{@link JPopupMenu}</code>.
225    * @param keyCode the code of the key to press.
226    * @return this fixture.
227    * @throws IllegalArgumentException if any of the given code is not a valid key code.
228    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is disabled.
229    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is not showing on the screen.
230    * @see java.awt.event.KeyEvent
231    */
 
232  1 toggle public JPopupMenuFixture pressKey(int keyCode) {
233  1 driver.pressKey(target, keyCode);
234  1 return this;
235    }
236   
237    /**
238    * Simulates a user releasing the given key on this fixture's <code>{@link JPopupMenu}</code>.
239    * @param keyCode the code of the key to release.
240    * @return this fixture.
241    * @throws IllegalArgumentException if any of the given code is not a valid key code.
242    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is disabled.
243    * @throws IllegalStateException if this fixture's <code>JPopupMenu</code> is not showing on the screen.
244    * @see java.awt.event.KeyEvent
245    */
 
246  1 toggle public JPopupMenuFixture releaseKey(int keyCode) {
247  1 driver.releaseKey(target, keyCode);
248  1 return this;
249    }
250   
251    /**
252    * Asserts that this fixture's <code>{@link JPopupMenu}</code> has input focus.
253    * @return this fixture.
254    * @throws AssertionError if this fixture's <code>JPopupMenu</code> does not have input focus.
255    */
 
256  1 toggle public JPopupMenuFixture requireFocused() {
257  1 driver.requireFocused(target);
258  1 return this;
259    }
260   
261    /**
262    * Asserts that this fixture's <code>{@link JPopupMenu}</code> is enabled.
263    * @return this fixture.
264    * @throws AssertionError if this fixture's <code>JPopupMenu</code> is disabled.
265    */
 
266  1 toggle public JPopupMenuFixture requireEnabled() {
267  1 driver.requireEnabled(target);
268  1 return this;
269    }
270   
271    /**
272    * Asserts that this fixture's <code>{@link JPopupMenu}</code> is enabled.
273    * @param timeout the time this fixture will wait for the component to be enabled.
274    * @return this fixture.
275    * @throws WaitTimedOutError if this fixture's <code>JPopupMenu</code> is never enabled.
276    */
 
277  1 toggle public JPopupMenuFixture requireEnabled(Timeout timeout) {
278  1 driver.requireEnabled(target, timeout);
279  1 return this;
280    }
281   
282    /**
283    * Asserts that this fixture's <code>{@link JPopupMenu}</code> is disabled.
284    * @return this fixture.
285    * @throws AssertionError if this fixture's <code>JPopupMenu</code> is enabled.
286    */
 
287  1 toggle public JPopupMenuFixture requireDisabled() {
288  1 driver.requireDisabled(target);
289  1 return this;
290    }
291   
292    /**
293    * Asserts that this fixture's <code>{@link JPopupMenu}</code> is visible.
294    * @return this fixture.
295    * @throws AssertionError if this fixture's <code>JPopupMenu</code> is not visible.
296    */
 
297  1 toggle public JPopupMenuFixture requireVisible() {
298  1 driver.requireVisible(target);
299  1 return this;
300    }
301   
302    /**
303    * Asserts that this fixture's <code>{@link JPopupMenu}</code> is not visible.
304    * @return this fixture.
305    * @throws AssertionError if this fixture's <code>JPopupMenu</code> is visible.
306    */
 
307  1 toggle public JPopupMenuFixture requireNotVisible() {
308  1 driver.requireNotVisible(target);
309  1 return this;
310    }
311    }