harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r394923 [10/16] - in /incubator/harmony/enhanced/classlib/trunk/modules/beans: make/common/ src/test/java.injected/ src/test/java.injected/java/ src/test/java.injected/java/beans/ src/test/java/tests/ src/test/java/tests/api/ src/test/java/...
Date Tue, 18 Apr 2006 12:11:45 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeSupportTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeSupportTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeSupportTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeSupportTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,1763 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.beans;
+
+import java.beans.EventHandler;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyVetoException;
+import java.beans.VetoableChangeListener;
+import java.beans.VetoableChangeListenerProxy;
+import java.beans.VetoableChangeSupport;
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+
+import junit.framework.TestCase;
+import tests.api.java.beans.beancontext.mock.MockVetoableChangeListener;
+import tests.api.java.beans.mock.NonSerializedVCListener;
+import tests.api.java.beans.mock.SerializedVCListener;
+import tests.util.SerializationTester;
+
+/**
+ * Unit test for VetoableChangeSupport
+ */
+public class VetoableChangeSupportTest extends TestCase {
+
+	/*
+	 * Constructor a VetoableChangeSupport instance with normal input
+	 */
+	public void testVetoableChangeSupport() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+	}
+
+	/*
+	 * Constructor a VetoableChangeSupport instance with null source
+	 */
+	public void testVetoableChangeSupport_null() {
+		MockSource source = null;
+		try {
+			VetoableChangeSupport support = new VetoableChangeSupport(source);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	/*
+	 * Class under test for void addVetoableChangeListener(String,
+	 * VetoableChangeListener)
+	 */
+	public void testAddVetoableChangeListenerStringVetoableChangeListener() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		String propertyName = "label";
+		support.addVetoableChangeListener(propertyName, proxy);
+
+		assertTrue(support.hasListeners(propertyName));
+		assertFalse(support.hasListeners("text"));
+
+		VetoableChangeListener[] listeners1 = support
+				.getVetoableChangeListeners();
+		VetoableChangeListener[] listeners2 = support
+				.getVetoableChangeListeners(propertyName);
+		VetoableChangeListener[] listeners3 = support
+				.getVetoableChangeListeners("text");
+
+		assertEquals(0, listeners3.length);
+		assertEquals(1, listeners1.length);
+		assertEquals(1, listeners2.length);
+
+		assertSame(proxy, listeners2[0]);
+		VetoableChangeListenerProxy wrappers = (VetoableChangeListenerProxy) listeners1[0];
+		assertSame(proxy, wrappers.getListener());
+		assertEquals(propertyName, wrappers.getPropertyName());
+
+	}
+
+	/*
+	 * add a null listener
+	 */
+	public void testAddVetoableChangeListenerStringVetoableChangeListener_null() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		String propertyName = "label";
+		support.addVetoableChangeListener(propertyName, null);
+		VetoableChangeListener[] listeners1 = support
+				.getVetoableChangeListeners();
+		VetoableChangeListener[] listeners2 = support
+				.getVetoableChangeListeners(propertyName);
+
+		assertTrue(support.hasListeners(propertyName));
+		assertFalse(support.hasListeners("text"));
+
+		assertEquals(1, listeners1.length);
+		assertEquals(propertyName,
+				((VetoableChangeListenerProxy) listeners1[0]).getPropertyName());
+		assertNull(((VetoableChangeListenerProxy) listeners1[0]).getListener());
+		assertEquals(1, listeners2.length);
+		assertNull(listeners2[0]);
+	}
+
+	/*
+	 * add a listener which has already been added.
+	 */
+	public void testAddVetoableChangeListenerStringVetoableChangeListener_duplicate() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		String propertyName = "label";
+		support.addVetoableChangeListener(propertyName, proxy);
+		{
+			assertTrue(support.hasListeners(propertyName));
+			assertFalse(support.hasListeners("text"));
+
+			VetoableChangeListener[] listeners1 = support
+					.getVetoableChangeListeners();
+			VetoableChangeListener[] listeners2 = support
+					.getVetoableChangeListeners(propertyName);
+			VetoableChangeListener[] listeners3 = support
+					.getVetoableChangeListeners("text");
+
+			assertEquals(0, listeners3.length);
+			assertEquals(1, listeners1.length);
+			assertEquals(1, listeners2.length);
+
+			assertSame(proxy, listeners2[0]);
+			VetoableChangeListenerProxy wrappers = (VetoableChangeListenerProxy) listeners1[0];
+			assertSame(proxy, wrappers.getListener());
+			assertEquals(propertyName, wrappers.getPropertyName());
+		}
+
+		support.addVetoableChangeListener(propertyName, proxy);
+		{
+			assertTrue(support.hasListeners(propertyName));
+			assertFalse(support.hasListeners("text"));
+
+			VetoableChangeListener[] listeners1 = support
+					.getVetoableChangeListeners();
+			VetoableChangeListener[] listeners2 = support
+					.getVetoableChangeListeners(propertyName);
+			VetoableChangeListener[] listeners3 = support
+					.getVetoableChangeListeners("text");
+
+			assertEquals(0, listeners3.length);
+			assertEquals(2, listeners1.length);
+			assertEquals(2, listeners2.length);
+			for (int i = 0; i < listeners2.length; i++) {
+				assertSame(proxy, listeners2[i]);
+				VetoableChangeListenerProxy wrappers = (VetoableChangeListenerProxy) listeners1[i];
+				assertSame(proxy, wrappers.getListener());
+				assertEquals(propertyName, wrappers.getPropertyName());
+			}
+		}
+	}
+
+	/*
+	 * add listener with null property name.
+	 */
+	public void testAddVetoableChangeListenerStringVetoableChangeListener_property_null() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		String propertyName = null;
+		try {
+			support.addVetoableChangeListener(propertyName, proxy);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	/*
+	 * add listeners to an invalid property
+	 */
+	public void testAddVetoableChangeListenerStringVetoableChangeListener_property_invalid() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		String propertyName = "label_invalid";
+		support.addVetoableChangeListener(propertyName, proxy);
+
+		VetoableChangeListener[] listeners1 = support
+				.getVetoableChangeListeners();
+		VetoableChangeListener[] listeners2 = support
+				.getVetoableChangeListeners("label_invalid");
+		assertEquals(1, listeners1.length);
+		assertEquals(1, listeners2.length);
+		assertEquals("label_invalid",
+				((VetoableChangeListenerProxy) listeners1[0]).getPropertyName());
+		assertSame(proxy, listeners2[0]);
+		assertFalse(support.hasListeners("label"));
+	}
+
+	/*
+	 * add different listener with a particular property name.
+	 */
+	public void testAddVetoableChangeListenerStringVetoableChangeListener_property_duplicate() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		VetoableChangeListener proxy2 = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		String propertyName = "label";
+		support.addVetoableChangeListener(propertyName, proxy);
+		support.addVetoableChangeListener(propertyName, proxy2);
+
+		assertTrue(support.hasListeners(propertyName));
+		assertFalse(support.hasListeners("text"));
+
+		VetoableChangeListener[] listeners1 = support
+				.getVetoableChangeListeners();
+		VetoableChangeListener[] listeners2 = support
+				.getVetoableChangeListeners(propertyName);
+		VetoableChangeListener[] listeners3 = support
+				.getVetoableChangeListeners("text");
+
+		assertEquals(0, listeners3.length);
+		assertEquals(2, listeners1.length);
+		assertEquals(2, listeners2.length);
+		for (int i = 0; i < listeners2.length; i++) {
+			assertTrue((proxy == listeners2[i]) || (proxy2 == listeners2[i]));
+			VetoableChangeListenerProxy wrappers = (VetoableChangeListenerProxy) listeners1[i];
+			assertTrue((proxy == wrappers.getListener())
+					|| (proxy2 == wrappers.getListener()));
+			assertEquals(propertyName, wrappers.getPropertyName());
+		}
+	}
+
+	/*
+	 * Class under test for void
+	 * addVetoableChangeListener(VetoableChangeListener)
+	 */
+	public void testAddVetoableChangeListenerVetoableChangeListener() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener(proxy);
+
+		assertTrue(support.hasListeners("label"));
+		assertTrue(support.hasListeners("text"));
+
+		VetoableChangeListener[] listeners1 = support
+				.getVetoableChangeListeners();
+		VetoableChangeListener[] listeners2 = support
+				.getVetoableChangeListeners("label");
+		VetoableChangeListener[] listeners3 = support
+				.getVetoableChangeListeners("text");
+
+		assertEquals(1, listeners1.length);
+		assertEquals(0, listeners2.length);
+		assertEquals(0, listeners3.length);
+
+		assertSame(proxy, listeners1[0]);
+	}
+
+	/*
+	 * add a null listener
+	 */
+	public void testAddVetoableChangeListenerVetoableChangeListener_null() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+		support.addVetoableChangeListener(null);
+
+		assertTrue(support.hasListeners("label"));
+		assertTrue(support.hasListeners("text"));
+
+		VetoableChangeListener[] listeners1 = support
+				.getVetoableChangeListeners();
+		VetoableChangeListener[] listeners2 = support
+				.getVetoableChangeListeners("label");
+		VetoableChangeListener[] listeners3 = support
+				.getVetoableChangeListeners("text");
+
+		assertEquals(1, listeners1.length);
+		assertEquals(0, listeners2.length);
+		assertEquals(0, listeners3.length);
+
+		assertNull(listeners1[0]);
+	}
+
+	/*
+	 * add duplicated listeners
+	 */
+	public void testAddVetoableChangeListenerVetoableChangeListener_duplicate() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener(proxy);
+		support.addVetoableChangeListener(proxy);
+
+		assertTrue(support.hasListeners("label"));
+		assertTrue(support.hasListeners("text"));
+
+		VetoableChangeListener[] listeners1 = support
+				.getVetoableChangeListeners();
+		VetoableChangeListener[] listeners2 = support
+				.getVetoableChangeListeners("label");
+		VetoableChangeListener[] listeners3 = support
+				.getVetoableChangeListeners("text");
+
+		assertEquals(2, listeners1.length);
+		assertEquals(0, listeners2.length);
+		assertEquals(0, listeners3.length);
+		for (int i = 0; i < listeners1.length; i++) {
+			assertSame(proxy, listeners1[i]);
+		}
+	}
+
+	/*
+	 * add two different listeners
+	 */
+	public void testAddVetoableChangeListenerVetoableChangeListener_TwoDifferent() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		VetoableChangeListener proxy2 = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "getText");
+		support.addVetoableChangeListener(proxy);
+		support.addVetoableChangeListener(proxy2);
+
+		assertTrue(support.hasListeners("label"));
+		assertTrue(support.hasListeners("text"));
+
+		VetoableChangeListener[] listeners1 = support
+				.getVetoableChangeListeners();
+		VetoableChangeListener[] listeners2 = support
+				.getVetoableChangeListeners("label");
+		VetoableChangeListener[] listeners3 = support
+				.getVetoableChangeListeners("text");
+
+		assertEquals(2, listeners1.length);
+		assertEquals(0, listeners2.length);
+		assertEquals(0, listeners3.length);
+		for (int i = 0; i < listeners1.length; i++) {
+			assertTrue((proxy == listeners1[i]) || (proxy2 == listeners1[i]));
+		}
+	}
+
+	/*
+	 * add a VetoableChangeListenerProxy
+	 */
+	public void testAddVetoableChangeListenerVetoableChangeListener_Proxy() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		proxy = new MockVetoableChangeListener();
+		String propertyName = "label";
+
+		VetoableChangeListenerProxy listenerProxy = new VetoableChangeListenerProxy(
+				propertyName, proxy);
+
+		support.addVetoableChangeListener(listenerProxy);
+
+		assertTrue(support.hasListeners(propertyName));
+		assertFalse(support.hasListeners("text"));
+		{
+			VetoableChangeListener[] listeners1 = support
+					.getVetoableChangeListeners();
+			VetoableChangeListener[] listeners2 = support
+					.getVetoableChangeListeners(propertyName);
+			VetoableChangeListener[] listeners3 = support
+					.getVetoableChangeListeners("text");
+
+			assertEquals(0, listeners3.length);
+			assertEquals(1, listeners1.length);
+			assertEquals(1, listeners2.length);
+
+			assertSame(proxy, listeners2[0]);
+			VetoableChangeListenerProxy wrappers = (VetoableChangeListenerProxy) listeners1[0];
+			assertSame(proxy, wrappers.getListener());
+			assertEquals(propertyName, wrappers.getPropertyName());
+		}
+		// add test for remove proxy
+		support.removeVetoableChangeListener(listenerProxy);
+		{
+			VetoableChangeListener[] listeners1 = support
+					.getVetoableChangeListeners();
+			VetoableChangeListener[] listeners2 = support
+					.getVetoableChangeListeners(propertyName);
+			assertEquals(0, listeners1.length);
+			assertEquals(0, listeners2.length);
+		}
+
+	}
+
+	/*
+	 * Class under test for void fireVetoableChange(PropertyChangeEvent)
+	 */
+	public void testFireVetoableChangePropertyChangeEvent()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener(proxy);
+		PropertyChangeEvent event = new PropertyChangeEvent(source, "label",
+				"Label: old", "Label: new");
+		support.fireVetoableChange(event);
+
+		assertEquals("called", source.getText());
+	}
+
+	public void testFireVetoableChangePropertyChangeEvent_Veto()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		MockVetoListener normal1 = new MockVetoListener(false, "Norm1");
+		support.addVetoableChangeListener(normal1);
+
+		MockVetoListener veto1 = new MockVetoListener(true, "Veto1");
+		support.addVetoableChangeListener(veto1);
+
+		MockVetoListener normal2 = new MockVetoListener(false, "Norm2");
+		support.addVetoableChangeListener(normal2);
+
+		MockVetoListener veto2 = new MockVetoListener(true, "Veto2");
+		support.addVetoableChangeListener(veto2);
+
+		PropertyChangeEvent event = new PropertyChangeEvent(source, "label",
+				"1", "5");
+		try {
+			support.fireVetoableChange(event);
+		} catch (PropertyVetoException e) {
+
+		}
+
+		assertEquals(4, support.getVetoableChangeListeners().length);
+
+		// Check the calling status of the first listener
+		{
+			ArrayList oldValues = normal1.getOldValues();
+			assertEquals(2, oldValues.size());
+			assertEquals("1", oldValues.get(0));
+			assertEquals("5", oldValues.get(1));
+
+			ArrayList newValues = normal1.getNewValues();
+			assertEquals(2, newValues.size());
+			assertEquals("5", newValues.get(0));
+			assertEquals("1", newValues.get(1));
+		}
+
+		// Check the status of the second (Veto) listeners
+		{
+			ArrayList oldValues = veto1.getOldValues();
+			assertEquals(2, oldValues.size());
+			assertEquals("1", oldValues.get(0));
+			assertEquals("5", oldValues.get(1));
+
+			ArrayList newValues = veto1.getNewValues();
+			assertEquals(2, newValues.size());
+			assertEquals("5", newValues.get(0));
+			assertEquals("1", newValues.get(1));
+		}
+
+		// Check the status of the third listeners
+		{
+			ArrayList oldValues = normal2.getOldValues();
+			assertEquals(1, oldValues.size());
+			assertEquals("5", oldValues.get(0));
+
+			ArrayList newValues = normal2.getNewValues();
+			assertEquals(1, newValues.size());
+			assertEquals("1", newValues.get(0));
+		}
+
+		// Check the status of the fourth (Veto) listeners
+		{
+			ArrayList oldValues = veto2.getOldValues();
+			assertEquals(1, oldValues.size());
+			assertEquals("5", oldValues.get(0));
+
+			ArrayList newValues = veto2.getNewValues();
+			assertEquals(1, newValues.size());
+			assertEquals("1", newValues.get(0));
+		}
+	}
+
+	/*
+	 * fire a null event
+	 */
+	public void testFireVetoableChangePropertyChangeEvent_null()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener(proxy);
+		try {
+			support.fireVetoableChange(null);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * register for one property
+	 */
+	public void testFireVetoableChangePropertyChangeEvent_property()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		String propertyName = "label";
+		support.addVetoableChangeListener(propertyName, proxy);
+		PropertyChangeEvent event = new PropertyChangeEvent(source, "label",
+				"Label: old", "Label: new");
+		support.fireVetoableChange(event);
+
+		assertEquals("called", source.getText());
+	}
+
+	public void testFireVetoableChangePropertyChangeEvent_property_invalid()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		String propertyName = "label_invalid";
+		support.addVetoableChangeListener(propertyName, proxy);
+		PropertyChangeEvent event = new PropertyChangeEvent(source, "label",
+				"Label: old", "Label: new");
+		support.fireVetoableChange(event);
+
+		assertEquals("text.default", source.getText());
+	}
+
+	/*
+	 * there are two same listeners, and another different listener.
+	 */
+	public void testFireVetoableChangePropertyChangeEvent_DuplicateListener()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "increaseTop");
+		VetoableChangeListener proxy2 = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		support.addVetoableChangeListener(proxy);
+		support.addVetoableChangeListener(proxy);
+		support.addVetoableChangeListener(proxy2);
+
+		PropertyChangeEvent event = new PropertyChangeEvent(source, "label",
+				"Label: old", "Label: new");
+		support.fireVetoableChange(event);
+		assertEquals(2, source.getTop());
+		assertEquals("called", source.getText());
+	}
+
+	/*
+	 * listener is null
+	 */
+	public void testFireVetoableChangePropertyChangeEvent_listener_null()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		support.addVetoableChangeListener(null);
+		PropertyChangeEvent event = new PropertyChangeEvent(source, "label",
+				"Label: old", "Label: new");
+		try {
+			support.fireVetoableChange(event);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Class under test for void fireVetoableChange(String, boolean, boolean)
+	 */
+	public void testFireVetoableChangeStringbooleanboolean()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener(proxy);
+		support.fireVetoableChange("label", true, false);
+
+		assertEquals("called", source.getText());
+	}
+
+	/*
+	 * register a null listener
+	 */
+	public void testFireVetoableChangeStringbooleanboolean_listener_null()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		support.addVetoableChangeListener(null);
+		try {
+			support.fireVetoableChange("label", true, false);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * register listener for property "label".
+	 */
+	public void testFireVetoableChangeStringbooleanboolean_property()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener("label", proxy);
+		support.fireVetoableChange("label", true, false);
+
+		assertEquals("called", source.getText());
+	}
+
+	/*
+	 * register a null listener
+	 */
+	public void testFireVetoableChangeStringbooleanboolean_listener_null_property()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener("label", null);
+		try {
+			support.fireVetoableChange("label", true, false);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * two different listeners registered for all
+	 */
+	public void testFireVetoableChangeStringbooleanboolean_twoListeners()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		VetoableChangeListener proxy2 = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "increaseTop");
+		support.addVetoableChangeListener(proxy);
+		support.addVetoableChangeListener(proxy2);
+
+		support.fireVetoableChange("label", true, false);
+
+		assertEquals("called", source.getText());
+		assertEquals(1, source.getTop());
+	}
+
+	/*
+	 * two different listeners registered for property "label"
+	 */
+	public void testFireVetoableChangeStringbooleanboolean_property_twoListeners()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		VetoableChangeListener proxy2 = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "increaseTop");
+		support.addVetoableChangeListener("label", proxy);
+		support.addVetoableChangeListener("label", proxy2);
+
+		support.fireVetoableChange("label", true, false);
+
+		assertEquals("called", source.getText());
+		assertEquals(1, source.getTop());
+	}
+
+	/*
+	 * null propertyname
+	 */
+	public void testFireVetoableChangeStringbooleanboolean_Property_null()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "label",
+						"source.text");
+		support.addVetoableChangeListener(proxy);
+		support.fireVetoableChange(null, true, false);
+		assertEquals(source.getText(), source.getLabel());
+	}
+
+	/*
+	 * register listener to label.
+	 */
+	public void testFireVetoableChangeStringbooleanboolean_listener_Property_null()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "label",
+						"source.text");
+		support.addVetoableChangeListener("label", proxy);
+		support.fireVetoableChange(null, true, false);
+		assertEquals("label.default", source.getLabel());
+	}
+
+	/*
+	 * register a null listener
+	 */
+	public void testFireVetoableChangeStringbooleanboolean_listener_Null_Property_null()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "label",
+						"source.text");
+		support.addVetoableChangeListener("label", proxy);
+		support.fireVetoableChange(null, true, false);
+		assertEquals("label.default", source.getLabel());
+	}
+
+	/*
+	 * invalid propertyname
+	 */
+	public void testFireVetoableChangeStringbooleanboolean_Property_invalid()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "label",
+						"source.text");
+		support.addVetoableChangeListener(proxy);
+		String newText = "new Text value";
+		source.setText(newText);
+
+		support.fireVetoableChange("label_invalid", true, false);
+		assertEquals(newText, source.getLabel());
+	}
+
+	/*
+	 * register listener for lablel property
+	 */
+	public void testFireVetoableChangeStringbooleanboolean_listener_Property_invalid()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "label",
+						"source.text");
+		support.addVetoableChangeListener("label", proxy);
+		String newText = "new Text value";
+		source.setText(newText);
+
+		support.fireVetoableChange("text", true, false);
+		assertEquals("label.default", source.getLabel());
+
+		support.fireVetoableChange("label_invalid", true, false);
+		assertEquals("label.default", source.getLabel());
+
+		support.fireVetoableChange("label", true, false);
+		assertEquals(newText, source.getLabel());
+	}
+
+	/*
+	 * oldvalue==newValue
+	 */
+	public void testFireVetoableChangeStringbooleanboolean_SameValue()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener(proxy);
+
+		support.fireVetoableChange("label", true, true);
+		assertEquals("text.default", source.getText());
+	}
+
+	/*
+	 * Class under test for void fireVetoableChange(String, int, int)
+	 * 
+	 * register listener for all
+	 */
+	public void testFireVetoableChangeStringintint()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener(proxy);
+		support.fireVetoableChange("label", 1, 2);
+
+		assertEquals("called", source.getText());
+	}
+
+	/*
+	 * Propertyname is null register listener for all
+	 */
+	public void testFireVetoableChangeStringintint_property_null()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener(proxy);
+		support.fireVetoableChange(null, 1, 2);
+
+		assertEquals("called", source.getText());
+	}
+
+	/*
+	 * property name is invalid register listener for all
+	 */
+	public void testFireVetoableChangeStringintint_property_Invalid()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener(proxy);
+		support.fireVetoableChange("label_invalide", 1, 2);
+
+		assertEquals("called", source.getText());
+	}
+
+	/*
+	 * oldvalue=newVlaue register listener for all
+	 */
+	public void testFireVetoableChangeStringintint_SameValue()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener(proxy);
+		support.fireVetoableChange("label", 1, 1);
+
+		assertEquals("text.default", source.getText());
+	}
+
+	/*
+	 * Class under test for void fireVetoableChange(String, int, int)
+	 * 
+	 * register listener for one property - "label"
+	 */
+	public void testFireVetoableChangeStringintint_listener()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener("label", proxy);
+		support.fireVetoableChange("label", 1, 2);
+		assertEquals("called", source.getText());
+	}
+
+	/*
+	 * Propertyname is null register listener for one property - "label"
+	 */
+	public void testFireVetoableChangeStringintint_listener_property_null()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener("label", proxy);
+		support.fireVetoableChange(null, 1, 2);
+
+		assertEquals("text.default", source.getText());
+	}
+
+	/*
+	 * property name is invalid register listener for one property - "label"
+	 */
+	public void testFireVetoableChangeStringintint_listener_property_Invalid()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener("label", proxy);
+		support.fireVetoableChange("label_invalide", 1, 2);
+
+		assertEquals("text.default", source.getText());
+	}
+
+	/*
+	 * oldvalue=newVlaue register listener for one property - "label"
+	 */
+	public void testFireVetoableChangeStringintint_listener_SameValue()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener("label", proxy);
+		support.fireVetoableChange("label", 1, 1);
+
+		assertEquals("text.default", source.getText());
+	}
+
+	public void testFireVetoableChangeStringintint_listener_Invalid_property()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener("label_invalid", proxy);
+		support.fireVetoableChange("label", 1, 2);
+
+		assertEquals("text.default", source.getText());
+	}
+
+	/*
+	 * Class under test for void fireVetoableChange(String, Object, Object)
+	 * 
+	 * register listener for all
+	 */
+	public void testFireVetoableChangeStringObjectObject()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener(proxy);
+		support.fireVetoableChange("label", "Label: old", "Label: new");
+		assertEquals("called", source.getText());
+	}
+
+	/*
+	 * property name is null. register listener for all
+	 */
+	public void testFireVetoableChangeStringObjectObject_property_Null()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener(proxy);
+		support.fireVetoableChange(null, "Label: old", "Label: new");
+		assertEquals("called", source.getText());
+	}
+
+	/*
+	 * property name is invalid. register listener for all
+	 */
+	public void testFireVetoableChangeStringObjectObject_property_invalid()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener(proxy);
+		support.fireVetoableChange("label_invalid", "Label: old", "Label: new");
+		assertEquals("called", source.getText());
+	}
+
+	/*
+	 * oldValue=NewValue. register listener for all
+	 */
+	public void testFireVetoableChangeStringObjectObject_SameValue()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener(proxy);
+		support.fireVetoableChange("label", "Label: old", "Label: old");
+		assertEquals("text.default", source.getText());
+	}
+
+	/*
+	 * oldValue=NewValue=null. register listener for all
+	 */
+	public void testFireVetoableChangeStringObjectObject_SameValue_null()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener(proxy);
+		support.fireVetoableChange("label", null, null);
+		assertEquals("called", source.getText());
+	}
+
+	/*
+	 * Class under test for void fireVetoableChange(String, Object, Object)
+	 * 
+	 * register listener for one property - "label"
+	 */
+	public void testFireVetoableChangeStringObjectObject_listener()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener("label", proxy);
+		support.fireVetoableChange("label", "Label: old", "Label: new");
+		assertEquals("called", source.getText());
+	}
+
+	/*
+	 * property name is null. register listener for one property - "label"
+	 */
+	public void testFireVetoableChangeStringObjectObject_listener_property_Null()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener("label", proxy);
+		support.fireVetoableChange(null, "Label: old", "Label: new");
+		assertEquals("text.default", source.getText());
+	}
+
+	/*
+	 * property name is invalid. register listener for one property - "label"
+	 */
+	public void testFireVetoableChangeStringObjectObject_listener_property_invalid()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener("label", proxy);
+		support.fireVetoableChange("label_invalid", "Label: old", "Label: new");
+		assertEquals("text.default", source.getText());
+	}
+
+	/*
+	 * oldValue=NewValue. register listener for one property - "label"
+	 */
+	public void testFireVetoableChangeStringObjectObject_listener_SameValue()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener(proxy);
+		support.fireVetoableChange("label", "Label: old", "Label: old");
+		assertEquals("text.default", source.getText());
+	}
+
+	/*
+	 * oldValue=NewValue=null. register listener for one property - "label"
+	 */
+	public void testFireVetoableChangeStringObjectObject_listener_SameValue_null()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener("label", proxy);
+		support.fireVetoableChange("label", null, null);
+		assertEquals("called", source.getText());
+	}
+
+	/*
+	 * register listener to an invalid property
+	 */
+	public void testFireVetoableChangeStringObjectObject_listener_invalid()
+			throws PropertyVetoException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		support.addVetoableChangeListener("label_invalid", proxy);
+		support.fireVetoableChange("label", "1", "2");
+		assertEquals("text.default", source.getText());
+	}
+
+	/*
+	 * Class under test for void removeVetoableChangeListener(String,
+	 * VetoableChangeListener)
+	 * 
+	 * register listener for property
+	 */
+	public void testRemoveVetoableChangeListenerStringVetoableChangeListener_property() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		String propertyName = "label";
+		support.addVetoableChangeListener(propertyName, proxy);
+		assertTrue(support.hasListeners(propertyName));
+
+		support.removeVetoableChangeListener(propertyName, proxy);
+		assertFalse(support.hasListeners(propertyName));
+		assertEquals(0, support.getVetoableChangeListeners(propertyName).length);
+		assertEquals(0, support.getVetoableChangeListeners().length);
+	}
+
+	/*
+	 * register listener for property, two same listeners
+	 */
+	public void testRemoveVetoableChangeListenerStringVetoableChangeListener_property_more() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		String propertyName = "label";
+		support.addVetoableChangeListener(propertyName, proxy);
+		support.addVetoableChangeListener(propertyName, proxy);
+
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(2, support.getVetoableChangeListeners(propertyName).length);
+
+		support.removeVetoableChangeListener(propertyName, proxy);
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(1, support.getVetoableChangeListeners(propertyName).length);
+		assertEquals(1, support.getVetoableChangeListeners().length);
+	}
+
+	/*
+	 * register listener for property, two different listeners
+	 */
+	public void testRemoveVetoableChangeListenerStringVetoableChangeListener_property_diff() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		VetoableChangeListener proxy2 = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "getText");
+
+		String propertyName = "label";
+		support.addVetoableChangeListener(propertyName, proxy);
+		support.addVetoableChangeListener(propertyName, proxy2);
+
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(2, support.getVetoableChangeListeners(propertyName).length);
+
+		support.removeVetoableChangeListener(propertyName, proxy);
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(1, support.getVetoableChangeListeners(propertyName).length);
+		assertEquals(1, support.getVetoableChangeListeners().length);
+		assertSame(proxy2, support.getVetoableChangeListeners(propertyName)[0]);
+	}
+
+	/*
+	 * register listener for property, two different listeners
+	 */
+	public void testRemoveVetoableChangeListenerStringVetoableChangeListener_listener_diff() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		VetoableChangeListener proxy2 = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "getText");
+
+		String propertyName = "label";
+		support.addVetoableChangeListener(propertyName, proxy);
+
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(1, support.getVetoableChangeListeners(propertyName).length);
+
+		support.removeVetoableChangeListener(propertyName, proxy2);
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(1, support.getVetoableChangeListeners(propertyName).length);
+		assertEquals(1, support.getVetoableChangeListeners().length);
+	}
+
+	public void testRemoveVetoableChangeListenerStringVetoableChangeListener_listener_null() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		String propertyName = "label";
+		support.addVetoableChangeListener(propertyName, null);
+
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(1, support.getVetoableChangeListeners(propertyName).length);
+
+		support.removeVetoableChangeListener(propertyName, proxy);
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(1, support.getVetoableChangeListeners(propertyName).length);
+		assertEquals(1, support.getVetoableChangeListeners().length);
+		assertNull(support.getVetoableChangeListeners(propertyName)[0]);
+	}
+
+	/*
+	 * register listener for property.
+	 */
+	public void testRemoveVetoableChangeListenerStringVetoableChangeListener_all() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		String propertyName = "label";
+		support.addVetoableChangeListener(proxy);
+		assertTrue(support.hasListeners(propertyName));
+
+		support.removeVetoableChangeListener(propertyName, proxy);
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(0, support.getVetoableChangeListeners(propertyName).length);
+		assertEquals(1, support.getVetoableChangeListeners().length);
+	}
+
+	/*
+	 * remove listener from null property
+	 */
+	public void testRemoveVetoableChangeListenerStringVetoableChangeListener_propertyName_Null() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		String propertyName = "label";
+		support.addVetoableChangeListener(propertyName, proxy);
+		assertTrue(support.hasListeners(propertyName));
+		try {
+			support.removeVetoableChangeListener(null, proxy);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * propertyname is invalid
+	 */
+	public void testRemoveVetoableChangeListenerStringVetoableChangeListener_propertyName_Invalid() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		String propertyName = "label";
+		support.addVetoableChangeListener(propertyName, proxy);
+		assertTrue(support.hasListeners(propertyName));
+
+		support.removeVetoableChangeListener(propertyName + "_invalid", proxy);
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(1, support.getVetoableChangeListeners(propertyName).length);
+		assertEquals(1, support.getVetoableChangeListeners().length);
+	}
+
+	/*
+	 * no listener attached to the property
+	 */
+	public void testRemoveVetoableChangeListenerStringVetoableChangeListener_propertyName_NoListener() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		String propertyName = "label";
+		assertFalse(support.hasListeners(propertyName));
+
+		support.removeVetoableChangeListener(propertyName, proxy);
+		assertFalse(support.hasListeners(propertyName));
+		assertEquals(0, support.getVetoableChangeListeners(propertyName).length);
+		assertEquals(0, support.getVetoableChangeListeners().length);
+	}
+
+	/*
+	 * listener null
+	 */
+	public void testRemoveVetoableChangeListenerStringVetoableChangeListener_listener_null_null() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		String propertyName = "label";
+		support.addVetoableChangeListener(propertyName, null);
+		assertTrue(support.hasListeners(propertyName));
+
+		support.removeVetoableChangeListener(propertyName, null);
+		assertFalse(support.hasListeners(propertyName));
+		assertEquals(0, support.getVetoableChangeListeners(propertyName).length);
+		assertEquals(0, support.getVetoableChangeListeners().length);
+	}
+
+	/*
+	 * Class under test for void
+	 * removeVetoableChangeListener(VetoableChangeListener)
+	 * 
+	 * register listener for all
+	 */
+	public void testRemoveVetoableChangeListenerVetoableChangeListener_all() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		String propertyName = "label";
+		support.addVetoableChangeListener(proxy);
+		assertTrue(support.hasListeners(propertyName));
+
+		support.removeVetoableChangeListener(proxy);
+		assertFalse(support.hasListeners(propertyName));
+		assertEquals(0, support.getVetoableChangeListeners(propertyName).length);
+		assertEquals(0, support.getVetoableChangeListeners().length);
+	}
+
+	/*
+	 * two same listeners
+	 */
+	public void testRemoveVetoableChangeListenerVetoableChangeListener_all_more() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		String propertyName = "label";
+		support.addVetoableChangeListener(proxy);
+		support.addVetoableChangeListener(proxy);
+
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(2, support.getVetoableChangeListeners().length);
+
+		support.removeVetoableChangeListener(proxy);
+
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(0, support.getVetoableChangeListeners(propertyName).length);
+		assertEquals(1, support.getVetoableChangeListeners().length);
+	}
+
+	/*
+	 * two different listeners
+	 */
+	public void testRemoveVetoableChangeListenerVetoableChangeListener_all_more_diff() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+		VetoableChangeListener proxy2 = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "getText");
+
+		String propertyName = "label";
+		support.addVetoableChangeListener(proxy);
+		support.addVetoableChangeListener(proxy2);
+
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(2, support.getVetoableChangeListeners().length);
+
+		support.removeVetoableChangeListener(proxy);
+
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(0, support.getVetoableChangeListeners(propertyName).length);
+		assertEquals(1, support.getVetoableChangeListeners().length);
+		assertEquals(proxy2, support.getVetoableChangeListeners()[0]);
+	}
+
+	/*
+	 * listener null
+	 */
+	public void testRemoveVetoableChangeListenerVetoableChangeListener_all_null() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		String propertyName = "label";
+		support.addVetoableChangeListener(null);
+
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(1, support.getVetoableChangeListeners().length);
+
+		support.removeVetoableChangeListener(proxy);
+
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(0, support.getVetoableChangeListeners(propertyName).length);
+		assertEquals(1, support.getVetoableChangeListeners().length);
+	}
+
+	/*
+	 * register for one property
+	 */
+	public void testRemoveVetoableChangeListenerVetoableChangeListener_property() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		String propertyName = "label";
+		support.addVetoableChangeListener("label", proxy);
+
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(1, support.getVetoableChangeListeners().length);
+
+		support.removeVetoableChangeListener(proxy);
+
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(1, support.getVetoableChangeListeners(propertyName).length);
+		assertEquals(1, support.getVetoableChangeListeners().length);
+	}
+
+	/*
+	 * listener null
+	 */
+	public void testRemoveVetoableChangeListenerVetoableChangeListener_null() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		String propertyName = "label";
+		support.addVetoableChangeListener(proxy);
+
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(1, support.getVetoableChangeListeners().length);
+
+		support.removeVetoableChangeListener(null);
+
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(0, support.getVetoableChangeListeners(propertyName).length);
+		assertEquals(1, support.getVetoableChangeListeners().length);
+	}
+
+	/*
+	 * register null listener, remove null listener.
+	 */
+	public void testRemoveVetoableChangeListenerVetoableChangeListener_null_null() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		String propertyName = "label";
+		support.addVetoableChangeListener(null);
+
+		assertTrue(support.hasListeners(propertyName));
+		assertEquals(1, support.getVetoableChangeListeners().length);
+
+		support.removeVetoableChangeListener(null);
+
+		assertFalse(support.hasListeners(propertyName));
+		assertEquals(0, support.getVetoableChangeListeners(propertyName).length);
+		assertEquals(0, support.getVetoableChangeListeners().length);
+	}
+
+	/*
+	 * no this listener
+	 */
+	public void testRemoveVetoableChangeListenerVetoableChangeListener_invalid() {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		VetoableChangeListener proxy = (VetoableChangeListener) EventHandler
+				.create(VetoableChangeListener.class, source, "setText");
+
+		String propertyName = "label";
+		assertFalse(support.hasListeners(propertyName));
+		assertEquals(0, support.getVetoableChangeListeners().length);
+
+		support.removeVetoableChangeListener(proxy);
+
+		assertFalse(support.hasListeners(propertyName));
+		assertEquals(0, support.getVetoableChangeListeners(propertyName).length);
+		assertEquals(0, support.getVetoableChangeListeners().length);
+	}
+
+	public void testSerialization() throws IOException, ClassNotFoundException {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		String propertyName1 = "text";
+		SerializedVCListener serialized = new SerializedVCListener(
+				propertyName1);
+		support.addVetoableChangeListener(propertyName1, serialized);
+
+		String propertyName2 = "top";
+		NonSerializedVCListener nonSerialized = new NonSerializedVCListener(
+				propertyName2);
+		support.addVetoableChangeListener(propertyName2, nonSerialized);
+
+		assertTrue(support.hasListeners(propertyName1));
+		assertTrue(support.hasListeners(propertyName2));
+		assertEquals(2, support.getVetoableChangeListeners().length);
+		assertEquals(1,
+				support.getVetoableChangeListeners(propertyName1).length);
+		assertEquals(1,
+				support.getVetoableChangeListeners(propertyName2).length);
+
+		VetoableChangeSupport deserializedSupport = (VetoableChangeSupport) SerializationTester
+				.getDeserilizedObject(support);
+
+		assertTrue(deserializedSupport.hasListeners(propertyName1));
+		assertFalse(deserializedSupport.hasListeners(propertyName2));
+		assertEquals(1, deserializedSupport.getVetoableChangeListeners().length);
+		assertEquals(1, deserializedSupport
+				.getVetoableChangeListeners(propertyName1).length);
+		assertEquals(0, deserializedSupport
+				.getVetoableChangeListeners(propertyName2).length);
+
+		assertEquals(
+				support.getVetoableChangeListeners(propertyName1)[0],
+				deserializedSupport.getVetoableChangeListeners(propertyName1)[0]);
+
+	}
+
+	public void testSerialization_Compatibility() throws Exception {
+		MockSource source = new MockSource();
+		VetoableChangeSupport support = new VetoableChangeSupport(source);
+
+		String propertyName1 = "text";
+		SerializedVCListener serialized = new SerializedVCListener(
+				propertyName1);
+		support.addVetoableChangeListener(propertyName1, serialized);
+
+		String propertyName2 = "top";
+		NonSerializedVCListener nonSerialized = new NonSerializedVCListener(
+				propertyName2);
+		support.addVetoableChangeListener(propertyName2, nonSerialized);
+
+		assertTrue(support.hasListeners(propertyName1));
+		assertTrue(support.hasListeners(propertyName2));
+		assertEquals(2, support.getVetoableChangeListeners().length);
+		assertEquals(1,
+				support.getVetoableChangeListeners(propertyName1).length);
+		assertEquals(1,
+				support.getVetoableChangeListeners(propertyName2).length);
+
+		VetoableChangeSupport deserializedSupport = (VetoableChangeSupport) SerializationTester
+				.readObject(support,
+						"tests/api/java/beans/VetoableChangeSupport.ser");
+
+		assertTrue(deserializedSupport.hasListeners(propertyName1));
+		assertFalse(deserializedSupport.hasListeners(propertyName2));
+		assertEquals(1, deserializedSupport.getVetoableChangeListeners().length);
+		assertEquals(1, deserializedSupport
+				.getVetoableChangeListeners(propertyName1).length);
+		assertEquals(0, deserializedSupport
+				.getVetoableChangeListeners(propertyName2).length);
+
+		assertEquals(
+				support.getVetoableChangeListeners(propertyName1)[0],
+				deserializedSupport.getVetoableChangeListeners(propertyName1)[0]);
+	}
+
+	public static class MockSource implements Serializable {
+		private String name;
+
+		private String text;
+
+		private String label;
+
+		private int top;
+
+		private boolean visible;
+
+		public MockSource() {
+			this.name = getClass().getName();
+			this.text = "text.default";
+			this.label = "label.default";
+		}
+
+		/**
+		 * @return Returns the name.
+		 */
+		public String getName() {
+			return name;
+		}
+
+		/**
+		 * @param name
+		 *            The name to set.
+		 */
+		public void setName(String name) {
+			this.name = name;
+		}
+
+		/**
+		 * @return Returns the text.
+		 */
+		public String getText() {
+			return text;
+		}
+
+		/**
+		 * @param text
+		 *            The text to set.
+		 */
+		public void setText(String text) {
+			this.text = text;
+		}
+
+		public void setText() {
+			this.text = "called";
+		}
+
+		/**
+		 * @return Returns the top.
+		 */
+		public int getTop() {
+			return top;
+		}
+
+		/**
+		 * @param top
+		 *            The top to set.
+		 */
+		public void setTop(int top) {
+			this.top = top;
+		}
+
+		public void increaseTop() {
+			this.top++;
+		}
+
+		/**
+		 * @return Returns the visible.
+		 */
+		public boolean isVisible() {
+			return visible;
+		}
+
+		/**
+		 * @param visible
+		 *            The visible to set.
+		 */
+		public void setVisible(boolean visible) {
+			this.visible = visible;
+		}
+
+		/**
+		 * @return Returns the label.
+		 */
+		public String getLabel() {
+			return label;
+		}
+
+		/**
+		 * @param label
+		 *            The label to set.
+		 */
+		public void setLabel(String label) {
+			this.label = label;
+		}
+	}
+
+	public static class MockVetoListener implements VetoableChangeListener {
+		ArrayList oldValues = new ArrayList();
+
+		ArrayList newValues = new ArrayList();
+
+		boolean veto;
+
+		String prefix;
+
+		public MockVetoListener(boolean veto, String prefix) {
+			this.veto = veto;
+			this.prefix = prefix;
+		}
+
+		public void vetoableChange(PropertyChangeEvent event)
+				throws PropertyVetoException {
+			oldValues.add(event.getOldValue());
+			newValues.add(event.getNewValue());
+
+			if (false) {
+				System.out.println(prefix + " old: " + event.getOldValue()
+						+ " new: " + event.getNewValue());
+			}
+			if (veto) {
+				throw new PropertyVetoException("Vete Change", event);
+			}
+		}
+
+		public ArrayList getOldValues() {
+			return this.oldValues;
+		}
+
+		public ArrayList getNewValues() {
+			return this.newValues;
+		}
+
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VisibilityTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VisibilityTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VisibilityTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VisibilityTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,49 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.beans;
+
+import java.beans.Visibility;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the signature of the interface Visibility.
+ */
+public class VisibilityTest extends TestCase {
+
+	public void testSignature() {
+		DummyVisibility o = new DummyVisibility();
+		assertTrue(o instanceof Visibility);
+	}
+
+	static class DummyVisibility implements Visibility {
+
+		public boolean avoidingGui() {
+			return false;
+		}
+
+		public void dontUseGui() {
+		}
+
+		public boolean needsGui() {
+			return false;
+		}
+
+		public void okToUseGui() {
+		}
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/XMLDecoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/XMLDecoderTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/XMLDecoderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/XMLDecoderTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,281 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.beans;
+
+import java.beans.ExceptionListener;
+import java.beans.XMLDecoder;
+import java.beans.XMLEncoder;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import junit.framework.TestCase;
+import tests.api.java.beans.EncoderTest.SampleBean;
+import tests.api.java.beans.XMLEncoderTest.DependencyBean;
+import tests.api.java.beans.mock.MockBean4Codec;
+import tests.api.java.beans.mock.MockExceptionListener;
+
+/**
+ * Tests XMLDecoder
+ */
+public class XMLDecoderTest extends TestCase {
+
+	public static void main(String[] args) {
+		junit.textui.TestRunner.run(XMLDecoderTest.class);
+	}
+
+	static byte xml123bytes[] = null;
+
+	static {
+		ByteArrayOutputStream byteout = new ByteArrayOutputStream();
+		XMLEncoder enc = new XMLEncoder(byteout);
+		enc.writeObject(Integer.valueOf("1"));
+		enc.writeObject(Integer.valueOf("2"));
+		enc.writeObject(Integer.valueOf("3"));
+		enc.close();
+		xml123bytes = byteout.toByteArray();
+	}
+
+	public void testClose() {
+		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
+		assertEquals(Integer.valueOf("1"), dec.readObject());
+
+		dec.close();
+
+		assertEquals(Integer.valueOf("2"), dec.readObject());
+		assertEquals(Integer.valueOf("3"), dec.readObject());
+	}
+
+	public void testGetExceptionListener() {
+		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
+		assertNotNull(dec.getExceptionListener());
+	}
+
+	public void testGetOwner() {
+		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
+		assertNull(dec.getOwner());
+	}
+
+	public void testReadObject_ArrayOutOfBounds() {
+		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
+		assertEquals(Integer.valueOf("1"), dec.readObject());
+		assertEquals(Integer.valueOf("2"), dec.readObject());
+		assertEquals(Integer.valueOf("3"), dec.readObject());
+
+		try {
+			dec.readObject();
+			fail();
+		} catch (ArrayIndexOutOfBoundsException e) {
+			// expected
+		}
+	}
+
+	public void testReadObject_Null() {
+		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
+				"null.xml"));
+		Object obj = dec.readObject();
+		assertNull(obj);
+	}
+
+	public void testReadObject_Integer() {
+		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
+				"int.xml"));
+		Object obj = dec.readObject();
+		assertEquals(Integer.valueOf("3"), obj);
+	}
+
+	public void testReadObject_StringCodec() {
+		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
+				"SampleBean_StringCodec.xml"));
+		SampleBean obj = (SampleBean) dec.readObject();
+		assertEquals("<Li Yang> & \"liyang'", obj.getMyid());
+		assertEquals("a child", obj.getRef().getMyid());
+	}
+
+	public void testReadObject_IntArray() {
+		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
+				"IntArray.xml"));
+		int ints[] = (int[]) dec.readObject();
+		assertEquals(1, ints[0]);
+		assertEquals(2, ints[1]);
+		assertEquals(3, ints[2]);
+	}
+
+	public void testReadObject_PropertyDependency() {
+		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
+				"DependencyBean.xml"));
+		DependencyBean b = (DependencyBean) dec.readObject();
+		assertEquals(888, b.getInts()[0]);
+		assertSame(b.getInts(), b.getRef());
+	}
+
+	public void testReadObject_NoChange() {
+		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
+				"MockBean4Codec_NoChange.xml"));
+		MockBean4Codec b = (MockBean4Codec) dec.readObject();
+	}
+
+	public void testReadObject_BornFriendChange() {
+		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
+				"MockBean4Codec_BornFriendChange.xml"));
+		MockBean4Codec b = (MockBean4Codec) dec.readObject();
+		assertEquals(888, b.getBornFriend().getZarr()[0]);
+		assertEquals(b.getBornFriend(), b.getNill());
+	}
+
+	public void testReadObject_ManyChanges() {
+		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
+				"MockBean4Codec_ManyChanges.xml"));
+		MockBean4Codec b = (MockBean4Codec) dec.readObject();
+		assertEquals(127, b.getB());
+		assertSame(b, b.getBackRef());
+		assertEquals(new Byte((byte) 127), b.getBobj());
+		assertEquals(false, b.isBool());
+		assertEquals(Boolean.TRUE, b.getBoolobj());
+		assertEquals(Exception.class, b.getBornFriend().getClazz());
+		assertEquals(888, b.getBornFriend().getZarr()[0]);
+		assertEquals('Z', b.getC());
+		assertEquals(String.class, b.getClazz());
+		assertEquals(new Character('z'), b.getCobj());
+		assertEquals(123.456, b.getD(), 0);
+		assertEquals(new Double(123.456), b.getDobj());
+		assertEquals(12.34F, b.getF(), 0);
+		assertEquals(new Float(12.34F), b.getFobj());
+		assertEquals(MockBean4Codec.class, b.getFriend().getClazz());
+		assertEquals(999, b.getI());
+		assertEquals(new Integer(999), b.getIobj());
+		assertEquals(8888888, b.getL());
+		assertEquals(new Long(8888888), b.getLobj());
+		assertEquals("Li Yang", b.getName());
+		assertNull(b.getNill());
+		assertEquals(55, b.getS());
+		assertEquals(new Short((short) 55), b.getSobj());
+		assertEquals(3, b.getZarr().length);
+		assertEquals(3, b.getZarr()[0]);
+		assertEquals(2, b.getZarr()[1]);
+		assertEquals(1, b.getZarr()[2]);
+		assertEquals(1, b.getZarrarr().length);
+		assertEquals(3, b.getZarrarr()[0].length);
+		assertEquals("6", b.getZarrarr()[0][0]);
+		assertEquals("6", b.getZarrarr()[0][1]);
+		assertEquals("6", b.getZarrarr()[0][2]);
+	}
+
+	public void testReadObject_StaticField() {
+		XMLDecoder dec1 = new XMLDecoder(this.getClass().getResourceAsStream(
+				"MockBean4StaticField_Original.xml"));
+		MockBean4StaticField o1 = (MockBean4StaticField) dec1.readObject();
+
+		XMLDecoder dec2 = new XMLDecoder(this.getClass().getResourceAsStream(
+				"MockBean4StaticField.xml"));
+		MockBean4StaticField o2 = (MockBean4StaticField) dec2.readObject();
+
+		if (!o1.equals(o2)) {
+			System.out
+					.println("Loading object with static field, original xml: "
+							+ o1.getV());
+			System.out.println("Loading object with static field, field xml: "
+					+ o2.getV());
+		}
+
+		assertEquals(o1, o2);
+	}
+
+	public void testReadObject_Owner() {
+		MockBean4Owner_Owner o1 = new MockBean4Owner_Owner();
+		XMLDecoder dec1 = new XMLDecoder(this.getClass().getResourceAsStream(
+				"MockBean4Owner_SetOwner.xml"), o1);
+		MockBean4Owner_Target t1 = (MockBean4Owner_Target) dec1.readObject();
+
+		assertEquals(o1.getV(), 1);
+		assertEquals(o1, t1.getV());
+	}
+
+	public void testReadObject_Owner_WithWriteStatement() {
+		MockBean4Owner_Owner o2 = new MockBean4Owner_Owner();
+		XMLDecoder dec2 = new XMLDecoder(this.getClass().getResourceAsStream(
+				"MockBean4Owner_SetOwnerWithWriteStatement.xml"), o2);
+		MockBean4Owner_Target t2 = (MockBean4Owner_Target) dec2.readObject();
+
+		assertEquals(o2.getV(), 999);
+		assertEquals(o2, t2.getV());
+	}
+
+	public void testSetExceptionListener() {
+		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
+		Object defaultL = dec.getExceptionListener();
+
+		dec.setExceptionListener(null);
+		assertSame(defaultL, dec.getExceptionListener());
+
+		ExceptionListener newL = new MockExceptionListener();
+		dec.setExceptionListener(newL);
+		assertSame(newL, dec.getExceptionListener());
+	}
+
+	public void testSetExceptionListener_CatchException() {
+		MockExceptionListener l = new MockExceptionListener();
+		XMLDecoder dec = new XMLDecoder(XMLDecoderTest.class
+				.getResourceAsStream("bad_int.xml"), null, l);
+		assertTrue(l.size() > 0);
+	}
+
+	public void testSetOwner() {
+		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
+		assertNull(dec.getOwner());
+
+		String owner = "owner";
+		dec.setOwner(owner);
+		assertSame(owner, dec.getOwner());
+
+		dec.setOwner(null);
+		assertNull(dec.getOwner());
+	}
+
+	/*
+	 * Class under test for void XMLDecoder(java.io.InputStream)
+	 */
+	public void testXMLDecoderInputStream() {
+		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
+		assertNull(dec.getOwner());
+		assertNotNull(dec.getExceptionListener());
+	}
+
+	/*
+	 * Class under test for void XMLDecoder(java.io.InputStream,
+	 * java.lang.Object)
+	 */
+	public void testXMLDecoderInputStreamObject() {
+		String owner = "owner";
+		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes),
+				owner);
+		assertSame(owner, dec.getOwner());
+		assertNotNull(dec.getExceptionListener());
+	}
+
+	/*
+	 * Class under test for void XMLDecoder(java.io.InputStream,
+	 * java.lang.Object, java.beans.ExceptionListener)
+	 */
+	public void testXMLDecoderInputStreamObjectExceptionListener() {
+		String owner = "owner";
+		MockExceptionListener l = new MockExceptionListener();
+		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes),
+				owner, l);
+		assertSame(owner, dec.getOwner());
+		assertSame(l, dec.getExceptionListener());
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/XMLEncoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/XMLEncoderTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/XMLEncoderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/XMLEncoderTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,410 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.beans;
+
+import java.beans.Expression;
+import java.beans.PersistenceDelegate;
+import java.beans.Statement;
+import java.beans.XMLEncoder;
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+
+import junit.framework.TestCase;
+import tests.api.java.beans.EncoderTest.SampleBean;
+import tests.api.java.beans.mock.MockBean4Codec;
+
+/**
+ * Tests for XMLEncoder
+ */
+public class XMLEncoderTest extends TestCase {
+
+	public static void main(String[] args) {
+
+		// VerboseEncoder enc = new VerboseEncoder();
+		//
+		// MockBean4Codec b = new MockBean4Codec();
+		// b.getBornFriend().getZarr()[0] = 888;
+		// b.setNill(b.getBornFriend());
+		//
+		// enc.writeObject(b);
+		// enc.flush();
+
+		junit.textui.TestRunner.run(XMLEncoderTest.class);
+	}
+
+	public static class DependencyBean {
+		private int ints[] = new int[] { 1 };
+
+		private Object ref;
+
+		public int[] getInts() {
+			return ints;
+		}
+
+		public void setInts(int[] ints) {
+			this.ints = ints;
+		}
+
+		public Object getRef() {
+			return ref;
+		}
+
+		public void setRef(Object ref) {
+			this.ref = ref;
+		}
+	}
+
+	public static class VerboseEncoder extends XMLEncoder {
+
+		private PrintWriter out;
+
+		private boolean ident;
+
+		public VerboseEncoder() {
+			this(new PrintWriter(System.out, true), true);
+		}
+
+		public VerboseEncoder(PrintWriter out, boolean ident) {
+			super(System.out);
+			this.out = out;
+			this.ident = ident;
+		}
+
+		public Object get(Object arg0) {
+			String identStr = ident ? ident() : "";
+			out.println(identStr + "get()> " + arg0);
+			Object result = super.get(arg0);
+			out.println(identStr + "get()< " + result);
+			return result;
+		}
+
+		public PersistenceDelegate getPersistenceDelegate(Class type) {
+			PersistenceDelegate result = super.getPersistenceDelegate(type);
+			return result;
+		}
+
+		public Object remove(Object arg0) {
+			String identStr = ident ? ident() : "";
+			out.println(identStr + "remove()> " + arg0);
+			Object result = super.remove(arg0);
+			out.println(identStr + "remove()< " + result);
+			return result;
+		}
+
+		public void writeExpression(Expression arg0) {
+			String identStr = ident ? ident() : "";
+			out.println(identStr + "writeExpression()> " + string(arg0));
+			super.writeExpression(arg0);
+			out.println(identStr + "writeExpression()< ");
+		}
+
+		public void writeStatement(Statement arg0) {
+			String identStr = ident ? ident() : "";
+			out.println(identStr + "writeStatement()> " + string(arg0));
+			super.writeStatement(arg0);
+			out.println(identStr + "writeStatement()< ");
+		}
+
+		public void writeObject(Object arg0) {
+			String identStr = ident ? ident() : "";
+			out.println(identStr + "writeObject()> " + arg0);
+			super.writeObject(arg0);
+			out.println(identStr + "writeObject()< ");
+		}
+	}
+
+	public static String ident() {
+		Exception ex = new Exception();
+		int level = ex.getStackTrace().length;
+		StringBuffer buf = new StringBuffer();
+		for (int i = 0; i < level; i++) {
+			buf.append("  ");
+		}
+		return buf.toString();
+	}
+
+	public static String string(Statement stat) {
+		String str = "(" + stat.getTarget() + ")." + stat.getMethodName() + "(";
+		Object args[] = stat.getArguments();
+		for (int i = 0; i < args.length; i++) {
+			if (i > 0) {
+				str += ", ";
+			}
+			str += args[i];
+		}
+		str = str + ")";
+		return str;
+	}
+
+	public static String string(Expression exp) {
+		String str = "";
+		try {
+			str += str + exp.getValue();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		str += "=" + string((Statement) exp);
+		return str;
+	}
+
+	public void testWriteExpression() {
+		// covered by testWriteObject
+	}
+
+	public void testWriteStatement() {
+		// coverd by testWriteStatement
+	}
+
+	public void testWriteObject_Null() throws IOException {
+		assertCodedXML(null, "null.xml");
+	}
+
+	public void testWriteObject_Integer() throws IOException {
+		assertCodedXML(new Integer(3), "int.xml");
+	}
+
+	public void testWriteObject_StringCodec() throws IOException {
+		SampleBean b = new SampleBean();
+		b.setMyid("<Li Yang> & \"liyang'");
+		SampleBean c = new SampleBean();
+		c.setMyid("a child");
+		b.setRef(c);
+		assertCodedXML(b, "SampleBean_StringCodec.xml");
+	}
+
+	public void testWriteObject_IntArray() throws IOException {
+		assertCodedXML(new int[] { 1, 2, 3 }, "IntArray.xml");
+	}
+
+	public void testWriteObject_PropertyDependency() throws IOException {
+		DependencyBean b = new DependencyBean();
+		b.getInts()[0] = 888;
+		b.setRef(b.getInts());
+		assertCodedXML(b, "DependencyBean.xml");
+	}
+
+	public void testWriteObject_NoChange() throws IOException {
+		assertCodedXML(new MockBean4Codec(), "MockBean4Codec_NoChange.xml");
+	}
+
+	public void testWriteObject_BornFriendChange() throws IOException {
+		MockBean4Codec b = new MockBean4Codec();
+		b.getBornFriend().getZarr()[0] = 888;
+		b.setNill(b.getBornFriend());
+
+		assertCodedXML(b, "MockBean4Codec_BornFriendChange.xml");
+	}
+
+	public void testWriteObject_ManyChanges() throws IOException {
+		assertCodedXML(MockBean4Codec.getInstanceOfManyChanges(),
+				"MockBean4Codec_ManyChanges.xml");
+	}
+
+	public void testWriteObject_ManyChanges_2() throws IOException {
+		assertCodedXML(MockBean4Codec.getInstanceOfManyChanges2(),
+				"MockBean4Codec_ManyChanges_2.xml");
+	}
+
+	public void testWriteObject_SetOwner() throws IOException {
+		ByteArrayOutputStream temp = new ByteArrayOutputStream();
+		XMLEncoder enc = new XMLEncoder(temp);
+
+		MockBean4Owner_Target t = new MockBean4Owner_Target();
+		MockBean4Owner_Owner o = new MockBean4Owner_Owner();
+		t.setV(o);
+		enc.setOwner(o);
+
+		assertCodedXML(t, "MockBean4Owner_SetOwner.xml", temp, enc);
+
+	}
+
+	public void testWriteObject_SetOwnerWithWriteStatement() throws IOException {
+		ByteArrayOutputStream temp = new ByteArrayOutputStream();
+		XMLEncoder enc = new XMLEncoder(temp);
+
+		MockBean4Owner_Target t = new MockBean4Owner_Target();
+		MockBean4Owner_Owner o = new MockBean4Owner_Owner();
+		t.setV(o);
+		enc.setOwner(o);
+
+		enc.writeStatement(new Statement(o, "loading", new Object[] {}));
+
+		assertCodedXML(t, "MockBean4Owner_SetOwnerWithWriteStatement.xml",
+				temp, enc);
+
+	}
+
+	public void testWriteObject_StaticField() throws IOException {
+		ByteArrayOutputStream temp = new ByteArrayOutputStream();
+		XMLEncoder enc = new XMLEncoder(temp);
+
+		enc.setPersistenceDelegate(MockBean4StaticField.class,
+				new MockBean4StaticField_PD());
+
+		assertCodedXML(MockBean4StaticField.inst, "MockBean4StaticField.xml",
+				temp, enc);
+
+	}
+
+	public void testClose() {
+		ByteArrayOutputStream out = new ByteArrayOutputStream() {
+			boolean closeCalled = false;
+
+			public void close() throws IOException {
+				if (closeCalled) {
+					throw new IOException("close already called!");
+				} else {
+					closeCalled = true;
+					super.close();
+				}
+			}
+		};
+		XMLEncoder enc = new XMLEncoder(out);
+		enc.writeObject(new Integer(3));
+		assertTrue(out.size() == 0);
+
+		enc.close();
+
+		assertTrue(out.size() > 0);
+		try {
+			out.close();
+			fail();
+		} catch (IOException e) {
+			assertEquals("close already called!", e.getMessage());
+		}
+	}
+
+	public void testFlush() {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		XMLEncoder enc = new XMLEncoder(out);
+		Integer i = new Integer(3);
+		enc.writeObject(i);
+		assertTrue(out.size() == 0);
+		assertNotNull(enc.get(i));
+
+		enc.flush();
+
+		assertTrue(out.size() > 0);
+		assertNull(enc.get(i));
+	}
+
+	public void testXMLEncoder_Null() {
+		try {
+			XMLEncoder enc = new XMLEncoder(null);
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	public void testGetOwner() {
+		XMLEncoder enc = new XMLEncoder(System.out);
+		assertNull(enc.getOwner());
+	}
+
+	public void testSetOwner() {
+		XMLEncoder enc = new XMLEncoder(System.out);
+		Object owner = Boolean.FALSE;
+
+		enc.setOwner(owner);
+		assertSame(owner, enc.getOwner());
+
+		enc.setOwner(null);
+		assertNull(enc.getOwner());
+	}
+
+	private void assertCodedXML(Object obj, String xmlFile) throws IOException {
+		ByteArrayOutputStream temp = new ByteArrayOutputStream();
+		XMLEncoder enc = new XMLEncoder(temp);
+
+		assertCodedXML(obj, xmlFile, temp, enc);
+	}
+
+	private void assertCodedXML(Object obj, String xmlFile,
+			ByteArrayOutputStream temp, XMLEncoder enc) throws IOException {
+		if (enc == null || temp == null) {
+			temp = new ByteArrayOutputStream();
+			enc = new XMLEncoder(temp);
+		}
+		enc.writeObject(obj);
+		enc.close();
+		byte bytes[] = temp.toByteArray();
+
+		InputStream refIn = XMLEncoderTest.class.getResourceAsStream(xmlFile);
+		if (refIn == null) {
+			FileOutputStream file = new FileOutputStream(xmlFile);
+			file.write(bytes);
+			file.close();
+			throw new Error("resource " + xmlFile + " not exist in "
+					+ XMLEncoderTest.class.getPackage()
+					+ ", write in current dir!");
+		}
+		BufferedReader xml = new BufferedReader(new InputStreamReader(
+				new ByteArrayInputStream(bytes), "UTF-8"));
+		BufferedReader refXml = new BufferedReader(new InputStreamReader(refIn,
+				"UTF-8"));
+
+		String line = null, refLine = null;
+		int lineNum = 0;
+		while (true) {
+			lineNum++;
+			line = xml.readLine();
+			refLine = refXml.readLine();
+			if (line == null && refLine == null) {
+				break;
+			}
+			if (line == null) {
+				throw new RuntimeException("line " + lineNum
+						+ ", xml ends, but ref line is: " + refLine);
+			}
+			if (refLine == null) {
+				throw new RuntimeException("line " + lineNum
+						+ ", ref xml ends, but line is: " + line);
+			}
+			if (lineNum == 2) {
+				String trim = line.trim();
+				assertTrue(trim.startsWith("<java version=\""));
+				assertTrue(trim.endsWith("\" class=\"java.beans.XMLDecoder\">"));
+			} else {
+				String trim = line.trim();
+				String refTrim = refLine.trim();
+				if (trim.endsWith(" />") && refTrim.endsWith("/>")
+						&& trim.length() == refTrim.length() + 1) {
+					trim = trim.substring(0, trim.length() - 3);
+					refTrim = refTrim.substring(0, refTrim.length() - 2);
+				}
+				if (!trim.equals(refTrim)) {
+					System.out.println("---- Bad xml ----");
+					BufferedReader reader = new BufferedReader(
+							new InputStreamReader(new ByteArrayInputStream(
+									bytes), "UTF-8"));
+					String l = null;
+					while ((l = reader.readLine()) != null) {
+						System.out.println(l);
+					}
+					throw new RuntimeException("line " + lineNum
+							+ ", expected: " + refLine + ", but was: " + line);
+				}
+			}
+		}
+	}
+
+}



Mime
View raw message