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