01: package org.uispec4j;
02:
03: import junit.framework.Assert;
04: import org.uispec4j.assertion.Assertion;
05:
06: import javax.swing.JSpinner;
07: import javax.swing.SpinnerModel;
08: import javax.swing.SpinnerNumberModel;
09:
10: /**
11: * Wrapper for JSpinner components implementing a SpinnerNumberModel.
12: */
13: public class NumberSpinner extends Spinner {
14: private SpinnerNumberModel model;
15:
16: public NumberSpinner(JSpinner jSpinner) {
17: super (jSpinner);
18: SpinnerModel model = jSpinner.getModel();
19: if (!model.getClass()
20: .isAssignableFrom(SpinnerNumberModel.class)) {
21: throw new ItemNotFoundException(
22: "Expected JSpinner using a SpinnerNumberModel");
23: }
24: this .model = (SpinnerNumberModel) model;
25: }
26:
27: /**
28: * Checks that the list spinner displays starts with the given value
29: */
30: public Assertion minEquals(final int expectedMin) {
31: return new Assertion() {
32: public void check() throws Exception {
33: Assert.assertEquals(new Integer(expectedMin), model
34: .getMinimum());
35: }
36: };
37: }
38:
39: /**
40: * Checks that the list spinner displays starts with the given value
41: */
42: public Assertion maxEquals(final int expectedMax) {
43: return new Assertion() {
44: public void check() throws Exception {
45: Assert.assertEquals(new Integer(expectedMax), model
46: .getMaximum());
47: }
48: };
49: }
50:
51: /**
52: * Checks that the list spinner computes previous and next value with the given value.
53: */
54: public Assertion stepSizeEquals(final int expectedStepSize) {
55: return new Assertion() {
56: public void check() throws Exception {
57: Assert.assertEquals(new Integer(expectedStepSize),
58: model.getStepSize());
59: }
60: };
61: }
62: }
|