J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * @test |
| 26 | * @bug 5004188 |
| 27 | * @summary Tests sequence of methods |
| 28 | * @author Sergey Malenkov |
| 29 | */ |
| 30 | |
| 31 | import java.beans.PropertyChangeEvent; |
| 32 | import java.beans.PropertyChangeListener; |
| 33 | import java.beans.PropertyChangeSupport; |
| 34 | |
| 35 | enum Fire { |
| 36 | PropertyChangeEvent, |
| 37 | PropertyObject, |
| 38 | PropertyInteger, |
| 39 | PropertyBoolean, |
| 40 | IndexedPropertyObject, |
| 41 | IndexedPropertyInteger, |
| 42 | IndexedPropertyBoolean, |
| 43 | } |
| 44 | |
| 45 | public class TestMethods extends PropertyChangeSupport implements PropertyChangeListener { |
| 46 | private static final String NAME = "property"; |
| 47 | |
| 48 | public static void main(String[] args) { |
| 49 | Object source = new Object(); |
| 50 | new TestMethods(source).firePropertyChange(new PropertyChangeEvent(source, NAME, null, null)); |
| 51 | new TestMethods(source).firePropertyChange(NAME, null, null); |
| 52 | new TestMethods(source).firePropertyChange(NAME, 0, 1); |
| 53 | new TestMethods(source).firePropertyChange(NAME, true, false); |
| 54 | new TestMethods(source).fireIndexedPropertyChange(NAME, 0, null, null); |
| 55 | new TestMethods(source).fireIndexedPropertyChange(NAME, 0, 0, 1); |
| 56 | new TestMethods(source).fireIndexedPropertyChange(NAME, 0, true, false); |
| 57 | } |
| 58 | |
| 59 | private Fire state; |
| 60 | |
| 61 | public TestMethods(Object source) { |
| 62 | super(source); |
| 63 | addPropertyChangeListener(this); |
| 64 | } |
| 65 | |
| 66 | public void propertyChange(PropertyChangeEvent event) { |
| 67 | if (this.state != Fire.PropertyChangeEvent) |
| 68 | throw new Error("Illegal state: " + this.state); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public void firePropertyChange(String property, Object oldValue, Object newValue) { |
| 73 | if ((this.state != null) && (this.state != Fire.PropertyBoolean) && (this.state != Fire.PropertyInteger)) |
| 74 | throw new Error("Illegal state: " + this.state); |
| 75 | |
| 76 | this.state = Fire.PropertyObject; |
| 77 | super.firePropertyChange(property, oldValue, newValue); |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public void firePropertyChange(String property, int oldValue, int newValue) { |
| 82 | if (this.state != null) |
| 83 | throw new Error("Illegal state: " + this.state); |
| 84 | |
| 85 | this.state = Fire.PropertyInteger; |
| 86 | super.firePropertyChange(property, oldValue, newValue); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public void firePropertyChange(String property, boolean oldValue, boolean newValue) { |
| 91 | if (this.state != null) |
| 92 | throw new Error("Illegal state: " + this.state); |
| 93 | |
| 94 | this.state = Fire.PropertyBoolean; |
| 95 | super.firePropertyChange(property, oldValue, newValue); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public void firePropertyChange(PropertyChangeEvent event) { |
| 100 | if ((this.state != null) && (this.state != Fire.PropertyObject) && (this.state != Fire.IndexedPropertyObject)) |
| 101 | throw new Error("Illegal state: " + this.state); |
| 102 | |
| 103 | this.state = Fire.PropertyChangeEvent; |
| 104 | super.firePropertyChange(event); |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public void fireIndexedPropertyChange(String property, int index, Object oldValue, Object newValue) { |
| 109 | if ((this.state != null) && (this.state != Fire.IndexedPropertyBoolean) && (this.state != Fire.IndexedPropertyInteger)) |
| 110 | throw new Error("Illegal state: " + this.state); |
| 111 | |
| 112 | this.state = Fire.IndexedPropertyObject; |
| 113 | super.fireIndexedPropertyChange(property, index, oldValue, newValue); |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public void fireIndexedPropertyChange(String property, int index, int oldValue, int newValue) { |
| 118 | if (this.state != null) |
| 119 | throw new Error("Illegal state: " + this.state); |
| 120 | |
| 121 | this.state = Fire.IndexedPropertyInteger; |
| 122 | super.fireIndexedPropertyChange(property, index, oldValue, newValue); |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public void fireIndexedPropertyChange(String property, int index, boolean oldValue, boolean newValue) { |
| 127 | if (this.state != null) |
| 128 | throw new Error("Illegal state: " + this.state); |
| 129 | |
| 130 | this.state = Fire.IndexedPropertyBoolean; |
| 131 | super.fireIndexedPropertyChange(property, index, oldValue, newValue); |
| 132 | } |
| 133 | } |