01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Dennis Ushakov
19: * @version $Revision$
20: */package javax.swing;
21:
22: import java.util.Arrays;
23: import java.util.EventListener;
24:
25: public class AbstractSpinnerModelTest extends BasicSwingTestCase {
26: private AbstractSpinnerModel model;
27:
28: private ChangeController chl;
29:
30: private static class TestListener implements EventListener {
31: };
32:
33: @Override
34: public void setUp() {
35: model = new AbstractSpinnerModel() {
36: public Object getNextValue() {
37: return null;
38: }
39:
40: public Object getPreviousValue() {
41: return null;
42: }
43:
44: public Object getValue() {
45: return "test";
46: }
47:
48: public void setValue(Object value) {
49: fireStateChanged();
50: }
51: };
52: chl = new ChangeController();
53: }
54:
55: @Override
56: public void tearDown() {
57: model = null;
58: chl = null;
59: }
60:
61: public void testAddRemoveChangeListener() {
62: model.addChangeListener(chl);
63: assertEquals(1, model.listenerList.getListenerCount());
64: model.removeChangeListener(chl);
65: assertEquals(0, model.listenerList.getListenerCount());
66: }
67:
68: public void getChangeListeners() {
69: model.addChangeListener(chl);
70: assertTrue(Arrays.asList(model.getChangeListeners()).contains(
71: chl));
72: }
73:
74: public void testFireStateChanged() {
75: model.addChangeListener(chl);
76: model.setValue(null);
77: assertTrue(chl.isChanged());
78: }
79:
80: public void testGetListeners() {
81: final TestListener testListener = new TestListener();
82: model.listenerList.add(TestListener.class, testListener);
83: assertTrue(Arrays
84: .asList(model.getListeners(TestListener.class))
85: .contains(testListener));
86: }
87: }
|