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 Dmitry A. Durnev
019: * @version $Revision$
020: */package java.awt;
021:
022: import java.beans.PropertyChangeEvent;
023: import java.beans.PropertyChangeListener;
024:
025: import junit.framework.TestCase;
026:
027: @SuppressWarnings("serial")
028: public class ComponentRTest extends TestCase {
029: private static PropertyChangeEvent lastEvent;
030:
031: private static class PropertyChangeListenerImpl implements
032: PropertyChangeListener {
033: public void propertyChange(PropertyChangeEvent pce) {
034: lastEvent = pce;
035: }
036:
037: }
038:
039: public final void testFirePropertyChange() {
040: Component comp = new Component() {
041: @Override
042: public void firePropertyChange(String s, Object o1,
043: Object o2) {
044: // consuming object property change
045: }
046:
047: };
048: comp
049: .addPropertyChangeListener(new PropertyChangeListenerImpl());
050: assertNull(lastEvent);
051: comp.setFocusable(false);
052: assertNotNull("boolean property change was fired", lastEvent);
053: Object newVal = lastEvent.getNewValue();
054: Object oldVal = lastEvent.getOldValue();
055: assertTrue("new value is Boolean", newVal instanceof Boolean);
056: assertFalse(((Boolean) newVal).booleanValue());
057: assertTrue(((Boolean) oldVal).booleanValue());
058:
059: }
060:
061: public final void testGetMinimumSize() {
062: final Component comp = new Component() {
063: };
064: Dimension size = new Dimension(100, 100);
065: Dimension defSize = new Dimension(1, 1);
066: comp.setSize(size);
067: assertEquals(size, comp.getMinimumSize());
068: comp.addNotify();
069: assertEquals(defSize, comp.getMinimumSize());
070: size.setSize(13, 13);
071: comp.setSize(size);
072: assertEquals(defSize, comp.getMinimumSize());
073: comp.removeNotify();
074: assertEquals(size, comp.getMinimumSize());
075: }
076:
077: public void testTransferFocusUpCycle() {
078: // Regression test for HARMONY-2456
079: new Button().transferFocusUpCycle();
080: }
081:
082: public void testDeadLoop4887() {
083: final int count[] = new int[1];
084: Component c = new Panel() {
085: public void paint(Graphics g) {
086: count[0]++;
087: setBackground(new Color(255, 255, 255));
088: setForeground(Color.BLACK);
089: setFont(new Font("Serif", Font.PLAIN, 10));
090: }
091: };
092:
093: Tools.checkDeadLoop(c, count);
094: }
095:
096: public static void main(String[] args) {
097: junit.textui.TestRunner.run(ComponentRTest.class);
098: }
099:
100: }
|