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.plaf.basic;
021:
022: import java.awt.Component;
023: import java.util.Arrays;
024: import javax.swing.BasicSwingTestCase;
025: import javax.swing.JLabel;
026: import javax.swing.JSpinner;
027: import javax.swing.SwingConstants;
028:
029: public class BasicSpinnerUITest extends BasicSwingTestCase {
030: private BasicSpinnerUI ui;
031:
032: private JSpinner spinner;
033:
034: @Override
035: public void setUp() {
036: spinner = new JSpinner();
037: spinner.getUI().uninstallUI(spinner);
038: ui = new BasicSpinnerUI();
039: }
040:
041: @Override
042: public void tearDown() {
043: spinner = null;
044: ui = null;
045: }
046:
047: public void testInstallListeners() {
048: ui.spinner = spinner;
049: ui.installListeners();
050: assertTrue(spinner.getPropertyChangeListeners().length > 0);
051: }
052:
053: public void testInstallUI() {
054: ui.installUI(spinner);
055: assertTrue(Arrays.asList(spinner.getComponents()).contains(
056: spinner.getEditor()));
057: }
058:
059: public void testCreatePreviousNextButton() {
060: Component nextButton = ui.createNextButton();
061: assertTrue(nextButton instanceof BasicArrowButton);
062: assertEquals(((BasicArrowButton) nextButton).getDirection(),
063: SwingConstants.NORTH);
064: assertTrue(((BasicArrowButton) nextButton).getActionListeners().length > 0);
065: assertTrue(((BasicArrowButton) nextButton).getMouseListeners().length > 1);
066: assertTrue(((BasicArrowButton) nextButton).getFocusListeners().length > 1);
067: assertNotSame(nextButton, ui.createNextButton());
068: Component previousButton = ui.createPreviousButton();
069: assertTrue(previousButton instanceof BasicArrowButton);
070: assertEquals(
071: ((BasicArrowButton) previousButton).getDirection(),
072: SwingConstants.SOUTH);
073: assertTrue(((BasicArrowButton) previousButton)
074: .getActionListeners().length > 0);
075: assertTrue(((BasicArrowButton) previousButton)
076: .getMouseListeners().length > 1);
077: assertTrue(((BasicArrowButton) previousButton)
078: .getFocusListeners().length > 1);
079: assertNotSame(previousButton, ui.createPreviousButton());
080: }
081:
082: public void testCreateEditor() {
083: ui.spinner = spinner;
084: Component editor = ui.createEditor();
085: assertSame(editor, spinner.getEditor());
086: }
087:
088: /**
089: * Regression test for HARMONY-2716
090: * */
091: public void testInstallNextButtonListeners()
092: throws ClassCastException {
093: BasicSpinnerUIForTest localBasicSpinnerUI = new BasicSpinnerUIForTest();
094: localBasicSpinnerUI.installNextButtonListeners(new JLabel());
095: }
096:
097: /**
098: * Regression test for HARMONY-2716
099: * */
100: public void testInstallPreviousButtonListeners()
101: throws ClassCastException {
102: BasicSpinnerUIForTest localBasicSpinnerUI = new BasicSpinnerUIForTest();
103: localBasicSpinnerUI
104: .installPreviousButtonListeners(new JLabel());
105: }
106:
107: class BasicSpinnerUIForTest extends BasicSpinnerUI {
108: public void installNextButtonListeners(Component c) {
109: super .installNextButtonListeners(c);
110: }
111:
112: public void installPreviousButtonListeners(Component c) {
113: super.installPreviousButtonListeners(c);
114: }
115: }
116: }
|