01: package org.uispec4j;
02:
03: import javax.swing.JSpinner;
04: import javax.swing.SpinnerListModel;
05: import javax.swing.SpinnerModel;
06:
07: public class SpinnerTest extends SpinnerTestCase {
08:
09: protected SpinnerModel createSpinnerModel() {
10: return new SpinnerListModel(new String[] { "1", "2", "3" });
11: }
12:
13: protected Spinner createSpinner(JSpinner jSpinner) {
14: return new Spinner(jSpinner);
15: }
16:
17: public void testFactory() throws Exception {
18: checkFactory(new JSpinner(), Spinner.class);
19: }
20:
21: public void testCurrentPreviousAndNextValues() throws Exception {
22: assertTrue(spinner.valueEquals("1"));
23: assertTrue(spinner.nextValueEquals("2"));
24:
25: spinner.setValue("3");
26: assertTrue(spinner.valueEquals("3"));
27: assertTrue(spinner.previousValueEquals("2"));
28:
29: spinner.setValue("2");
30: assertTrue(spinner.valueEquals("2"));
31: assertTrue(spinner.previousValueEquals("1"));
32: assertTrue(spinner.nextValueEquals("3"));
33: }
34:
35: public void testSettingAValueNotInTheSequenceFails()
36: throws Exception {
37: try {
38: spinner.setValue("4");
39: fail();
40: } catch (ItemNotFoundException e) {
41: assertEquals("'4' not found", e.getMessage());
42: }
43: }
44:
45: public void testFailureWithCurrentPreviousAndNextValues()
46: throws Exception {
47: spinner.setValue("1");
48: checkPreviousValueFails("4");
49: checkPreviousValueFails(null);
50:
51: spinner.setValue("3");
52: checkNextValueFails("2");
53: checkNextValueFails(null);
54: }
55:
56: public void testClickButtons() throws Exception {
57: spinner.setValue("1");
58: spinner.clickForNextValue();
59: assertTrue(spinner.valueEquals("2"));
60:
61: spinner.clickForNextValue();
62: assertTrue(spinner.valueEquals("3"));
63:
64: spinner.clickForPreviousValue();
65: assertTrue(spinner.valueEquals("2"));
66:
67: spinner.clickForPreviousValue();
68: assertTrue(spinner.valueEquals("1"));
69: }
70:
71: public void testClickButtonsDoesNotFailIfNotValueAvailable()
72: throws Exception {
73: spinner.setValue("1");
74: spinner.clickForPreviousValue();
75: assertTrue(spinner.valueEquals("1"));
76:
77: spinner.setValue("3");
78: spinner.clickForNextValue();
79: assertTrue(spinner.valueEquals("3"));
80: }
81: }
|