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 Anton Avtamonov
019: * @version $Revision$
020: */package javax.swing.plaf.basic;
021:
022: import java.awt.Dimension;
023: import javax.swing.JScrollPane;
024: import javax.swing.SwingTestCase;
025:
026: public class BasicScrollPaneUITest extends SwingTestCase {
027: private BasicScrollPaneUI ui;
028:
029: public BasicScrollPaneUITest(final String name) {
030: super (name);
031: }
032:
033: @Override
034: protected void setUp() throws Exception {
035: ui = new BasicScrollPaneUI();
036: }
037:
038: @Override
039: protected void tearDown() throws Exception {
040: ui = null;
041: }
042:
043: public void testCreateUI() throws Exception {
044: assertTrue(BasicScrollPaneUI.createUI(null) instanceof BasicScrollPaneUI);
045: assertNotSame(BasicScrollPaneUI.createUI(null),
046: BasicScrollPaneUI.createUI(null));
047: }
048:
049: public void testCreateViewportChangeListener() throws Exception {
050: assertNotNull(ui.createViewportChangeListener());
051: if (isHarmony()) {
052: assertTrue(ui.createViewportChangeListener() instanceof BasicScrollPaneUI.ViewportChangeHandler);
053: assertNotSame(ui.createViewportChangeListener(), ui
054: .createViewportChangeListener());
055: }
056: }
057:
058: public void testCreateHSBChangeListener() throws Exception {
059: assertNotNull(ui.createHSBChangeListener());
060: if (isHarmony()) {
061: assertTrue(ui.createHSBChangeListener() instanceof BasicScrollPaneUI.HSBChangeListener);
062: assertNotSame(ui.createHSBChangeListener(), ui
063: .createHSBChangeListener());
064: }
065: }
066:
067: public void testCreateVSBChangeListener() throws Exception {
068: assertNotNull(ui.createVSBChangeListener());
069: if (isHarmony()) {
070: assertTrue(ui.createVSBChangeListener() instanceof BasicScrollPaneUI.VSBChangeListener);
071: assertNotSame(ui.createVSBChangeListener(), ui
072: .createVSBChangeListener());
073: }
074: }
075:
076: public void testCreateMouseWheelListener() throws Exception {
077: assertNotNull(ui.createMouseWheelListener());
078: if (isHarmony()) {
079: assertTrue(ui.createMouseWheelListener() instanceof BasicScrollPaneUI.MouseWheelHandler);
080: assertNotSame(ui.createMouseWheelListener(), ui
081: .createMouseWheelListener());
082: }
083: }
084:
085: public void testCreatePropertyChangeListener() throws Exception {
086: assertNotNull(ui.createPropertyChangeListener());
087: if (isHarmony()) {
088: assertTrue(ui.createPropertyChangeListener() instanceof BasicScrollPaneUI.PropertyChangeHandler);
089: assertNotSame(ui.createPropertyChangeListener(), ui
090: .createPropertyChangeListener());
091: }
092: }
093:
094: public void testInstallUninstallListeners() throws Exception {
095: ui.scrollpane = new JScrollPane();
096: int viewportListenersCount = ui.scrollpane.getViewport()
097: .getChangeListeners().length;
098: assertNull(ui.viewportChangeListener);
099: int scrollPaneListenersCount = ui.scrollpane
100: .getPropertyChangeListeners().length;
101: assertNull(ui.spPropertyChangeListener);
102: assertNull(ui.hsbChangeListener);
103: assertNull(ui.vsbChangeListener);
104: ui.installListeners(null);
105: assertEquals(viewportListenersCount + 1, ui.scrollpane
106: .getViewport().getChangeListeners().length);
107: assertNotNull(ui.viewportChangeListener);
108: assertEquals(scrollPaneListenersCount + 1, ui.scrollpane
109: .getPropertyChangeListeners().length);
110: assertNotNull(ui.spPropertyChangeListener);
111: assertNotNull(ui.hsbChangeListener);
112: assertNotNull(ui.vsbChangeListener);
113: ui.uninstallListeners(null);
114: assertEquals(viewportListenersCount, ui.scrollpane
115: .getViewport().getChangeListeners().length);
116: assertNull(ui.viewportChangeListener);
117: assertEquals(scrollPaneListenersCount, ui.scrollpane
118: .getPropertyChangeListeners().length);
119: assertNull(ui.spPropertyChangeListener);
120: assertNull(ui.hsbChangeListener);
121: assertNull(ui.vsbChangeListener);
122: }
123:
124: public void testGetMaximumSize() throws Exception {
125: assertEquals(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE),
126: ui.getMaximumSize(null));
127: assertNotSame(ui.getMaximumSize(null), ui.getMaximumSize(null));
128: }
129: }
|