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.colorchooser;
21:
22: import java.awt.Color;
23: import java.util.Arrays;
24: import javax.swing.BasicSwingTestCase;
25: import javax.swing.event.ChangeListener;
26:
27: public class DefaultColorSelectionModelTest extends BasicSwingTestCase {
28: ChangeController changeController;
29:
30: DefaultColorSelectionModel model;
31:
32: @Override
33: public void setUp() throws Exception {
34: changeController = new ChangeController();
35: model = new DefaultColorSelectionModel();
36: }
37:
38: @Override
39: public void tearDown() throws Exception {
40: model = null;
41: changeController = null;
42: }
43:
44: public void testDefaultColorSelectionModel() {
45: assertSame(Color.WHITE, model.getSelectedColor());
46: assertNull(model.changeEvent);
47: assertNotNull(model.listenerList);
48: }
49:
50: public void testGetSetSelectedColor() {
51: model.addChangeListener(changeController);
52: model.setSelectedColor(Color.GREEN);
53: assertTrue(changeController.isChanged());
54: assertSame(Color.GREEN, model.getSelectedColor());
55: changeController.reset();
56: model.setSelectedColor(Color.GREEN);
57: assertFalse(changeController.isChanged());
58: model.setSelectedColor(new Color(0, 255, 0));
59: assertFalse(changeController.isChanged());
60: }
61:
62: public void testAddGetRemoveChangeListeners() {
63: model.addChangeListener(changeController);
64: assertTrue(Arrays.asList(model.listenerList.getListenerList())
65: .contains(changeController));
66: assertEquals(model.listenerList
67: .getListeners(ChangeListener.class), model
68: .getChangeListeners());
69: model.removeChangeListener(changeController);
70: assertFalse(Arrays.asList(model.listenerList.getListenerList())
71: .contains(changeController));
72: assertEquals(model.listenerList
73: .getListeners(ChangeListener.class), model
74: .getChangeListeners());
75: model.listenerList = null;
76: testExceptionalCase(new NullPointerCase() {
77: @Override
78: public void exceptionalAction() throws Exception {
79: model.addChangeListener(changeController);
80: }
81: });
82: testExceptionalCase(new NullPointerCase() {
83: @Override
84: public void exceptionalAction() throws Exception {
85: model.getChangeListeners();
86: }
87: });
88: }
89:
90: public void testFireStateChanged() {
91: model.addChangeListener(changeController);
92: model.fireStateChanged();
93: assertNotNull(model.changeEvent);
94: assertTrue(changeController.isChanged());
95: }
96: }
|