001: package org.uispec4j;
002:
003: import org.uispec4j.utils.Functor;
004: import org.uispec4j.utils.UIComponentFactory;
005: import org.uispec4j.xml.XmlAssert;
006:
007: import javax.swing.ImageIcon;
008: import javax.swing.JLabel;
009:
010: public class TextBoxForLabelTest extends TextBoxComponentTestCase {
011: private JLabel jLabel;
012:
013: protected void setUp() throws Exception {
014: super .setUp();
015: jLabel = new JLabel("some text");
016: jLabel.setName("myLabel");
017: textBox = new TextBox(jLabel);
018: }
019:
020: protected void createTextBox(String text) {
021: jLabel = new JLabel(text);
022: textBox = new TextBox(jLabel);
023: }
024:
025: public void testGetComponentTypeName() throws Exception {
026: assertEquals("textBox", UIComponentFactory.createUIComponent(
027: new JLabel()).getDescriptionTypeName());
028: }
029:
030: public void testGetDescription() throws Exception {
031: XmlAssert.assertEquivalent("<textBox name='myLabel'/>", textBox
032: .getDescription());
033: }
034:
035: public void testFactory() throws Exception {
036: checkFactory(new JLabel(), TextBox.class);
037: }
038:
039: public void testAssertTextEquals() throws Exception {
040: assertTrue(textBox.textEquals("some text"));
041: checkAssertionFails(textBox.textEquals("unknown"),
042: "expected:<unknown> but was:<some text>");
043: }
044:
045: public void testAssertTextEqualsWithHtml() throws Exception {
046: String text = "My name is <b>Bond</b>";
047: jLabel.setText(text);
048: assertTrue(textBox.textEquals(text));
049: assertFalse(textBox
050: .textEquals("My name is <b>Bond</b>, James Bond"));
051: }
052:
053: public void testAssertTextContains() throws Exception {
054: jLabel.setText("some text");
055: assertTrue(textBox.textContains("some"));
056: checkAssertionFails(textBox.textContains("error"),
057: "The component text does not contain 'error' - actual content is: some text");
058: }
059:
060: public void testAssertTextDoesNotContain() throws Exception {
061: jLabel.setText("some text");
062: assertTrue(textBox.textDoesNotContain("xxx"));
063: checkAssertionFails(textBox.textDoesNotContain("some"),
064: "The component text should not contain 'some' - actual content is: some text");
065: }
066:
067: public void testAssertTextIsEditable() throws Exception {
068: assertFalse(textBox.isEditable());
069: }
070:
071: public void testAssertEmpty() throws Exception {
072: jLabel.setText("");
073: assertTrue(textBox.textIsEmpty());
074: jLabel.setText("a");
075: checkAssertionFails(textBox.textIsEmpty(),
076: "Text should be empty but contains: a");
077: }
078:
079: public void testSetTextIsNotSupported() throws Exception {
080: checkAssertionFailedError(new Functor() {
081: public void run() throws Exception {
082: textBox.setText("text");
083: }
084: }, "The text box is not editable");
085: assertEquals("some text", textBox.getText());
086: }
087:
088: public void testInsertTextIsNotSupported() throws Exception {
089: checkAssertionFailedError(new Functor() {
090: public void run() throws Exception {
091: textBox.insertText("text", 0);
092: }
093: }, "The text box is not editable");
094: assertEquals("some text", textBox.getText());
095: }
096:
097: public void testGetText() throws Exception {
098: assertEquals("some text", textBox.getText());
099: jLabel.setText("new text");
100: assertEquals("new text", textBox.getText());
101: }
102:
103: public void testClickOnHyperlinkIsNotSupported() throws Exception {
104: checkAssertionFailedError(new Functor() {
105: public void run() throws Exception {
106: textBox.clickOnHyperlink("text");
107: }
108: }, "This component does not support hyperlinks.");
109: checkAssertionFailedError(new Functor() {
110: public void run() throws Exception {
111: textBox.triggerClickOnHyperlink("text").run();
112: }
113: }, "This component does not support hyperlinks.");
114: }
115:
116: public void testAssertIconEquals() throws Exception {
117: ImageIcon icon1 = new ImageIcon();
118: jLabel.setIcon(icon1);
119: assertTrue(textBox.iconEquals(icon1));
120: checkAssertionFailedError(new Functor() {
121: public void run() throws Exception {
122: ImageIcon icon2 = new ImageIcon();
123: assertTrue(textBox.iconEquals(icon2));
124: }
125: });
126: }
127: }
|