| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 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 |
|
@link |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
@link |
| 47 |
|
|
| 48 |
|
@author |
| 49 |
|
|
| 50 |
|
@since |
| 51 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (41) |
Complexity: 18 |
Complexity Density: 0.82 |
|
| 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 |
|
@link |
| 59 |
|
@param |
| 60 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 61 |
49
|
public JProgressBarDriver(Robot robot) {... |
| 62 |
49
|
super(robot); |
| 63 |
|
} |
| 64 |
|
|
| 65 |
|
|
| 66 |
|
@link |
| 67 |
|
@param |
| 68 |
|
@param |
| 69 |
|
@throws |
| 70 |
|
@see |
| 71 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 72 |
3
|
@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 |
|
@link |
| 79 |
|
@param |
| 80 |
|
@param |
| 81 |
|
@throws |
| 82 |
|
@throws |
| 83 |
|
@see |
| 84 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 85 |
2
|
@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 |
|
@link |
| 92 |
|
@param |
| 93 |
|
@param |
| 94 |
|
@throws |
| 95 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 96 |
2
|
@RunsInEDT... |
| 97 |
|
public void requireValue(JProgressBar progressBar, int value) { |
| 98 |
2
|
assertThat(valueOf(progressBar)).as(propertyName(progressBar, "value")).isEqualTo(value); |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
|
| 102 |
|
@link |
| 103 |
|
@param |
| 104 |
|
@throws |
| 105 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 106 |
2
|
@RunsInEDT... |
| 107 |
|
public void requireIndeterminate(JProgressBar progressBar) { |
| 108 |
2
|
requireIndeterminate(progressBar, true); |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
|
| 112 |
|
@link |
| 113 |
|
@param |
| 114 |
|
@throws |
| 115 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 116 |
2
|
@RunsInEDT... |
| 117 |
|
public void requireDeterminate(JProgressBar progressBar) { |
| 118 |
2
|
requireIndeterminate(progressBar, false); |
| 119 |
|
} |
| 120 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 121 |
4
|
@RunsInEDT... |
| 122 |
|
private void requireIndeterminate(JProgressBar progressBar, boolean indeterminate) { |
| 123 |
4
|
assertThat(isIndeterminate(progressBar)).as(propertyName(progressBar, "indeterminate")).isEqualTo(indeterminate); |
| 124 |
|
} |
| 125 |
|
|
| 126 |
|
|
| 127 |
|
@link |
| 128 |
|
@param |
| 129 |
|
@param |
| 130 |
|
@throws |
| 131 |
|
@throws |
| 132 |
|
@throws |
| 133 |
|
|
| 134 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 135 |
4
|
@RunsInEDT... |
| 136 |
|
public void waitUntilValueIs(JProgressBar progressBar, int value) { |
| 137 |
4
|
waitUntilValueIs(progressBar, value, DEFAULT_TIMEOUT); |
| 138 |
|
} |
| 139 |
|
|
| 140 |
|
|
| 141 |
|
@link |
| 142 |
|
@param |
| 143 |
|
@param |
| 144 |
|
@param |
| 145 |
|
@throws |
| 146 |
|
@throws |
| 147 |
|
@throws |
| 148 |
|
@throws |
| 149 |
|
|
| 150 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 151 |
9
|
@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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 158 |
9
|
@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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
| 164 |
9
|
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 |
|
@link |
| 171 |
|
@param |
| 172 |
|
@throws |
| 173 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 174 |
2
|
@RunsInEDT... |
| 175 |
|
public void waitUntilIsDeterminate(JProgressBar progressBar) { |
| 176 |
2
|
waitUntilIsDeterminate(progressBar, DEFAULT_TIMEOUT); |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
|
| 180 |
|
@link |
| 181 |
|
@param |
| 182 |
|
@param |
| 183 |
|
@throws |
| 184 |
|
@throws |
| 185 |
|
|
| 186 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 187 |
5
|
@RunsInEDT... |
| 188 |
|
public void waitUntilIsDeterminate(JProgressBar progressBar, Timeout timeout) { |
| 189 |
5
|
validateIsNotNull(timeout); |
| 190 |
4
|
waitUntilValueIsDeterminate(progressBar, timeout); |
| 191 |
|
} |
| 192 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 193 |
10
|
private void validateIsNotNull(Timeout timeout) {... |
| 194 |
2
|
if (timeout == null) throw new NullPointerException("Timeout should not be null"); |
| 195 |
|
} |
| 196 |
|
|
| 197 |
|
|
| 198 |
|
@link |
| 199 |
|
@param |
| 200 |
|
@return@link |
| 201 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 202 |
1
|
@RunsInEDT... |
| 203 |
|
public String textOf(JProgressBar progressBar) { |
| 204 |
1
|
return stringOf(progressBar); |
| 205 |
|
} |
| 206 |
|
} |