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

📄 datespinner.java

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

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

import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
import javax.swing.SpinnerModel;

/**
 * Wrapper for JSpinner components implementing a SpinnerDateModel.
 */
public class DateSpinner extends Spinner {
  private SpinnerDateModel model;

  public DateSpinner(JSpinner jSpinner) throws ItemNotFoundException {
    super(jSpinner);
    SpinnerModel model = jSpinner.getModel();
    if (!model.getClass().isAssignableFrom(SpinnerDateModel.class)) {
      throw new ItemNotFoundException("Expected JSpinner using a SpinnerDateModel");
    }
    this.model = (SpinnerDateModel) model;
  }

  /**
   * Checks that the date spinner displays starts with the given value
   * @see DateUtils to format the date as String
   */
  public Assertion startDateEquals(final String expectedStartDate) {
    return new Assertion() {
      public void check() throws Exception {
        Assert.assertEquals(DateUtils.getDate(expectedStartDate), model.getStart());
      }
    };
  }

  /**
   * Checks that the date spinner displays ends with the given value
   * @see DateUtils to format the date as String
   */
  public Assertion endDateEquals(final String expectedEndDate) {
    return new Assertion() {
      public void check() throws Exception {
        Assert.assertEquals(DateUtils.getDate(expectedEndDate), model.getEnd());
      }
    };
  }

  /**
   * Checks that the date spinner computes previous and next value with the given value.
   * {@link java.util.Calendar} constants
   */
  public Assertion calendarFieldsEquals(final int expectedCalendarFields) {
    return new Assertion() {
      public void check() throws Exception {
        Assert.assertEquals(expectedCalendarFields, model.getCalendarField());
      }
    };
  }
}

⌨️ 快捷键说明

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