| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.fest.swing.finder; |
| 17 |
|
|
| 18 |
|
import static org.fest.swing.timing.Pause.pause; |
| 19 |
|
import static org.fest.util.Strings.concat; |
| 20 |
|
|
| 21 |
|
import java.awt.Component; |
| 22 |
|
import java.util.concurrent.TimeUnit; |
| 23 |
|
|
| 24 |
|
import org.fest.swing.core.*; |
| 25 |
|
import org.fest.swing.exception.WaitTimedOutError; |
| 26 |
|
import org.fest.swing.fixture.ComponentFixture; |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
@link |
| 30 |
|
@param |
| 31 |
|
|
| 32 |
|
@author |
| 33 |
|
@author |
| 34 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (30) |
Complexity: 10 |
Complexity Density: 0.59 |
|
| 35 |
|
public abstract class ComponentFinderTemplate<T extends Component> { |
| 36 |
|
|
| 37 |
|
static final long TIMEOUT = 5000; |
| 38 |
|
|
| 39 |
|
private long timeout = TIMEOUT; |
| 40 |
|
|
| 41 |
|
private final ComponentMatcher matcher; |
| 42 |
|
private final String searchDescription; |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
@link |
| 46 |
|
@param |
| 47 |
|
@param |
| 48 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 49 |
20
|
protected ComponentFinderTemplate(String componentName, Class<? extends T> componentType) {... |
| 50 |
20
|
this(new NameMatcher(componentName, componentType, true)); |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
@link |
| 55 |
|
@param |
| 56 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 57 |
29
|
protected ComponentFinderTemplate(GenericTypeMatcher<? extends T> matcher) {... |
| 58 |
29
|
this((ComponentMatcher)matcher); |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
|
| 62 |
|
@link |
| 63 |
|
@param |
| 64 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 65 |
29
|
protected ComponentFinderTemplate(Class<? extends T> componentType) {... |
| 66 |
29
|
this(new TypeMatcher(componentType, true)); |
| 67 |
|
} |
| 68 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 69 |
82
|
private ComponentFinderTemplate(ComponentMatcher matcher) {... |
| 70 |
4
|
if (matcher == null) throw new NullPointerException("The matcher should not be null"); |
| 71 |
78
|
this.matcher = matcher; |
| 72 |
78
|
searchDescription = concat("component to be found using matcher ", matcher); |
| 73 |
|
} |
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
@param |
| 78 |
|
@param |
| 79 |
|
@return |
| 80 |
|
@throws |
| 81 |
|
@throws |
| 82 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 83 |
22
|
protected ComponentFinderTemplate<T> withTimeout(long newTimeout, TimeUnit unit) {... |
| 84 |
11
|
if (unit == null) throw new NullPointerException("Time unit cannot be null"); |
| 85 |
11
|
return withTimeout(unit.toMillis(newTimeout)); |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
|
@param |
| 91 |
|
@return |
| 92 |
|
@throws |
| 93 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 94 |
34
|
protected ComponentFinderTemplate<T> withTimeout(long newTimeout) {... |
| 95 |
11
|
if (newTimeout < 0) throw new IllegalArgumentException("Timeout cannot be a negative number"); |
| 96 |
23
|
this.timeout = newTimeout; |
| 97 |
23
|
return this; |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
@param |
| 103 |
|
@return |
| 104 |
|
@throws |
| 105 |
|
|
| 106 |
|
public abstract ComponentFixture<T> using(Robot robot); |
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
@param |
| 111 |
|
@return |
| 112 |
|
@throws |
| 113 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 114 |
56
|
protected final T findComponentWith(Robot robot) {... |
| 115 |
56
|
ComponentFoundCondition condition = new ComponentFoundCondition(searchDescription, robot.finder(), matcher); |
| 116 |
56
|
pause(condition, timeout); |
| 117 |
44
|
return cast(condition.found()); |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
@param |
| 123 |
|
@return |
| 124 |
|
|
| 125 |
|
protected abstract T cast(Component c); |
| 126 |
|
} |