|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JLabelDriver | Line # 39 | 4 | 0% | 4 | 0 | 100% |
1.0
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| No Tests | |||
| 1 | /* | |
| 2 | * Created on Feb 28, 2008 | |
| 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 @2008-2010 the original author or authors. | |
| 15 | */ | |
| 16 | package org.fest.swing.driver; | |
| 17 | ||
| 18 | import static org.fest.swing.driver.TextAssert.verifyThat; | |
| 19 | ||
| 20 | import java.util.regex.Pattern; | |
| 21 | ||
| 22 | import javax.swing.JLabel; | |
| 23 | ||
| 24 | import org.fest.swing.annotation.RunsInEDT; | |
| 25 | import org.fest.swing.core.Robot; | |
| 26 | ||
| 27 | /** | |
| 28 | * Understands functional testing of <code>{@link JLabel}</code>s: | |
| 29 | * <ul> | |
| 30 | * <li>user input simulation</li> | |
| 31 | * <li>state verification</li> | |
| 32 | * <li>property value query</li> | |
| 33 | * </ul> | |
| 34 | * This class is intended for internal use only. Please use the classes in the package | |
| 35 | * <code>{@link org.fest.swing.fixture}</code> in your tests. | |
| 36 | * | |
| 37 | * @author Alex Ruiz | |
| 38 | */ | |
| 39 | public class JLabelDriver extends JComponentDriver implements TextDisplayDriver<JLabel> { | |
| 40 | ||
| 41 | private static final String TEXT_PROPERTY = "text"; | |
| 42 | ||
| 43 | /** | |
| 44 | * Creates a new </code>{@link JLabelDriver}</code>. | |
| 45 | * @param robot the robot to use to simulate user input. | |
| 46 | */ | |
| 47 | 35 |
public JLabelDriver(Robot robot) { |
| 48 | 35 | super(robot); |
| 49 | } | |
| 50 | ||
| 51 | /** | |
| 52 | * Asserts that the text of the <code>{@link JLabel}</code> is equal to the specified <code>String</code>. | |
| 53 | * @param label the target <code>JLabel</code>. | |
| 54 | * @param expected the text to match. | |
| 55 | * @throws AssertionError if the text of the <code>JLabel</code> is not equal to the given one. | |
| 56 | */ | |
| 57 | 4 |
@RunsInEDT |
| 58 | public void requireText(JLabel label, String expected) { | |
| 59 | 4 | verifyThat(textOf(label)).as(propertyName(label, TEXT_PROPERTY)).isEqualOrMatches(expected); |
| 60 | } | |
| 61 | ||
| 62 | /** | |
| 63 | * Asserts that the text of the <code>{@link JLabel}</code> matches the given regular expression pattern. | |
| 64 | * @param label the target <code>JLabel</code>. | |
| 65 | * @param pattern the regular expression pattern to match. | |
| 66 | * @throws AssertionError if the text of the <code>JLabel</code> does not match the given regular expression pattern. | |
| 67 | * @throws NullPointerException if the given regular expression pattern is <code>null</code>. | |
| 68 | * @since 1.2 | |
| 69 | */ | |
| 70 | 2 |
@RunsInEDT |
| 71 | public void requireText(JLabel label, Pattern pattern) { | |
| 72 | 2 | verifyThat(textOf(label)).as(propertyName(label, TEXT_PROPERTY)).matches(pattern); |
| 73 | } | |
| 74 | ||
| 75 | /** | |
| 76 | * Returns the text of the given <code>{@link JLabel}</code>. | |
| 77 | * @param label the given <code>JLabel</code>. | |
| 78 | * @return the text of the given <code>JLabel</code>. | |
| 79 | */ | |
| 80 | 6 |
@RunsInEDT |
| 81 | public String textOf(JLabel label) { | |
| 82 | 6 | return JLabelTextQuery.textOf(label); |
| 83 | } | |
| 84 | } | |
|
||||||||||||