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
9   146   7   1.29
0   32   0.78   7
7     1  
1    
11.1% of code in this file is excluded from these metrics.
 
  JOptionPaneFinder       Line # 74 9 11.1% 7 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Oct 29, 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.finder;
17   
18    import java.awt.Component;
19    import java.util.concurrent.TimeUnit;
20   
21    import javax.swing.JOptionPane;
22   
23    import org.fest.swing.core.GenericTypeMatcher;
24    import org.fest.swing.core.Robot;
25    import org.fest.swing.fixture.JOptionPaneFixture;
26   
27    /**
28    * Understands a finder for <code>{@link JOptionPane}</code>s. Lookups are performed till a file chooser is found, or
29    * until the given time to perform the lookup is over. The default lookup time is 5 seconds.
30    * </p>
31    * <p>
32    * This example illustrates finding a <code>{@link JOptionPane}</code> by name, using the default lookup time (5
33    * seconds):
34    *
35    * <pre>
36    * JOptionPaneFixture optionPane = JOptionPaneFinder.findOptionPane().using(robot);
37    * </pre>
38    *
39    * </p>
40    * <p>
41    * Where <code>robot</code> is an instance of <code>{@link org.fest.swing.core.Robot}</code>.
42    * </p>
43    * <p>
44    * This example shows how to find a <code>{@link JOptionPane}</code> by type using a lookup time of 10 seconds:
45    *
46    * <pre>
47    * JOptionPaneFixture optionPane = JOptionPaneFinder.findOptionPane().withTimeout(10000).using(robot);
48    * </pre>
49    *
50    * We can also specify the time unit:
51    *
52    * <pre>
53    * JOptionPaneFixture optionPane = JOptionPaneFinder.findOptionPane().withTimeout(10, {@link TimeUnit#SECONDS SECONDS}).using(robot);
54    * </pre>
55    *
56    * </p>
57    * <p>
58    * This example shows how to find a <code>{@link JOptionPane}</code> using a <code>{@link GenericTypeMatcher}</code>:
59    *
60    * <pre>
61    * GenericTypeMatcher&lt;JOptionPane&gt; matcher = new GenericTypeMatcher&lt;JOptionPane&gt;() {
62    * protected boolean isMatching(JOptionPane optionPane) {
63    * return &quot;A message&quot;.equals(optionPane.getMessage());
64    * }
65    * };
66    * JOptionPaneFixture optionPane = JOptionPaneFinder.findOptionPane(matcher).using(robot);
67    * </pre>
68    *
69    * </p>
70    *
71    * @author Yvonne Wang
72    * @author Alex Ruiz
73    */
 
74    public class JOptionPaneFinder extends ComponentFinderTemplate<JOptionPane> {
75   
76    /**
77    * Creates a new </code>{@link JOptionPaneFinder}</code>. This finder looks up a <code>{@link JOptionPane}</code> by
78    * type.
79    */
 
80    toggle protected JOptionPaneFinder() {
81    super(JOptionPane.class);
82    }
83   
84    /**
85    * Creates a new </code>{@link JOptionPaneFinder}</code>.
86    * @param matcher specifies the search criteria to use when looking up a {@code JOptionPane}.
87    */
 
88  6 toggle protected JOptionPaneFinder(GenericTypeMatcher<? extends JOptionPane> matcher) {
89  6 super(matcher);
90    }
91   
92    /**
93    * Creates a new <code>{@link JOptionPaneFinder}</code> capable of looking up a <code>{@link JOptionPane}</code>.
94    * @return the created finder.
95    */
 
96  9 toggle public static JOptionPaneFinder findOptionPane() {
97  9 return new JOptionPaneFinder();
98    }
99   
100    /**
101    * Creates a new <code>{@link JOptionPaneFinder}</code> capable of looking up a <code>{@link JOptionPane}</code>
102    * using the given matcher.
103    * @param matcher the given matcher.
104    * @return the created finder.
105    */
 
106  7 toggle public static JOptionPaneFinder findOptionPane(GenericTypeMatcher<? extends JOptionPane> matcher) {
107  7 return new JOptionPaneFinder(matcher);
108    }
109   
110    /**
111    * Finds a <code>{@link JOptionPane}</code> by name or type.
112    * @param robot contains the underlying finding to delegate the search to.
113    * @return a <code>JOptionPaneFixture</code> managing the found <code>JOptionPane</code>.
114    * @throws org.fest.swing.exception.WaitTimedOutError if a <code>JOptionPane</code> could not be found.
115    */
 
116  11 toggle public JOptionPaneFixture using(Robot robot) {
117  11 return new JOptionPaneFixture(robot, findComponentWith(robot));
118    }
119   
120    /**
121    * Sets the timeout for this finder. The window to search should be found within the given time period.
122    * @param timeout the number of milliseconds before stopping the search.
123    * @return this finder.
124    */
 
125  6 toggle @Override public JOptionPaneFinder withTimeout(long timeout) {
126  6 super.withTimeout(timeout);
127  4 return this;
128    }
129   
130    /**
131    * Sets the timeout for this finder. The window to search should be found within the given time period.
132    * @param timeout the period of time the search should be performed.
133    * @param unit the time unit for <code>timeout</code>.
134    * @return this finder.
135    */
 
136  4 toggle @Override public JOptionPaneFinder withTimeout(long timeout, TimeUnit unit) {
137  4 super.withTimeout(timeout, unit);
138  2 return this;
139    }
140   
141    /**
142    * Casts the given {@code Component} to <code>{@link JOptionPane}</code>.
143    * @return the given {@code Component}, casted to {@code JFileChooser}.
144    */
 
145  9 toggle protected JOptionPane cast(Component c) { return (JOptionPane) c; }
146    }