numberspinner.java

来自「基于Junit的 功能和单元测试的的测试工具。只支持Swing.」· Java 代码 · 共 58 行

JAVA
58
字号
package org.uispec4j;

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

import javax.swing.JSpinner;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;

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

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

  /**
   * Checks that the list spinner displays starts with the given value
   */
  public Assertion minEquals(final int expectedMin) {
    return new Assertion() {
      public void check() throws Exception {
        Assert.assertEquals(new Integer(expectedMin), model.getMinimum());
      }
    };
  }

  /**
   * Checks that the list spinner displays starts with the given value
   */
  public Assertion maxEquals(final int expectedMax) {
    return new Assertion() {
      public void check() throws Exception {
        Assert.assertEquals(new Integer(expectedMax), model.getMaximum());
      }
    };
  }

  /**
   * Checks that the list spinner computes previous and next value with the given value.
   */
  public Assertion stepSizeEquals(final int expectedStepSize) {
    return new Assertion() {
      public void check() throws Exception {
        Assert.assertEquals(new Integer(expectedStepSize), model.getStepSize());
      }
    };
  }
}

⌨️ 快捷键说明

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