| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.fest.swing.driver; |
| 17 |
|
|
| 18 |
|
import static org.fest.assertions.Assertions.assertThat; |
| 19 |
|
import static org.fest.swing.driver.AbstractButtonSelectedQuery.isSelected; |
| 20 |
|
import static org.fest.swing.driver.ComponentStateValidator.validateIsEnabledAndShowing; |
| 21 |
|
import static org.fest.swing.driver.TextAssert.verifyThat; |
| 22 |
|
import static org.fest.swing.edt.GuiActionRunner.execute; |
| 23 |
|
|
| 24 |
|
import java.util.regex.Pattern; |
| 25 |
|
|
| 26 |
|
import javax.swing.AbstractButton; |
| 27 |
|
|
| 28 |
|
import org.fest.assertions.Description; |
| 29 |
|
import org.fest.swing.annotation.RunsInEDT; |
| 30 |
|
import org.fest.swing.core.Robot; |
| 31 |
|
import org.fest.swing.edt.GuiQuery; |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
@link |
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
@link |
| 42 |
|
|
| 43 |
|
@author |
| 44 |
|
@author |
| 45 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (33) |
Complexity: 14 |
Complexity Density: 0.82 |
|
| 46 |
|
public class AbstractButtonDriver extends JComponentDriver implements TextDisplayDriver<AbstractButton> { |
| 47 |
|
|
| 48 |
|
private static final String SELECTED_PROPERTY = "selected"; |
| 49 |
|
private static final String TEXT_PROPERTY = "text"; |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
@link |
| 53 |
|
@param |
| 54 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 55 |
222
|
public AbstractButtonDriver(Robot robot) {... |
| 56 |
222
|
super(robot); |
| 57 |
|
} |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
@param |
| 62 |
|
@param |
| 63 |
|
@throws |
| 64 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 65 |
4
|
@RunsInEDT... |
| 66 |
|
public void requireText(AbstractButton button, String expected) { |
| 67 |
4
|
verifyThat(textOf(button)).as(propertyName(button, TEXT_PROPERTY)).isEqualOrMatches(expected); |
| 68 |
|
} |
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
@param |
| 73 |
|
@param |
| 74 |
|
@throws |
| 75 |
|
@throws |
| 76 |
|
@since |
| 77 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 78 |
2
|
public void requireText(AbstractButton button, Pattern pattern) {... |
| 79 |
2
|
verifyThat(textOf(button)).as(propertyName(button, TEXT_PROPERTY)).matches(pattern); |
| 80 |
|
} |
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
@param |
| 85 |
|
@return |
| 86 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 87 |
7
|
@RunsInEDT... |
| 88 |
|
public String textOf(AbstractButton button) { |
| 89 |
7
|
return AbstractButtonTextQuery.textOf(button); |
| 90 |
|
} |
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
@param |
| 95 |
|
@throws |
| 96 |
|
@throws |
| 97 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 98 |
4
|
@RunsInEDT... |
| 99 |
|
public void select(AbstractButton button) { |
| 100 |
1
|
if (validateAndFindIsSelected(button)) return; |
| 101 |
1
|
robot.click(button); |
| 102 |
|
} |
| 103 |
|
|
| 104 |
|
|
| 105 |
|
|
| 106 |
|
@param |
| 107 |
|
@throws |
| 108 |
|
@throws |
| 109 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 110 |
4
|
@RunsInEDT... |
| 111 |
|
public void unselect(AbstractButton button) { |
| 112 |
1
|
if (!validateAndFindIsSelected(button)) return; |
| 113 |
1
|
robot.click(button); |
| 114 |
|
} |
| 115 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 116 |
8
|
@RunsInEDT... |
| 117 |
|
private static boolean validateAndFindIsSelected(final AbstractButton button) { |
| 118 |
8
|
return execute(new GuiQuery<Boolean>() { |
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 119 |
8
|
protected Boolean executeInEDT() {... |
| 120 |
8
|
validateIsEnabledAndShowing(button); |
| 121 |
4
|
return button.isSelected(); |
| 122 |
|
} |
| 123 |
|
}); |
| 124 |
|
} |
| 125 |
|
|
| 126 |
|
|
| 127 |
|
|
| 128 |
|
@param |
| 129 |
|
@throws |
| 130 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 131 |
2
|
@RunsInEDT... |
| 132 |
|
public void requireSelected(AbstractButton button) { |
| 133 |
2
|
assertThatButtonIsSelected(button, true); |
| 134 |
|
} |
| 135 |
|
|
| 136 |
|
|
| 137 |
|
|
| 138 |
|
@param |
| 139 |
|
@throws |
| 140 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 141 |
2
|
@RunsInEDT... |
| 142 |
|
public void requireNotSelected(AbstractButton button) { |
| 143 |
2
|
assertThatButtonIsSelected(button, false); |
| 144 |
|
} |
| 145 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 146 |
4
|
@RunsInEDT... |
| 147 |
|
private void assertThatButtonIsSelected(AbstractButton button, boolean selected) { |
| 148 |
4
|
assertThat(isSelected(button)).as(selectedProperty(button)).isEqualTo(selected); |
| 149 |
|
} |
| 150 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 151 |
4
|
@RunsInEDT... |
| 152 |
|
private static Description selectedProperty(AbstractButton button) { |
| 153 |
4
|
return propertyName(button, SELECTED_PROPERTY); |
| 154 |
|
} |
| 155 |
|
} |