001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Dennis Ushakov
019: * @version $Revision$
020: */package javax.swing;
021:
022: public class SpinnerNumberModelTest extends BasicSwingTestCase {
023: private SpinnerNumberModel model;
024:
025: private ChangeController chl;
026:
027: @Override
028: public void setUp() {
029: model = new SpinnerNumberModel();
030: chl = new ChangeController();
031: model.addChangeListener(chl);
032: }
033:
034: @Override
035: public void tearDown() {
036: model = null;
037: chl = null;
038: }
039:
040: public void testSpinnerNumberModel() {
041: assertNull(model.getMaximum());
042: assertNull(model.getMinimum());
043: assertEquals(new Integer(0), model.getValue());
044: assertEquals(new Integer(1), model.getStepSize());
045: final Integer val = new Integer(10);
046: model = new SpinnerNumberModel(10, 10, 10, 10);
047: assertEquals(val, model.getValue());
048: assertEquals(val, model.getStepSize());
049: assertEquals(val, model.getValue());
050: assertEquals(val, model.getStepSize());
051: testExceptionalCase(new IllegalArgumentCase() {
052: @Override
053: public void exceptionalAction() throws Exception {
054: model = new SpinnerNumberModel(null, val, val, val);
055: }
056: });
057: testExceptionalCase(new IllegalArgumentCase() {
058: @Override
059: public void exceptionalAction() throws Exception {
060: model = new SpinnerNumberModel(val, val, val, null);
061: }
062: });
063: testExceptionalCase(new IllegalArgumentCase() {
064: @Override
065: public void exceptionalAction() throws Exception {
066: model = new SpinnerNumberModel(val, val,
067: new Integer(-1), val);
068: }
069: });
070: }
071:
072: public void testSetGetMinimum() {
073: final Double min = new Double(-2.);
074: model.setMinimum(min);
075: assertTrue(chl.isChanged());
076: assertSame(min, model.getMinimum());
077: model.setMinimum(new Integer(10));
078: model.setMinimum(min);
079: chl.reset();
080: model.setMinimum(min);
081: assertFalse(chl.isChanged());
082: }
083:
084: public void testSetGetMaximum() {
085: final Double max = new Double(35.);
086: model.setMaximum(max);
087: assertTrue(chl.isChanged());
088: assertSame(max, model.getMaximum());
089: model.setMaximum(new Integer(-10));
090: model.setMaximum(max);
091: chl.reset();
092: model.setMaximum(max);
093: assertFalse(chl.isChanged());
094: }
095:
096: public void testSetGetStepSize() {
097: final Integer step = new Integer(3);
098: model.setStepSize(step);
099: assertTrue(chl.isChanged());
100: assertSame(step, model.getStepSize());
101: testExceptionalCase(new IllegalArgumentCase() {
102: @Override
103: public void exceptionalAction() throws Exception {
104: model.setStepSize(null);
105: }
106: });
107: model.setStepSize(step);
108: chl.reset();
109: model.setStepSize(step);
110: assertFalse(chl.isChanged());
111: }
112:
113: public void testSetGetValue() {
114: final Integer value = new Integer(10);
115: model.setValue(value);
116: assertTrue(chl.isChanged());
117: assertSame(value, model.getValue());
118: testExceptionalCase(new IllegalArgumentCase() {
119: @Override
120: public void exceptionalAction() throws Exception {
121: model.setValue(null);
122: }
123: });
124: testExceptionalCase(new IllegalArgumentCase() {
125: @Override
126: public void exceptionalAction() throws Exception {
127: model.setValue("test");
128: }
129: });
130: model.setValue(value);
131: chl.reset();
132: model.setValue(value);
133: assertFalse(chl.isChanged());
134: }
135:
136: public void testGetNumber() {
137: final Integer value = new Integer(10);
138: model.setValue(value);
139: assertSame(model.getValue(), model.getNumber());
140: }
141:
142: public void testGetPreviousValue() {
143: model.getPreviousValue();
144: Integer value = new Integer(10);
145: model.setValue(value);
146: Integer min = new Integer(8);
147: model.setMinimum(min);
148: Integer step = new Integer(2);
149: model.setStepSize(step);
150: assertEquals(min, model.getPreviousValue());
151: step = new Integer(3);
152: model.setStepSize(step);
153: assertNull(model.getPreviousValue());
154: }
155:
156: public void testNextValue() {
157: model.getNextValue();
158: Double value = new Double(10);
159: Double max = new Double(12);
160: Integer step = new Integer(2);
161: model = new SpinnerNumberModel(value, null, max, step);
162: assertEquals(max, model.getNextValue());
163: step = new Integer(3);
164: model.setStepSize(step);
165: assertNull(model.getNextValue());
166: }
167: }
|