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
27   204   14   1.93
0   67   0.52   14
14     1  
1    
 
  JMenuItemFixture       Line # 37 27 0% 14 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 javax.swing.JMenuItem;
19   
20    import org.fest.swing.core.KeyPressInfo;
21    import org.fest.swing.core.Robot;
22    import org.fest.swing.driver.JMenuItemDriver;
23    import org.fest.swing.exception.ActionFailedException;
24    import org.fest.swing.exception.ComponentLookupException;
25    import org.fest.swing.timing.Timeout;
26   
27    /**
28    * Understands functional testing of <code>{@link JMenuItem}</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 Alex Ruiz
36    */
 
37    public class JMenuItemFixture extends ComponentFixture<JMenuItem> implements KeyboardInputSimulationFixture,
38    StateVerificationFixture {
39   
40    private JMenuItemDriver driver;
41   
42    /**
43    * Creates a new <code>{@link JMenuItemFixture}</code>.
44    * @param robot performs simulation of user events on a <code>JMenuItem</code>.
45    * @param menuItemName the name of the <code>JMenuItem</code> to find using the given <code>Robot</code>.
46    * @throws NullPointerException if <code>robot</code> is <code>null</code>.
47    * @throws ComponentLookupException if a matching <code>JMenuItem</code> could not be found.
48    * @throws ComponentLookupException if more than one matching <code>JMenuItem</code> is found.
49    */
 
50  1 toggle public JMenuItemFixture(Robot robot, String menuItemName) {
51  1 this(robot, robot.finder().findByName(menuItemName, JMenuItem.class, false));
52    }
53   
54    /**
55    * Creates a new <code>{@link JMenuItemFixture}</code>.
56    * @param robot performs simulation of user events on the given <code>JMenuItem</code>.
57    * @param target the <code>JMenuItem</code> to be managed by this fixture.
58    * @throws NullPointerException if <code>robot</code> is <code>null</code>.
59    * @throws NullPointerException if <code>target</code> is <code>null</code>.
60    */
 
61  24 toggle public JMenuItemFixture(Robot robot, JMenuItem target) {
62  24 super(robot, target);
63  24 driver(new JMenuItemDriver(robot));
64    }
65   
66    /**
67    * Sets the <code>{@link JMenuItemDriver}</code> to be used by this fixture.
68    * @param newDriver the new <code>JMenuItemDriver</code>.
69    * @throws NullPointerException if the given driver is <code>null</code>.
70    */
 
71  36 toggle protected final void driver(JMenuItemDriver newDriver) {
72  36 validateNotNull(newDriver);
73  35 driver = newDriver;
74    }
75   
76    /**
77    * Simulates a user selecting this fixture's <code>{@link JMenuItem}</code>.
78    * @return this fixture.
79    * @throws IllegalStateException if this fixture's <code>JMenuItem</code> is disabled.
80    * @throws IllegalStateException if this fixture's <code>JMenuItem</code> is not showing on the screen.
81    * @throws ActionFailedException if the menu has a pop-up and it fails to show up.
82    */
 
83  7 toggle public JMenuItemFixture click() {
84  7 driver.click(target);
85  7 return this;
86    }
87   
88    /**
89    * Gives input focus to this fixture's <code>{@link JMenuItem}</code>.
90    * @throws IllegalStateException if this fixture's <code>JMenuItem</code> is disabled.
91    * @throws IllegalStateException if this fixture's <code>JMenuItem</code> is not showing on the screen.
92    * @return this fixture.
93    */
 
94  1 toggle public JMenuItemFixture focus() {
95  1 driver.focus(target);
96  1 return this;
97    }
98   
99    /**
100    * Simulates a user pressing given key with the given modifiers on this fixture's <code>{@link JMenuItem}</code>.
101    * Modifiers is a mask from the available <code>{@link java.awt.event.InputEvent}</code> masks.
102    * @param keyPressInfo specifies the key and modifiers to press.
103    * @return this fixture.
104    * @throws NullPointerException if the given <code>KeyPressInfo</code> is <code>null</code>.
105    * @throws IllegalArgumentException if the given code is not a valid key code.
106    * @throws IllegalStateException if this fixture's <code>JMenuItem</code> is disabled.
107    * @throws IllegalStateException if this fixture's <code>JMenuItem</code> is not showing on the screen.
108    * @see KeyPressInfo
109    */
 
110  1 toggle public JMenuItemFixture pressAndReleaseKey(KeyPressInfo keyPressInfo) {
111  1 driver.pressAndReleaseKey(target, keyPressInfo);
112  1 return this;
113    }
114   
115    /**
116    * Simulates a user pressing and releasing the given keys on this fixture's <code>{@link JMenuItem}</code>.
117    * @param keyCodes one or more codes of the keys to press.
118    * @return this fixture.
119    * @throws IllegalStateException if this fixture's <code>JMenuItem</code> is disabled.
120    * @throws IllegalStateException if this fixture's <code>JMenuItem</code> is not showing on the screen.
121    * @see java.awt.event.KeyEvent
122    */
 
123  1 toggle public JMenuItemFixture pressAndReleaseKeys(int... keyCodes) {
124  1 driver.pressAndReleaseKeys(target, keyCodes);
125  1 return this;
126    }
127   
128    /**
129    * Simulates a user pressing the given key on this fixture's <code>{@link JMenuItem}</code>.
130    * @param keyCode the code of the key to press.
131    * @return this fixture.
132    * @throws IllegalStateException if this fixture's <code>JMenuItem</code> is disabled.
133    * @throws IllegalStateException if this fixture's <code>JMenuItem</code> is not showing on the screen.
134    * @see java.awt.event.KeyEvent
135    */
 
136  1 toggle public JMenuItemFixture pressKey(int keyCode) {
137  1 driver.pressKey(target, keyCode);
138  1 return this;
139    }
140   
141    /**
142    * Simulates a user releasing the given key on this fixture's <code>{@link JMenuItem}</code>.
143    * @param keyCode the code of the key to release.
144    * @return this fixture.
145    * @throws IllegalStateException if this fixture's <code>JMenuItem</code> is disabled.
146    * @throws IllegalStateException if this fixture's <code>JMenuItem</code> is not showing on the screen.
147    * @see java.awt.event.KeyEvent
148    */
 
149  1 toggle public JMenuItemFixture releaseKey(int keyCode) {
150  1 driver.releaseKey(target, keyCode);
151  1 return this;
152    }
153   
154    /**
155    * Asserts that this fixture's <code>{@link JMenuItem}</code> is enabled.
156    * @return this fixture.
157    * @throws AssertionError if this fixture's <code>JMenuItem</code> is disabled.
158    */
 
159  1 toggle public JMenuItemFixture requireEnabled() {
160  1 driver.requireEnabled(target);
161  1 return this;
162    }
163   
164    /**
165    * Asserts that this fixture's <code>{@link JMenuItem}</code> is enabled.
166    * @param timeout the time this fixture will wait for the component to be enabled.
167    * @return this fixture.
168    * @throws org.fest.swing.exception.WaitTimedOutError if this fixture's <code>JMenuItem</code> is never enabled.
169    */
 
170  1 toggle public JMenuItemFixture requireEnabled(Timeout timeout) {
171  1 driver.requireEnabled(target, timeout);
172  1 return this;
173    }
174   
175    /**
176    * Asserts that this fixture's <code>{@link JMenuItem}</code> is disabled.
177    * @return this fixture.
178    * @throws AssertionError if this fixture's <code>JMenuItem</code> is enabled.
179    */
 
180  1 toggle public JMenuItemFixture requireDisabled() {
181  1 driver.requireDisabled(target);
182  1 return this;
183    }
184   
185    /**
186    * Asserts that this fixture's <code>{@link JMenuItem}</code> is visible.
187    * @return this fixture.
188    * @throws AssertionError if this fixture's <code>JMenuItem</code> is not visible.
189    */
 
190  1 toggle public JMenuItemFixture requireVisible() {
191  1 driver.requireVisible(target);
192  1 return this;
193    }
194   
195    /**
196    * Asserts that this fixture's <code>{@link JMenuItem}</code> is not visible.
197    * @return this fixture.
198    * @throws AssertionError if this fixture's <code>JMenuItem</code> is visible.
199    */
 
200  1 toggle public JMenuItemFixture requireNotVisible() {
201  1 driver.requireNotVisible(target);
202  1 return this;
203    }
204    }