⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textboxhandlerforlabel.java

📁 基于Junit的 功能和单元测试的的测试工具。只支持Swing.
💻 JAVA
字号:
package org.uispec4j;

import junit.framework.Assert;
import org.uispec4j.assertion.Assertion;
import org.uispec4j.utils.KeyUtils;

import javax.swing.*;
import java.awt.*;

class TextBoxHandlerForLabel implements TextBox.Handler {
  private JLabel jLabel;

  public TextBoxHandlerForLabel(JLabel label) {
    this.jLabel = label;
  }

  public Component getAwtComponent() {
    return jLabel;
  }

  public void setText(String text) {
    throwNotEditableError();
  }

  public void insertText(String text, int position) {
    throwNotEditableError();
  }

  public String getText() {
    return jLabel.getText();
  }

  public Assertion textIsEmpty() {
    return new Assertion() {
      public void check() {
        Assert.assertTrue("Text should be empty but contains: " + jLabel.getText(),
                          jLabel.getText().length() == 0);
      }
    };
  }

  public Assertion textEquals(final String text) {
    return new Assertion() {
      public void check() {
        Assert.assertEquals(text, jLabel.getText());
      }
    };
  }

  public Assertion htmlEquals(String html) {
    return new Assertion() {
      public void check() {
        Assert.fail("This component does not support html.");
      }
    };
  }

  public Assertion textContains(final String text) {
    return new Assertion() {
      public void check() {
        String actualText = jLabel.getText();
        Assert.assertTrue("The component text does not contain '" + text +
                          "' - actual content is: " + actualText,
                          actualText.indexOf(text) >= 0);
      }
    };
  }

  public Assertion textDoesNotContain(final String text) {
    return new Assertion() {
      public void check() {
        String actualText = jLabel.getText();
        Assert.assertTrue("The component text should not contain '" + text +
                          "' - actual content is: " + actualText,
                          actualText.indexOf(text) < 0);
      }
    };
  }

  public Assertion isEditable() {
    return new Assertion() {
      public void check() {
        Assert.fail("Text is not editable");
      }
    };
  }

  public void clickOnHyperlink(String link) {
    Assert.fail("This component does not support hyperlinks.");
  }

  public Assertion iconEquals(final Icon icon) {
    return new Assertion() {
      public void check() {
        Assert.assertEquals("Unexpected icon", icon, jLabel.getIcon());
      }
    };
  }

  public void pressKey(Key key) {
    KeyUtils.pressKey(jLabel, key);
  }

  private void throwNotEditableError() {
    Assert.fail("The text box is not editable");
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -