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 Sergey Burlak
019: * @version $Revision$
020: */package javax.swing.plaf.basic;
021:
022: import javax.swing.BasicSwingTestCase;
023: import javax.swing.JColorChooser;
024: import javax.swing.JPanel;
025: import javax.swing.JTabbedPane;
026: import javax.swing.colorchooser.AbstractColorChooserPanel;
027: import javax.swing.colorchooser.DefaultColorSelectionModel;
028:
029: public class BasicColorChooserUITest extends BasicSwingTestCase {
030: private JColorChooser ch;
031:
032: private BasicColorChooserUI ui;
033:
034: @Override
035: protected void setUp() throws Exception {
036: super .setUp();
037: ch = new JColorChooser();
038: ui = (BasicColorChooserUI) ch.getUI();
039: }
040:
041: @Override
042: protected void tearDown() throws Exception {
043: super .tearDown();
044: ch = null;
045: ui = null;
046: }
047:
048: public void testCreateUI() throws Exception {
049: assertNotNull(BasicColorChooserUI.createUI(ch));
050: assertNotSame(BasicColorChooserUI.createUI(ch),
051: BasicColorChooserUI.createUI(ch));
052: assertSame(BasicColorChooserUI.class, BasicColorChooserUI
053: .createUI(ch).getClass());
054: }
055:
056: public void testCreateDefaultChoosers() throws Exception {
057: assertNotNull(ui.createDefaultChoosers());
058: assertNotSame(ui.createDefaultChoosers(), ui
059: .createDefaultChoosers());
060: assertEquals(3, ui.createDefaultChoosers().length);
061: }
062:
063: public void testCreatePropertychangeListener() throws Exception {
064: assertNotNull(ui.createPropertyChangeListener());
065: if (isHarmony()) {
066: assertNotSame(ui.createPropertyChangeListener(), ui
067: .createPropertyChangeListener());
068: assertSame(BasicColorChooserUI.PropertyHandler.class, ui
069: .createPropertyChangeListener().getClass());
070: }
071: }
072:
073: public void testInstallUninstallPreviewPanel() throws Exception {
074: assertEquals(2, ch.getComponentCount());
075: assertNotNull(findComponent(ch, JTabbedPane.class, true));
076: ch.remove(ch.getComponent(1));
077: assertEquals(1, ch.getComponentCount());
078: ch.setPreviewPanel(new JPanel());
079: assertEquals(1, ch.getComponentCount());
080: ui.installPreviewPanel();
081: assertEquals(1, ch.getComponentCount());
082: }
083:
084: public void testUninstallDefaultChoosers() throws Exception {
085: assertEquals(2, ch.getComponentCount());
086: assertNotNull(findComponent(ch, JTabbedPane.class, true));
087: assertEquals(3, ((JTabbedPane) findComponent(ch,
088: JTabbedPane.class, true)).getTabCount());
089: ch.removeChooserPanel(ch.getChooserPanels()[0]);
090: assertEquals(2, ch.getComponentCount());
091: assertNotNull(findComponent(ch, JTabbedPane.class, true));
092: assertEquals(2, ((JTabbedPane) findComponent(ch,
093: JTabbedPane.class, true)).getTabCount());
094: ch.removeChooserPanel(ch.getChooserPanels()[0]);
095: assertEquals(2, ch.getComponentCount());
096: assertNull(findComponent(ch, JTabbedPane.class, true));
097: ch.removeChooserPanel(ch.getChooserPanels()[0]);
098: assertEquals(2, ch.getComponentCount());
099: assertNull(findComponent(ch, JTabbedPane.class, true));
100: ui.defaultChoosers = new AbstractColorChooserPanel[0];
101: ui.uninstallDefaultChoosers();
102: assertEquals(2, ch.getComponentCount());
103: assertNull(findComponent(ch, JTabbedPane.class, true));
104: }
105:
106: public void testInstallUninstallListeners() throws Exception {
107: ui.uninstallListeners();
108: int propChangeListCount = ch.getPropertyChangeListeners().length;
109: int changeListcount = ((DefaultColorSelectionModel) ch
110: .getSelectionModel()).getChangeListeners().length;
111: ui.installListeners();
112: assertEquals(propChangeListCount + 1, ch
113: .getPropertyChangeListeners().length);
114: assertEquals(changeListcount + 1,
115: ((DefaultColorSelectionModel) ch.getSelectionModel())
116: .getChangeListeners().length);
117: ui.uninstallListeners();
118: assertEquals(propChangeListCount, ch
119: .getPropertyChangeListeners().length);
120: assertEquals(changeListcount, ((DefaultColorSelectionModel) ch
121: .getSelectionModel()).getChangeListeners().length);
122: }
123: }
|