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
22   206   18   1.47
4   85   0.82   15
15     1.2  
1    
 
  JProgressBarDriver       Line # 52 22 0% 18 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Dec 1, 2009
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5    * 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 is distributed on
10    * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11    * specific language governing permissions and limitations under the License.
12    *
13    * Copyright @2009-2010 the original author or authors.
14    */
15    package org.fest.swing.driver;
16   
17    import static java.util.concurrent.TimeUnit.SECONDS;
18    import static org.fest.assertions.Assertions.assertThat;
19    import static org.fest.swing.driver.JProgressBarIndeterminateQuery.isIndeterminate;
20    import static org.fest.swing.driver.JProgressBarMinimumAndMaximumQuery.minimumAndMaximumOf;
21    import static org.fest.swing.driver.JProgressBarStringQuery.stringOf;
22    import static org.fest.swing.driver.JProgressBarValueQuery.valueOf;
23    import static org.fest.swing.driver.JProgressBarWaitUntilIsDeterminate.waitUntilValueIsDeterminate;
24    import static org.fest.swing.driver.JProgressBarWaitUntilValueIsEqualToExpectedTask.waitUntilValueIsEqualToExpected;
25    import static org.fest.swing.driver.TextAssert.verifyThat;
26    import static org.fest.swing.timing.Timeout.timeout;
27    import static org.fest.util.Strings.concat;
28   
29    import java.util.regex.Pattern;
30   
31    import javax.swing.JProgressBar;
32   
33    import org.fest.swing.annotation.RunsInEDT;
34    import org.fest.swing.core.Robot;
35    import org.fest.swing.exception.WaitTimedOutError;
36    import org.fest.swing.timing.Timeout;
37    import org.fest.swing.util.Pair;
38   
39    /**
40    * Understands functional testing of <code>{@link JProgressBar}</code>s:
41    * <ul>
42    * <li>state verification</li>
43    * <li>property value query</li>
44    * </ul>
45    * This class is intended for internal use only. Please use the classes in the package
46    * <code>{@link org.fest.swing.fixture}</code> in your tests.
47    *
48    * @author Alex Ruiz
49    *
50    * @since 1.2
51    */
 
52    public class JProgressBarDriver extends JComponentDriver implements TextDisplayDriver<JProgressBar> {
53   
54    private static final Timeout DEFAULT_TIMEOUT = timeout(30, SECONDS);
55    private static final String TEXT_PROPERTY = "string";
56   
57    /**
58    * Creates a new </code>{@link JProgressBarDriver}</code>.
59    * @param robot the robot to use to simulate user input.
60    */
 
61  49 toggle public JProgressBarDriver(Robot robot) {
62  49 super(robot);
63    }
64   
65    /**
66    * Asserts that the text of the <code>{@link JProgressBar}</code> is equal to the specified <code>String</code>.
67    * @param progressBar the target <code>JProgressBar</code>.
68    * @param expected the text to match.
69    * @throws AssertionError if the text of the <code>JProgressBar</code> is not equal to the given one.
70    * @see JProgressBar#getString()
71    */
 
72  3 toggle @RunsInEDT
73    public void requireText(JProgressBar progressBar, String expected) {
74  3 verifyThat(stringOf(progressBar)).as(propertyName(progressBar, TEXT_PROPERTY)).isEqualOrMatches(expected);
75    }
76   
77    /**
78    * Asserts that the text of the <code>{@link JProgressBar}</code> matches the given regular expression pattern.
79    * @param progressBar the target <code>JProgressBar</code>.
80    * @param pattern the regular expression pattern to match.
81    * @throws AssertionError if the text of the <code>JProgressBar</code> does not match the given regular expression pattern.
82    * @throws NullPointerException if the given regular expression pattern is <code>null</code>.
83    * @see JProgressBar#getString()
84    */
 
85  2 toggle @RunsInEDT
86    public void requireText(JProgressBar progressBar, Pattern pattern) {
87  2 verifyThat(stringOf(progressBar)).as(propertyName(progressBar, TEXT_PROPERTY)).matches(pattern);
88    }
89   
90    /**
91    * Verifies that the value of the given <code>{@link JProgressBar}</code> is equal to the given one.
92    * @param progressBar the target <code>JProgressBar</code>.
93    * @param value the expected value.
94    * @throws AssertionError if the value of the <code>JProgressBar</code> is not equal to the given one.
95    */
 
96  2 toggle @RunsInEDT
97    public void requireValue(JProgressBar progressBar, int value) {
98  2 assertThat(valueOf(progressBar)).as(propertyName(progressBar, "value")).isEqualTo(value);
99    }
100   
101    /**
102    * Verifies that the given <code>{@link JProgressBar}</code> is in indeterminate mode.
103    * @param progressBar the target <code>JProgressBar</code>.
104    * @throws AssertionError if the given <code>JProgressBar</code> is not in indeterminate mode.
105    */
 
106  2 toggle @RunsInEDT
107    public void requireIndeterminate(JProgressBar progressBar) {
108  2 requireIndeterminate(progressBar, true);
109    }
110   
111    /**
112    * Verifies that the given <code>{@link JProgressBar}</code> is in determinate mode.
113    * @param progressBar the target <code>JProgressBar</code>.
114    * @throws AssertionError if the given <code>JProgressBar</code> is not in determinate mode.
115    */
 
116  2 toggle @RunsInEDT
117    public void requireDeterminate(JProgressBar progressBar) {
118  2 requireIndeterminate(progressBar, false);
119    }
120   
 
121  4 toggle @RunsInEDT
122    private void requireIndeterminate(JProgressBar progressBar, boolean indeterminate) {
123  4 assertThat(isIndeterminate(progressBar)).as(propertyName(progressBar, "indeterminate")).isEqualTo(indeterminate);
124    }
125   
126    /**
127    * Waits until the value of the given <code>{@link JProgressBar}</code> is equal to the given value.
128    * @param progressBar the target <code>JProgressBar</code>.
129    * @param value the expected value.
130    * @throws IllegalArgumentException if the given value is less than the <code>JProgressBar</code>'s minimum value.
131    * @throws IllegalArgumentException if the given value is greater than the <code>JProgressBar</code>'s maximum value.
132    * @throws WaitTimedOutError if the value of the <code>JProgressBar</code> does not reach the expected value within
133    * 30 seconds.
134    */
 
135  4 toggle @RunsInEDT
136    public void waitUntilValueIs(JProgressBar progressBar, int value) {
137  4 waitUntilValueIs(progressBar, value, DEFAULT_TIMEOUT);
138    }
139   
140    /**
141    * Waits until the value of the given <code>{@link JProgressBar}</code> is equal to the given value.
142    * @param progressBar the target <code>JProgressBar</code>.
143    * @param value the expected value.
144    * @param timeout the amount of time to wait.
145    * @throws IllegalArgumentException if the given value is less than the <code>JProgressBar</code>'s minimum value.
146    * @throws IllegalArgumentException if the given value is greater than the <code>JProgressBar</code>'s maximum value.
147    * @throws NullPointerException if the given timeout is <code>null</code>.
148    * @throws WaitTimedOutError if the value of the <code>JProgressBar</code> does not reach the expected value within
149    * the specified timeout.
150    */
 
151  9 toggle @RunsInEDT
152    public void waitUntilValueIs(JProgressBar progressBar, int value, Timeout timeout) {
153  9 assertIsInBetweenMinAndMax(progressBar, value);
154  5 validateIsNotNull(timeout);
155  4 waitUntilValueIsEqualToExpected(progressBar, value, timeout);
156    }
157   
 
158  9 toggle @RunsInEDT
159    private void assertIsInBetweenMinAndMax(JProgressBar progressBar, int value) {
160  9 Pair<Integer, Integer> minAndMax = minimumAndMaximumOf(progressBar);
161  9 assertIsInBetweenMinAndMax(value, minAndMax.i, minAndMax.ii);
162    }
163   
 
164  9 toggle private void assertIsInBetweenMinAndMax(int value, int min, int max) {
165  5 if (value >= min && value <= max) return;
166  4 throw new IllegalArgumentException(concat("Value <", value, "> should be between <[", min, ", ", max, "]>"));
167    }
168   
169    /**
170    * Waits until the value of the given <code>{@link JProgressBar}</code> is in determinate mode.
171    * @param progressBar the target <code>JProgressBar</code>.
172    * @throws WaitTimedOutError if the <code>JProgressBar</code> does not reach determinate mode within 30 seconds.
173    */
 
174  2 toggle @RunsInEDT
175    public void waitUntilIsDeterminate(JProgressBar progressBar) {
176  2 waitUntilIsDeterminate(progressBar, DEFAULT_TIMEOUT);
177    }
178   
179    /**
180    * Waits until the value of the given <code>{@link JProgressBar}</code> is in determinate mode.
181    * @param progressBar the target <code>JProgressBar</code>.
182    * @param timeout the amount of time to wait.
183    * @throws NullPointerException if the given timeout is <code>null</code>.
184    * @throws WaitTimedOutError if the <code>JProgressBar</code> does not reach determinate mode within the specified
185    * timeout.
186    */
 
187  5 toggle @RunsInEDT
188    public void waitUntilIsDeterminate(JProgressBar progressBar, Timeout timeout) {
189  5 validateIsNotNull(timeout);
190  4 waitUntilValueIsDeterminate(progressBar, timeout);
191    }
192   
 
193  10 toggle private void validateIsNotNull(Timeout timeout) {
194  2 if (timeout == null) throw new NullPointerException("Timeout should not be null");
195    }
196   
197    /**
198    * Returns the text of the given <code>{@link JProgressBar}</code>.
199    * @param progressBar the target <code>JProgressBar</code>.
200    * @return the text of the given <code>{@link JProgressBar}</code>.
201    */
 
202  1 toggle @RunsInEDT
203    public String textOf(JProgressBar progressBar) {
204  1 return stringOf(progressBar);
205    }
206    }