You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ml...@apache.org on 2006/04/18 14:11:45 UTC

svn commit: r394923 [2/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/t...

Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/CustomizerTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/CustomizerTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/CustomizerTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/CustomizerTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,46 @@
+/* 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.Customizer;
+import java.beans.PropertyChangeListener;
+
+import tests.api.java.beans.BeanInfoTest.DummyBeanInfo;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the signature of the interface Customizer.
+ */
+public class CustomizerTest extends TestCase {
+
+	public void testSignature() {
+		DummyCustomizer o = new DummyCustomizer();
+		assertTrue(o instanceof Customizer);
+	}
+
+	static class DummyCustomizer implements Customizer {
+
+		public void addPropertyChangeListener(PropertyChangeListener listener) {
+		}
+
+		public void removePropertyChangeListener(PropertyChangeListener listener) {
+		}
+
+		public void setObject(Object bean) {
+		}
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/DefaultPersistenceDelegateTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/DefaultPersistenceDelegateTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/DefaultPersistenceDelegateTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/DefaultPersistenceDelegateTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,999 @@
+/* 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.DefaultPersistenceDelegate;
+import java.beans.Encoder;
+import java.beans.ExceptionListener;
+import java.beans.Expression;
+import java.beans.Introspector;
+import java.beans.PersistenceDelegate;
+import java.beans.PropertyDescriptor;
+import java.beans.SimpleBeanInfo;
+import java.beans.Statement;
+
+import junit.framework.TestCase;
+import tests.api.java.beans.mock.MockFoo;
+import tests.api.java.beans.mock.MockFoo2;
+import tests.api.java.beans.mock.MockFooStop;
+import tests.util.CallVerificationStack;
+
+/**
+ * Tests the class java.beans.DefaultPersistenceDelegate
+ */
+public class DefaultPersistenceDelegateTest extends TestCase {
+
+	/*
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+		Introspector.flushCaches();
+		CallVerificationStack.getInstance().clear();
+	}
+
+	/*
+	 * Test the default constructor.
+	 */
+	public void testConstructor_Default() {
+		new DefaultPersistenceDelegate();
+	}
+
+	/*
+	 * Test the constructor with normal property names.
+	 */
+	public void testConstructor_StringArray_Normal() {
+		new DefaultPersistenceDelegate(new String[] { "prop1", "", null });
+	}
+
+	/*
+	 * Test the constructor with an empty string array.
+	 */
+	public void testConstructor_StringArray_Empty() {
+		new DefaultPersistenceDelegate(new String[0]);
+	}
+
+	/*
+	 * Test the constructor with null.
+	 */
+	public void testConstructor_StringArray_Null() {
+		new DefaultPersistenceDelegate(null);
+	}
+
+	/*
+	 * Test instantiate() under normal conditions: two properties, valid getter
+	 * method but no setter method and no such a constructor requiring the two
+	 * properties.
+	 */
+	public void testInstantiate_Normal() throws Exception {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate(new String[] {
+				"prop1", "prop2" });
+		MockBean b = new MockBean();
+		Encoder enc = new Encoder();
+		b.setAll("bean1", 2);
+		Expression e = pd.instantiate(b, enc);
+		assertSame(b, e.getValue());
+		assertSame(MockBean.class, e.getTarget());
+		assertEquals("new", e.getMethodName());
+		assertSame("bean1", e.getArguments()[0]);
+		assertEquals(new Integer(2), e.getArguments()[1]);
+	}
+
+	/*
+	 * Test instantiate() with null instance.
+	 */
+	public void testInstantiate_NullInstance() throws Exception {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate(new String[] {
+				"prop1", "prop2" });
+		Encoder enc = new Encoder();
+		try {
+			pd.instantiate(null, enc);
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException ex) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test instantiate() with null encoder.
+	 */
+	public void testInstantiate_NullEncoder() throws Exception {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate(new String[] {
+				"prop1", "prop2" });
+		MockBean b = new MockBean();
+		b.setAll("bean1", 2);
+		Expression e = pd.instantiate(b, null);
+		assertSame(b, e.getValue());
+		assertSame(MockBean.class, e.getTarget());
+		assertEquals("new", e.getMethodName());
+		assertSame("bean1", e.getArguments()[0]);
+		assertEquals(new Integer(2), e.getArguments()[1]);
+		assertEquals(2, e.getArguments().length);
+	}
+
+	/*
+	 * Test instantiate() with null property name.
+	 */
+	public void testInstantiate_NullProperty() throws Exception {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate(new String[] {
+				"prop1", null });
+		MockBean b = new MockBean();
+		b.setAll("bean1", 2);
+		try {
+			pd.instantiate(b, new Encoder());
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException ex) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test instantiate() with empty property name.
+	 */
+	public void testInstantiate_EmptyProperty() throws Exception {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate(new String[] {
+				"prop1", "" });
+		MockBean b = new MockBean();
+		b.setAll("bean1", 2);
+		try {
+			pd.instantiate(b, null);
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException ex) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test instantiate() with no property.
+	 */
+	public void testInstantiate_NoProperty() throws Exception {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate();
+		MockBean b = new MockBean();
+		b.setAll("bean1", 2);
+		Expression e = pd.instantiate(b, new Encoder());
+		assertSame(b, e.getValue());
+		assertSame(MockBean.class, e.getTarget());
+		assertEquals("new", e.getMethodName());
+		assertEquals(0, e.getArguments().length);
+	}
+
+	/*
+	 * Test instantiate() with one normal property name, but non-existing getter
+	 * method.
+	 */
+	public void testInstantiate_NonExistingGetter() throws Exception {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate(new String[] {
+				"prop1", "non_existing" });
+		MockBean b = new MockBean();
+		b.setAll("bean1", 2);
+		Encoder enc = new Encoder();
+		ExceptionListener el = new ExceptionListener() {
+			public void exceptionThrown(Exception e) {
+				CallVerificationStack.getInstance().push(e);
+			}
+		};
+		enc.setExceptionListener(el);
+		Expression e = pd.instantiate(b, enc);
+		assertSame(b, e.getValue());
+		assertSame(MockBean.class, e.getTarget());
+		assertEquals("new", e.getMethodName());
+		assertEquals(2, e.getArguments().length);
+		assertSame(b.getProp1(), e.getArguments()[0]);
+		assertSame(null, e.getArguments()[1]);
+		assertTrue(CallVerificationStack.getInstance().pop() instanceof Exception);
+
+		enc.setExceptionListener(null);
+		assertNotNull(enc.getExceptionListener());
+		e = pd.instantiate(b, enc);
+		assertSame(b, e.getValue());
+		assertSame(MockBean.class, e.getTarget());
+		assertEquals("new", e.getMethodName());
+		assertEquals(2, e.getArguments().length);
+		assertSame(b.getProp1(), e.getArguments()[0]);
+		assertSame(null, e.getArguments()[1]);
+	}
+
+	/*
+	 * Test instantiate() with one normal property name, but non-existing getter
+	 * method, and null encoder.
+	 */
+	public void testInstantiate_NonExistingGetterNulEncoder() throws Exception {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate(new String[] {
+				"prop1", "non_existing" });
+		MockBean b = new MockBean();
+		b.setAll("bean1", 2);
+		try {
+			pd.instantiate(b, null);
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException ex) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test instantiate() with one normal property name, but an invalid getter
+	 * method (requiring an argument, for instance).
+	 */
+	public void testInstantiate_InvalidGetter() throws Exception {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate(new String[] {
+				"prop1", "prop4" });
+		MockBean b = new MockBean();
+		b.setAll("bean1", 2);
+		Expression e = pd.instantiate(b, new Encoder());
+		assertSame(b, e.getValue());
+		assertSame(MockBean.class, e.getTarget());
+		assertEquals("new", e.getMethodName());
+		assertEquals(2, e.getArguments().length);
+		assertSame(b.getProp1(), e.getArguments()[0]);
+		assertSame(null, e.getArguments()[1]);
+	}
+
+	/*
+	 * Test instantiate() with one normal property name, but a getter method
+	 * that will throw an exception.
+	 */
+	public void testInstantiate_ExceptionalGetter() throws Exception {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate(new String[] {
+				"prop1", "prop5" });
+		MockBean b = new MockBean();
+		b.setAll("bean1", 2);
+		Expression e = pd.instantiate(b, new Encoder());
+		assertSame(b, e.getValue());
+		assertSame(MockBean.class, e.getTarget());
+		assertEquals("new", e.getMethodName());
+		assertEquals(2, e.getArguments().length);
+		assertSame(b.getProp1(), e.getArguments()[0]);
+		assertSame(null, e.getArguments()[1]);
+	}
+
+	/*
+	 * Test instantiate() with one normal property name, but a getter method
+	 * that will throw an error.
+	 */
+	public void testInstantiate_ErrorGetter() throws Exception {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate(new String[] {
+				"prop1", "prop7" });
+		MockBean b = new MockBean();
+		b.setAll("bean1", 2);
+		Expression e = pd.instantiate(b, new Encoder());
+		assertSame(b, e.getValue());
+		assertSame(MockBean.class, e.getTarget());
+		assertEquals("new", e.getMethodName());
+		assertEquals(2, e.getArguments().length);
+		assertSame(b.getProp1(), e.getArguments()[0]);
+		assertSame(null, e.getArguments()[1]);
+	}
+
+	/*
+	 * Test instantiate() with one normal property name, but a private getter
+	 * method.
+	 */
+	public void testInstantiate_PrivateGetter() throws Exception {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate(new String[] {
+				"prop1", "prop6" });
+		MockBean b = new MockBean();
+		b.setAll("bean1", 2);
+		Expression e = pd.instantiate(b, new Encoder());
+		assertSame(b, e.getValue());
+		assertSame(MockBean.class, e.getTarget());
+		assertEquals("new", e.getMethodName());
+		assertEquals(2, e.getArguments().length);
+		assertSame(b.getProp1(), e.getArguments()[0]);
+		assertSame(null, e.getArguments()[1]);
+	}
+
+	/*
+	 * Test instantiate() with a property name starting with initial upper case
+	 * letter, and a valid getter method.
+	 */
+	public void testInstantiate_InitialUpperCasePropName() throws Exception {
+		String[] props = new String[] { "Prop1", "prop2" };
+		MockPersistenceDelegate pd = new MockPersistenceDelegate(props);
+		MockBean b = new MockBean();
+		b.setAll("bean1", 2);
+		Expression e = pd.instantiate(b, new Encoder());
+		assertSame(b, e.getValue());
+		assertSame(MockBean.class, e.getTarget());
+		assertEquals("new", e.getMethodName());
+		assertEquals(2, e.getArguments().length);
+		assertSame(b.getProp1(), e.getArguments()[0]);
+		assertEquals(new Integer(2), e.getArguments()[1]);
+	}
+
+	/*
+	 * Test instantiate() with a bean with no getter.
+	 */
+	public void testInstantiate_NoGetter() throws Exception {
+		MockEncoder enc = new MockEncoder();
+		MockPersistenceDelegate pd = new MockPersistenceDelegate(
+				new String[] { "i" });
+		MockNoGetterBean2 b = new MockNoGetterBean2(3);
+		enc.setExceptionListener(new ExceptionListener() {
+			public void exceptionThrown(Exception e) {
+				CallVerificationStack.getInstance().push(e);
+			}
+		});
+		Expression e = pd.instantiate(b, enc);
+		assertSame(b, e.getValue());
+		assertSame(MockNoGetterBean2.class, e.getTarget());
+		assertEquals("new", e.getMethodName());
+		assertEquals(1, e.getArguments().length);
+		assertSame(null, e.getArguments()[0]);
+		assertFalse(CallVerificationStack.getInstance().empty());
+	}
+
+	/*
+	 * Test instantiate() with a property name that has an unregular getter
+	 * method, defined by its beaninfo.
+	 */
+	public void testInstantiate_NotRegularGetter() throws Exception {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate(new String[] {
+				"prop1", "i" });
+		MockFoo2 b = new MockFoo2(2);
+		Expression e = pd.instantiate(b, new Encoder());
+		assertSame(b, e.getValue());
+		assertSame(MockFoo2.class, e.getTarget());
+		assertEquals("new", e.getMethodName());
+		assertEquals(2, e.getArguments().length);
+		assertEquals(new Integer(2), e.getArguments()[0]);
+		assertEquals(null, e.getArguments()[1]);
+	}
+
+	/*
+	 * Tests mutatesTo() under normal conditions without any properties.
+	 */
+	public void testMutatesTo_NormalNoProperty() {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate();
+		assertTrue(pd.mutatesTo("test1", "test2"));
+		assertFalse(pd.mutatesTo(new Object(), new Object() {
+			public int hashCode() {
+				return super.hashCode();
+			}
+		}));
+		assertFalse(pd.mutatesTo(new MockFoo(), new MockFooStop()));
+	}
+
+	/*
+	 * Tests mutatesTo() under normal conditions with properties but no equal
+	 * method defined.
+	 */
+	public void testMutatesTo_NormalWithPropertyNoEqualMethod() {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate(
+				new String[] { "name" });
+		assertFalse(pd.mutatesTo(new Object(), new Object() {
+			public int hashCode() {
+				return super.hashCode();
+			}
+		}));
+	}
+
+	/*
+	 * Tests mutatesTo() under normal conditions with null properties and equal
+	 * method defined.
+	 */
+	public void testMutatesTo_NormalWithNullPropertyPublicEqualMethod() {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate(
+				new String[] { null });
+		assertFalse(pd.mutatesTo("test1", "test2"));
+	}
+
+	/*
+	 * Tests mutatesTo() under normal conditions with empty properties and equal
+	 * method defined.
+	 */
+	public void testMutatesTo_NormalWithEmptyPropertyPublicEqualMethod() {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate(new String[0]);
+		assertTrue(pd.mutatesTo("test1", "test2"));
+	}
+
+	/*
+	 * Tests mutatesTo() under normal conditions with properties and equal
+	 * method defined.
+	 */
+	public void testMutatesTo_NormalWithPropertyPublicEqualMethod() {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate(
+				new String[] { "name" });
+		assertFalse(pd.mutatesTo("test1", "test2"));
+		assertTrue(pd.mutatesTo("test1", "test1"));
+	}
+
+	/*
+	 * Tests mutatesTo() under normal conditions with properties and protected
+	 * equal method defined.
+	 */
+	public void testMutatesTo_NormalWithPropertyProtectedEqualMethod() {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate(
+				new String[] { "name" });
+		assertFalse(pd.mutatesTo(new MockPersistenceDelegate(), "test"));
+	}
+
+	/*
+	 * Tests mutatesTo() with null parameters.
+	 */
+	public void testMutatesTo_Null() {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate();
+		assertFalse(pd.mutatesTo("test", null));
+		assertFalse(pd.mutatesTo(null, null));
+		try {
+			pd.mutatesTo(null, "test");
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException ex) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test initialize() under normal conditions with a bean that does not have
+	 * bean info class.
+	 */
+	public void testInitialize_Normal() throws Exception {
+		MockEncoder enc = new MockEncoder();
+		MockPersistenceDelegate pd = new MockPersistenceDelegate();
+		MockFoo b = new MockFoo();
+		b.setName("myName");
+		// b.setLabel("myLabel");
+
+		enc.writeObject(b);
+		CallVerificationStack.getInstance().clear();
+		MockFoo b2 = (MockFoo) enc.get(b);
+		b2.setName("YourName");
+
+		pd.initialize(MockFoo.class, b, b2, enc);
+
+		// should have called writeStatement()
+		Statement stm = (Statement) CallVerificationStack.getInstance().pop();
+		assertSame(b, stm.getTarget());
+		assertEquals("setName", stm.getMethodName());
+		assertEquals(1, stm.getArguments().length);
+		assertEquals("myName", stm.getArguments()[0]);
+
+		// should have called get()
+		assertEquals("myName", CallVerificationStack.getInstance().pop());
+
+		// should have called writeExpression()
+		Expression exp = (Expression) CallVerificationStack.getInstance().pop();
+		assertSame(b.getName(), exp.getValue());
+		assertSame(b, exp.getTarget());
+		assertEquals("getName", exp.getMethodName());
+		assertEquals(0, exp.getArguments().length);
+
+		// should have called get()
+		assertEquals(null, CallVerificationStack.getInstance().pop());
+
+		// should have called writeExpression()
+		exp = (Expression) CallVerificationStack.getInstance().pop();
+		assertSame(b.getLabel(), exp.getValue());
+		assertSame(b, exp.getTarget());
+		assertEquals("getLabel", exp.getMethodName());
+		assertEquals(0, exp.getArguments().length);
+
+		assertTrue(CallVerificationStack.getInstance().empty());
+	}
+
+	/*
+	 * Test initialize() under normal conditions with a bean that does have bean
+	 * info class.
+	 */
+	public void testInitialize_NormalBeanInfo() throws Exception {
+		MockEncoder enc = new MockEncoder();
+		MockPersistenceDelegate pd = new MockPersistenceDelegate();
+		MockFoo2 b = new MockFoo2(2);
+
+		enc.writeObject(b);
+		CallVerificationStack.getInstance().clear();
+		MockFoo2 b2 = (MockFoo2) enc.get(b);
+		b2.myset(3);
+
+		pd.initialize(MockFoo2.class, b, b2, enc);
+
+		// should have called writeStatement()
+		Statement stm = (Statement) CallVerificationStack.getInstance().pop();
+		assertSame(b, stm.getTarget());
+		assertEquals("myset", stm.getMethodName());
+		assertEquals(1, stm.getArguments().length);
+		assertEquals(new Integer(2), stm.getArguments()[0]);
+
+		// should have called get()
+		assertEquals(new Integer(2), CallVerificationStack.getInstance().pop());
+
+		// should have called writeExpression()
+		Expression exp = (Expression) CallVerificationStack.getInstance().pop();
+		assertEquals(new Integer(2), exp.getValue());
+		assertSame(b, exp.getTarget());
+		assertEquals("myget", exp.getMethodName());
+		assertEquals(0, exp.getArguments().length);
+
+		assertTrue(CallVerificationStack.getInstance().empty());
+	}
+
+	/*
+	 * Test initialize() when oldInstance == newInstance.
+	 */
+	public void testInitialize_SameInstance() throws Exception {
+		MockEncoder enc = new MockEncoder();
+		MockPersistenceDelegate pd = new MockPersistenceDelegate();
+		MockFoo b = new MockFoo();
+		b.setName("mymyName");
+		// b.setLabel("myLabel");
+
+		pd.initialize(MockFoo.class, b, b, enc);
+
+		// should have called get()
+		assertEquals("mymyName", CallVerificationStack.getInstance().pop());
+
+		// should have called writeExpression()
+		Expression exp = (Expression) CallVerificationStack.getInstance().pop();
+		assertSame(b.getName(), exp.getValue());
+		assertSame(b, exp.getTarget());
+		assertEquals("getName", exp.getMethodName());
+		assertEquals(0, exp.getArguments().length);
+
+		// should have called get()
+		assertEquals(null, CallVerificationStack.getInstance().pop());
+
+		// should have called writeExpression()
+		exp = (Expression) CallVerificationStack.getInstance().pop();
+		assertSame(b.getLabel(), exp.getValue());
+		assertSame(b, exp.getTarget());
+		assertEquals("getLabel", exp.getMethodName());
+		assertEquals(0, exp.getArguments().length);
+
+		assertTrue(CallVerificationStack.getInstance().empty());
+	}
+
+	/*
+	 * Test initialize() with a bean with a transient property.
+	 */
+	public void testInitialize_TransientProperty() throws Exception {
+		MockEncoder enc = new MockEncoder();
+		MockPersistenceDelegate pd = new MockPersistenceDelegate();
+		MockTransientBean b = new MockTransientBean();
+		b.setName("myName");
+		pd.initialize(MockTransientBean.class, b, new MockTransientBean(), enc);
+		assertTrue(CallVerificationStack.getInstance().empty());
+		// set transient to false
+		Introspector.flushCaches();
+		MockTransientBeanBeanInfo.setTransient(false);
+		pd.initialize(MockTransientBean.class, new MockTransientBean(),
+				new MockTransientBean(), enc);
+		assertFalse(CallVerificationStack.getInstance().empty());
+	}
+
+	/*
+	 * Test initialize() with a bean with no setter.
+	 */
+	public void testInitialize_NoSetter() throws Exception {
+		MockEncoder enc = new MockEncoder();
+		MockPersistenceDelegate pd = new MockPersistenceDelegate();
+		MockNoSetterBean b = new MockNoSetterBean();
+		enc.setExceptionListener(new ExceptionListener() {
+			public void exceptionThrown(Exception e) {
+				CallVerificationStack.getInstance().push(e);
+			}
+		});
+		b.setName("myName");
+		pd.initialize(MockNoSetterBean.class, b, new MockNoSetterBean(), enc);
+		assertTrue(CallVerificationStack.getInstance().empty());
+
+		pd = new MockPersistenceDelegate(new String[] { "name" });
+		enc.setExceptionListener(new ExceptionListener() {
+			public void exceptionThrown(Exception e) {
+				CallVerificationStack.getInstance().push(e);
+			}
+		});
+		b.setName("myName");
+		pd.initialize(MockNoSetterBean.class, b, new MockNoSetterBean(), enc);
+		assertTrue(CallVerificationStack.getInstance().empty());
+	}
+
+	/*
+	 * Test initialize() with a bean with no getter.
+	 */
+	public void testInitialize_NoGetter() throws Exception {
+		MockEncoder enc = new MockEncoder();
+		MockPersistenceDelegate pd = new MockPersistenceDelegate();
+		MockNoGetterBean b = new MockNoGetterBean();
+
+		b.setName("myName");
+		enc.setExceptionListener(new ExceptionListener() {
+			public void exceptionThrown(Exception e) {
+				CallVerificationStack.getInstance().push(e);
+			}
+		});
+		enc.writeObject(b);
+		CallVerificationStack.getInstance().clear();
+		MockNoGetterBean b2 = (MockNoGetterBean) enc.get(b);
+		b2.setName("yourName");
+		b2.setLabel("hehe");
+		pd.initialize(MockNoGetterBean.class, b, b2, enc);
+		assertTrue(CallVerificationStack.getInstance().empty());
+	}
+
+	/*
+	 * Tests initialize() with null class.
+	 */
+	public void testInitialize_NullClass() {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate();
+		Encoder enc = new Encoder();
+		Object o1 = new Object();
+		Object o2 = new Object();
+		// enc.setPersistenceDelegate(MockFooStop.class,
+		// new MockPersistenceDelegate());
+		try {
+			enc.setExceptionListener(new ExceptionListener() {
+				public void exceptionThrown(Exception e) {
+					CallVerificationStack.getInstance().push(e);
+				}
+			});
+			pd.initialize(null, o1, o2, enc);
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException ex) {
+			// expected
+		}
+		assertTrue(CallVerificationStack.getInstance().empty());
+	}
+
+	/*
+	 * Tests initialize() with null old and new instances.
+	 */
+	public void testInitialize_NullInstances() {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate();
+		Encoder enc = new Encoder();
+		MockFoo b = new MockFoo();
+		b.setName("myName");
+		// enc.setPersistenceDelegate(MockFooStop.class,
+		// new MockPersistenceDelegate());
+		enc.setExceptionListener(new ExceptionListener() {
+			public void exceptionThrown(Exception e) {
+				CallVerificationStack.getInstance().push(e);
+			}
+		});
+		try {
+			pd.initialize(MockFoo.class, null, b, enc);
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException ex) {
+			// expected
+		}
+		assertTrue(CallVerificationStack.getInstance().empty());
+		pd.initialize(MockFoo.class, b, null, enc);
+		assertFalse(CallVerificationStack.getInstance().empty());
+	}
+
+	/*
+	 * Tests initialize() with null encoder.
+	 */
+	public void testInitialize_NullEncoder() {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate();
+		Object o1 = new Object();
+		Object o2 = new Object();
+		try {
+			pd.initialize(MockFoo.class, o1, o2, null);
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException ex) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test initialize() with a property name that has an unregular getter
+	 * method, defined by its beaninfo.
+	 */
+	public void testInitialize_NotRegularGetter() throws Exception {
+		MockPersistenceDelegate pd = new MockPersistenceDelegate();
+		// new String[] { "prop1" });
+		MockEncoder enc = new MockEncoder();
+
+		MockFoo2 b = new MockFoo2(2);
+		MockFoo2 b2 = new MockFoo2(1);
+		pd.initialize(MockFoo2.class, b, b2, enc);
+
+		// should have called writeStatement()
+		Statement stm = (Statement) CallVerificationStack.getInstance().pop();
+		assertSame(b, stm.getTarget());
+		assertEquals("myset", stm.getMethodName());
+		assertEquals(1, stm.getArguments().length);
+		assertEquals(new Integer(2), stm.getArguments()[0]);
+
+		// should have called get()
+		assertEquals(new Integer(2), CallVerificationStack.getInstance().pop());
+
+		// should have called writeExpression()
+		Expression exp = (Expression) CallVerificationStack.getInstance().pop();
+		assertEquals(new Integer(2), exp.getValue());
+		assertSame(b, exp.getTarget());
+		assertEquals("myget", exp.getMethodName());
+		assertEquals(0, exp.getArguments().length);
+	}
+
+	/*
+	 * Tests array persistence delegate
+	 */
+	public void testArrayPD_Normal() {
+		Encoder enc = new MockEncoder();
+		int[] ia = new int[] { 1 };
+		PersistenceDelegate pd = enc.getPersistenceDelegate(ia.getClass());
+		pd.writeObject(ia, enc);
+	}
+
+	/*
+	 * BeanInfo for the MockBean below.
+	 */
+	public static class MockNoGetterBeanBeanInfo extends SimpleBeanInfo {
+
+		public PropertyDescriptor[] getPropertyDescriptors() {
+			try {
+				PropertyDescriptor pd = new PropertyDescriptor("name", null,
+						MockNoGetterBean.class.getMethod("setName",
+								new Class[] { String.class }));
+				PropertyDescriptor pd2 = new PropertyDescriptor("ii", null,
+						MockNoGetterBean.class.getMethod("setII",
+								new Class[] { Integer.class }));
+				return new PropertyDescriptor[] { pd, pd2 };
+			} catch (Exception e) {
+				throw new Error(e);
+			}
+		}
+	}
+
+	/*
+	 * Mock bean with no getter.
+	 */
+	public static class MockNoGetterBean extends MockFoo {
+		private Integer ii = new Integer(2);
+
+		public void setII(Integer i) {
+			this.ii = i;
+		}
+	}
+
+	/*
+	 * Mock bean with no getter.
+	 */
+	public static class MockNoGetterBean2 {
+		private int ii;
+
+		public MockNoGetterBean2(int i) {
+			this.ii = i;
+		}
+
+		public void setI(int i) {
+			this.ii = i;
+		}
+	}
+
+	/*
+	 * BeanInfo for the MockBean below.
+	 */
+	public static class MockNoSetterBeanBeanInfo extends SimpleBeanInfo {
+
+		public PropertyDescriptor[] getPropertyDescriptors() {
+			try {
+				PropertyDescriptor pd = new PropertyDescriptor("name",
+						MockNoSetterBean.class.getMethod("getName", null), null);
+				return new PropertyDescriptor[] { pd };
+			} catch (Exception e) {
+				throw new Error(e);
+			}
+		}
+	}
+
+	/*
+	 * Mock bean with no setter.
+	 */
+	public static class MockNoSetterBean {
+		private String name;
+
+		public String getName() {
+			return name;
+		}
+
+		public void setName(String name) {
+			this.name = name;
+		}
+	}
+
+	/*
+	 * BeanInfo for the MockBean below.
+	 */
+	public static class MockTransientBeanBeanInfo extends SimpleBeanInfo {
+
+		private static boolean trans = true;
+
+		public static void setTransient(boolean b) {
+			trans = b;
+		}
+
+		public PropertyDescriptor[] getPropertyDescriptors() {
+			try {
+				PropertyDescriptor pd = new PropertyDescriptor("name",
+						MockTransientBean.class);
+				pd.setValue("transient", new Boolean(trans));
+				return new PropertyDescriptor[] { pd };
+			} catch (Exception e) {
+				throw new Error(e);
+			}
+		}
+	}
+
+	/*
+	 * Mock bean with a transient property.
+	 */
+	public static class MockTransientBean extends MockFoo {
+	}
+
+	/*
+	 * Mock bean.
+	 */
+	public static class MockBean {
+		private transient String prop1;
+
+		private transient int prop2;
+
+		public String getProp1() {
+			return this.prop1;
+		}
+
+		public int getProp2() {
+			return this.prop2;
+		}
+
+		public int getProp3() {
+			return this.prop2;
+		}
+
+		public void setProp3() {
+			// empty
+		}
+
+		public int getProp4(int i) {
+			return this.prop2;
+		}
+
+		public int getProp5() throws Exception {
+			throw new Exception();
+		}
+
+		private int getProp6() {
+			return 1;
+		}
+
+		public int getProp7() {
+			throw new Error();
+		}
+
+		public void setAll(String prop1, int prop2) {
+			this.prop1 = prop1;
+			this.prop2 = prop2;
+		}
+
+		public int get() {
+			return this.prop2;
+		}
+
+	}
+
+	/*
+	 * Mock DefaultPersistenceDelegate subclass.
+	 */
+	static class MockPersistenceDelegate extends DefaultPersistenceDelegate {
+
+		public MockPersistenceDelegate() {
+			super();
+		}
+
+		public MockPersistenceDelegate(String[] props) {
+			super(props);
+		}
+
+		public Expression instantiate(Object oldInstance, Encoder out) {
+			return super.instantiate(oldInstance, out);
+		}
+
+		public void initialize(Class type, Object oldInstance,
+				Object newInstance, Encoder enc) {
+			super.initialize(type, oldInstance, newInstance, enc);
+		}
+
+		public boolean mutatesTo(Object oldInstance, Object newInstance) {
+			return super.mutatesTo(oldInstance, newInstance);
+		}
+
+		protected boolean equals(String o) {
+			return true;
+		}
+
+	}
+
+	/*
+	 * Mock Encoder.
+	 */
+	static class MockEncoder extends Encoder {
+
+		public ExceptionListener getExceptionListener() {
+			StackTraceElement[] eles = (new Throwable()).getStackTrace();
+			int i = 1;
+			// while (eles[i++].getClassName().equals(
+			// DefaultPersistenceDelegate.class.getName())) {
+			// // skip calls from DefaultPersistenceDelegate
+			// }
+			return super.getExceptionListener();
+		}
+
+		public PersistenceDelegate getPersistenceDelegate(Class type) {
+			return super.getPersistenceDelegate(type);
+		}
+
+		public void setExceptionListener(ExceptionListener exceptionListener) {
+			super.setExceptionListener(exceptionListener);
+		}
+
+		public void setPersistenceDelegate(Class type,
+				PersistenceDelegate persistenceDelegate) {
+			super.setPersistenceDelegate(type, persistenceDelegate);
+		}
+
+		private void recordCall(Object param) {
+			StackTraceElement[] eles = (new Throwable()).getStackTrace();
+			int i = 0;
+			// skip Throwable.init()
+			while (eles[i].getClassName().equals("java.lang.Throwable")) {
+				i++;
+			}
+			// skip calls from MockEncoder
+			while (eles[i].getClassName().equals(MockEncoder.class.getName())) {
+				i++;
+			}
+			// skip calls from DefaultPersistenceDelegate & PersistenceDelegate
+			while (eles[i].getClassName().equals(
+					DefaultPersistenceDelegate.class.getName())
+					|| eles[i].getClassName().equals(
+							PersistenceDelegate.class.getName())) {
+				i++;
+			}
+			if (i > 2
+					&& eles[++i].getClassName().equals(
+							DefaultPersistenceDelegateTest.class.getName())) {
+				CallVerificationStack.getInstance().push(param);
+			}
+		}
+
+		public Object get(Object oldInstance) {
+			recordCall(oldInstance);
+			return super.get(oldInstance);
+		}
+
+		public Object remove(Object oldInstance) {
+			recordCall(oldInstance);
+			return super.remove(oldInstance);
+		}
+
+		public void writeExpression(Expression oldExp) {
+			recordCall(oldExp);
+			super.writeExpression(oldExp);
+		}
+
+		public void writeStatement(Statement oldStm) {
+			recordCall(oldStm);
+			super.writeStatement(oldStm);
+		}
+
+		public void writeObject(Object o) {
+			recordCall(o);
+			super.writeObject(o);
+		}
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/DependencyBean.xml
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/DependencyBean.xml?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/DependencyBean.xml (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/DependencyBean.xml Tue Apr 18 05:11:09 2006
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?> 
+
+<!-- Copyright 2006 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. -->
+
+<java version="1.4.2_07" class="java.beans.XMLDecoder"> 
+ <object class="tests.api.java.beans.XMLEncoderTest$DependencyBean"> 
+  <void id="intArray0" property="ints"> 
+   <void index="0"> 
+    <int>888</int> 
+   </void> 
+  </void> 
+  <void property="ref"> 
+   <object idref="intArray0"/> 
+  </void> 
+ </object> 
+</java> 

Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/DesignModeTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/DesignModeTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/DesignModeTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/DesignModeTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,41 @@
+/* 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.DesignMode;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the signature of the interface DesignMode.
+ */
+public class DesignModeTest extends TestCase {
+
+    public void testSignature() {
+        DummyDesignMode o = new DummyDesignMode();
+        assertTrue(o instanceof DesignMode);
+    }
+
+    static class DummyDesignMode implements DesignMode {
+
+        public boolean isDesignTime() {
+            return false;
+        }
+
+        public void setDesignTime(boolean value) {
+        }
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/EncoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/EncoderTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/EncoderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/EncoderTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,491 @@
+/* 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.DefaultPersistenceDelegate;
+import java.beans.Encoder;
+import java.beans.ExceptionListener;
+import java.beans.Expression;
+import java.beans.PersistenceDelegate;
+import java.beans.Statement;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.lang.reflect.Proxy;
+import java.util.List;
+
+import junit.framework.TestCase;
+import tests.api.java.beans.mock.MockBean4Codec;
+import tests.api.java.beans.mock.MockBean4CodecBadGetter;
+import tests.api.java.beans.mock.MockExceptionListener;
+import tests.api.java.beans.mock.MockFooLiYang;
+
+public class EncoderTest extends TestCase {
+
+	public static void main(String[] args) throws Exception {
+		// VerboseEncoder enc = new VerboseEncoder();
+		// SampleBean b = new SampleBean();
+		// b.setI(3);
+		// b.setMyid("new name");
+		// enc.writeObject(b);
+		// enc.remove(b);
+		// enc.writeObject(null);
+
+		junit.textui.TestRunner.run(EncoderTest.class);
+	}
+
+	public static class VerboseEncoder extends Encoder {
+
+		private PrintWriter out;
+
+		private boolean ident;
+
+		public VerboseEncoder() {
+			this(new PrintWriter(System.out, true), true);
+		}
+
+		public VerboseEncoder(PrintWriter out, boolean ident) {
+			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
+					+ new Exception().getStackTrace()[1].getClassName()
+					+ ".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 class VerbosePD extends DefaultPersistenceDelegate {
+
+		protected void initialize(Class arg0, Object arg1, Object arg2,
+				Encoder arg3) {
+			System.out.println(ident() + "PDinitialize()> " + arg0 + ", "
+					+ arg1 + ", " + arg2);
+			super.initialize(arg0, arg1, arg2, arg3);
+			System.out.println(ident() + "PDinitialize()< ");
+		}
+
+		protected Expression instantiate(Object arg0, Encoder arg1) {
+			System.out.println(ident() + "PDinstantiate()> " + arg0);
+			Expression result = super.instantiate(arg0, arg1);
+			System.out.println(ident() + "PDinstantiate()< " + result);
+			return result;
+		}
+
+		protected boolean mutatesTo(Object arg0, Object arg1) {
+			System.out
+					.println(ident() + "PDmutatesTo()> " + arg0 + ", " + arg1);
+			boolean result = super.mutatesTo(arg0, arg1);
+			System.out.println(ident() + "PDmutatesTo()< " + result);
+			return result;
+		}
+
+		public void writeObject(Object arg0, Encoder arg1) {
+			System.out.println(ident() + "PDwriteObject()> " + arg0);
+			super.writeObject(arg0, arg1);
+			System.out.println(ident() + "PDwriteObject()< ");
+		}
+	}
+
+	public static class SampleBean {
+		String myid = "default ID";
+
+		int i = 1;
+
+		SampleBean ref;
+
+		public String getMyid() {
+			return myid;
+		}
+
+		public void setMyid(String myid) {
+			this.myid = myid;
+		}
+
+		public int getI() {
+			return i;
+		}
+
+		public void setI(int i) {
+			this.i = i;
+		}
+
+		public SampleBean getRef() {
+			return ref;
+		}
+
+		public void setRef(SampleBean ref) {
+			this.ref = ref;
+		}
+
+		public String toString() {
+			String superResult = super.toString();
+			String addr = superResult.substring(superResult.indexOf("@"));
+			return "myid=" + myid;
+		}
+	}
+
+	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 static class MockEncoder extends Encoder {
+
+		public void writeObject(Object o) {
+			super.writeObject(o);
+		}
+	}
+
+	public void testGetExceptionListener() {
+		MockEncoder enc = new MockEncoder();
+		assertNotNull(enc.getExceptionListener());
+
+		MockExceptionListener l = new MockExceptionListener();
+		enc.setExceptionListener(l);
+		assertSame(l, enc.getExceptionListener());
+
+		enc.writeObject(new MockBean4CodecBadGetter());
+		assertTrue(l.size() > 0);
+	}
+
+	public void testSetExceptionListener_Null() {
+		MockEncoder enc = new MockEncoder();
+		ExceptionListener l = enc.getExceptionListener();
+		enc.setExceptionListener(null);
+		assertSame(l, enc.getExceptionListener());
+
+		ExceptionListener l2 = new MockExceptionListener();
+		enc.setExceptionListener(l2);
+		enc.setExceptionListener(null);
+		assertSame(l.getClass(), enc.getExceptionListener().getClass());
+	}
+
+	public void testSetExceptionListener() {
+		MockEncoder enc = new MockEncoder();
+		assertNotNull(enc.getExceptionListener());
+
+		MockExceptionListener l = new MockExceptionListener();
+		enc.setExceptionListener(l);
+		assertSame(l, enc.getExceptionListener());
+
+		enc.writeObject(new MockBean4CodecBadGetter());
+		assertTrue(l.size() > 0);
+	}
+
+	public void testWriteExpression() {
+		// covered by testWriteObject()
+	}
+
+	public void testWriteExpression_Null() {
+		MockEncoder enc = new MockEncoder();
+		try {
+			enc.writeExpression(null);
+			fail();
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	public void testWriteStatement() {
+		// covered by testWriteObject()
+	}
+
+	public void testWriteStatement_Null() {
+		MockEncoder enc = new MockEncoder();
+		try {
+			enc.writeStatement(null);
+			fail();
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	public void testWriteObject_Null() {
+		StringWriter sbwriter = new StringWriter();
+		VerboseEncoder enc = new VerboseEncoder(
+				new PrintWriter(sbwriter, true), false);
+		enc.writeObject(null);
+		String trace = sbwriter.toString();
+
+		final String LS = System.getProperty("line.separator");
+		assertEquals("writeObject()> null" + LS + "writeObject()< " + LS, trace);
+	}
+
+	public void testWriteObject() {
+		StringWriter sbwriter = new StringWriter();
+		VerboseEncoder enc = new VerboseEncoder(
+				new PrintWriter(sbwriter, true), false);
+		SampleBean b = new SampleBean();
+		b.setI(3);
+		b.setMyid("new name");
+		enc.writeObject(b);
+		String trace = sbwriter.toString();
+
+		final String LS = System.getProperty("line.separator");
+		int lastIndex = 0, index = 0;
+
+		index = trace
+				.indexOf(
+						"writeObject()> myid=new name"
+								+ LS
+								+ "get()> myid=new name"
+								+ LS
+								+ "get()< null"
+								+ LS
+								+ "remove()> myid=new name"
+								+ LS
+								+ "remove()< null"
+								+ LS
+								+ "writeExpression()> myid=new name=(class tests.api.java.beans.EncoderTest$SampleBean).new()"
+								+ LS, lastIndex);
+		assertTrue(lastIndex <= index);
+		lastIndex = index;
+
+		index = trace
+				.indexOf("writeObject()> myid=new name" + LS
+						+ "get()> myid=new name" + LS
+						+ "get()< myid=default ID" + LS
+						+ "writeExpression()> 3=(myid=new name).getI()" + LS,
+						lastIndex);
+		assertTrue(lastIndex <= index);
+		lastIndex = index;
+
+		index = trace.indexOf("get()> 3" + LS + "get()< 1" + LS, lastIndex);
+		assertTrue(lastIndex <= index);
+		lastIndex = index;
+
+		index = trace.indexOf(
+				"writeExpression()> new name=(myid=new name).getMyid()" + LS
+						+ "get()> new name" + LS + "get()< new name" + LS
+						+ "writeExpression()< " + LS, lastIndex);
+		assertTrue(lastIndex <= index);
+		lastIndex = index;
+
+		index = trace.indexOf(
+				"writeStatement()> (myid=new name).setMyid(new name)" + LS
+						+ "get()> myid=new name" + LS
+						+ "get()< myid=default ID" + LS + "get()> new name"
+						+ LS + "get()< new name" + LS + "writeStatement()< "
+						+ LS, lastIndex);
+		assertTrue(lastIndex <= index);
+		lastIndex = index;
+	}
+
+	public void testGetPersistenceDelegate_Null() {
+		// TODO different behavior
+		// MockEncoder enc = new MockEncoder();
+		// PersistenceDelegate pd = enc.getPersistenceDelegate(null);
+		// assertNotNull(pd);
+	}
+
+	public void testGetPersistenceDelegate_ArrayClass() {
+		MockEncoder enc = new MockEncoder();
+		PersistenceDelegate pd = enc.getPersistenceDelegate(int[].class);
+		assertFalse(pd instanceof DefaultPersistenceDelegate);
+	}
+
+	public void testGetPersistenceDelegate_ProxyClass() {
+		MockEncoder enc = new MockEncoder();
+		PersistenceDelegate pd = enc.getPersistenceDelegate(Proxy
+				.getProxyClass(ClassLoader.getSystemClassLoader(),
+						new Class[] { List.class }));
+	}
+
+	public void testGetPersistenceDelegate_BeanInfo() {
+		MockEncoder enc = new MockEncoder();
+		PersistenceDelegate pd = enc
+				.getPersistenceDelegate(MockFooLiYang.class);
+		assertTrue(pd instanceof VerbosePD);
+	}
+
+	public void testGetPersistenceDelegate_Default() {
+		MockEncoder enc = new MockEncoder();
+		MockEncoder enc2 = new MockEncoder();
+
+		PersistenceDelegate pd1 = enc.getPersistenceDelegate(SampleBean.class);
+		assertTrue(pd1 instanceof DefaultPersistenceDelegate);
+
+		PersistenceDelegate pd2 = enc.getPersistenceDelegate(SampleBean.class);
+		assertTrue(pd2 instanceof DefaultPersistenceDelegate);
+
+		PersistenceDelegate pd3 = enc2
+				.getPersistenceDelegate(MockBean4Codec.class);
+		assertTrue(pd3 instanceof DefaultPersistenceDelegate);
+
+		assertSame(pd1, pd2);
+		assertSame(pd1, pd3);
+	}
+
+	public void testSetPersistenceDelegate_Null() {
+		MockEncoder enc = new MockEncoder();
+		PersistenceDelegate pd = enc.getPersistenceDelegate(EncoderTest.class);
+
+		try {
+			enc.setPersistenceDelegate(null, pd);
+			fail();
+		} catch (NullPointerException e) {
+			// expected
+		}
+
+		try {
+			enc.setPersistenceDelegate(EncoderTest.class, null);
+			fail();
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	public void testSetPersistenceDelegate() {
+		MockEncoder enc = new MockEncoder();
+		PersistenceDelegate pd = enc.getPersistenceDelegate(EncoderTest.class);
+		assertTrue(pd instanceof DefaultPersistenceDelegate);
+
+		enc.setPersistenceDelegate(EncoderTest.class, new VerbosePD());
+		assertTrue(enc.getPersistenceDelegate(EncoderTest.class) instanceof VerbosePD);
+
+		MockEncoder enc2 = new MockEncoder();
+		assertTrue(enc.getPersistenceDelegate(EncoderTest.class) instanceof VerbosePD);
+	}
+
+	public void testGet_NullParam() {
+		MockEncoder enc = new MockEncoder();
+
+		assertNull(enc.get(null));
+	}
+
+	public void testGet_String() {
+		MockEncoder enc = new MockEncoder();
+
+		String str = "string";
+		assertSame(str, enc.get(str));
+	}
+
+	public void testGet_Integer() {
+		MockEncoder enc = new MockEncoder();
+
+		Integer integer = new Integer(8);
+		assertNull(enc.get(integer));
+		enc.writeObject(integer);
+		assertEquals(integer, enc.get(integer));
+		assertNull(enc.get(new Integer(integer.intValue())));
+
+		Double d = new Double(8);
+		assertNull(enc.get(d));
+		enc.writeObject(d);
+		assertEquals(d, enc.get(d));
+	}
+
+	public void testRemove_Null() {
+		MockEncoder enc = new MockEncoder();
+
+		assertNull(enc.remove(null));
+	}
+
+	public void testRemove_String() {
+		MockEncoder enc = new MockEncoder();
+
+		String str = "string";
+		assertSame(str, enc.get(str));
+		assertNull(enc.remove(str));
+
+		enc.writeObject(str);
+		assertSame(str, enc.get(str));
+		assertNull(enc.remove(str));
+	}
+
+	public void testRemove_Integer() {
+		MockEncoder enc = new MockEncoder();
+
+		Integer integer = new Integer(8);
+		assertNull(enc.remove(integer));
+
+		enc.writeObject(integer);
+		assertEquals(integer, enc.get(integer));
+		assertEquals(integer, enc.remove(integer));
+
+		assertNull(enc.get(integer));
+		assertNull(enc.remove(integer));
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/EventHandlerTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/EventHandlerTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/EventHandlerTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/EventHandlerTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,971 @@
+/* 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.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.EventListener;
+import java.util.EventObject;
+
+import junit.framework.TestCase;
+import tests.api.java.beans.mock.MockButton;
+
+/**
+ * Unit test for EventHandler.
+ */
+public class EventHandlerTest extends TestCase {
+
+	/*
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+	}
+
+	/*
+	 * @see TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	/*
+	 * Class under test for Object create(Class, Object, String)
+	 */
+	public void testCreateClassObjectString() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "setCalled");
+		button.addPropertyChangeListener(proxy);
+		button.setLabel("new label value");
+		assertTrue(Proxy.isProxyClass(proxy.getClass()));
+		assertTrue(target.isCalled());
+	}
+
+	/*
+	 * listenerInterface class is null
+	 */
+	public void testCreateClassObjectString_ClassNull() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		try {
+			PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+					.create(null, target, "setCalled");
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	/*
+	 * listenerInterface is not a interface
+	 */
+	public void testCreateClassObjectString_ClassInvalid() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		try {
+			PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+					.create(MockButton.class, target, "setCalled");
+			fail("Should throw IllegalArgumentException.");
+		} catch (IllegalArgumentException e) {
+		}
+	}
+
+	/*
+	 * the target object is null
+	 */
+	public void testCreateClassObjectString_ObjectNull() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		try {
+			PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+					.create(PropertyChangeListener.class, null, "setCalled");
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	/*
+	 * the target's method is null
+	 */
+	public void testCreateClassObjectString_MethodNull() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, null);
+		button.addPropertyChangeListener(proxy);
+		try {
+			button.setLabel("new label value");
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+		assertTrue(Proxy.isProxyClass(proxy.getClass()));
+	}
+
+	/*
+	 * the target's method is invalid
+	 */
+	public void testCreateClassObjectString_MethodEmpty() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "");
+		button.addPropertyChangeListener(proxy);
+		try {
+			button.setLabel("new label value");
+			fail("Should throw IndexOutOfBoundsException.");
+		} catch (IndexOutOfBoundsException e) {
+		}
+		assertTrue(Proxy.isProxyClass(proxy.getClass()));
+	}
+
+	/*
+	 * Class under test for Object create(Class, Object, String, String)
+	 */
+	public void testCreateClassObjectStringString() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "text",
+						"source.label");
+		assertTrue(Proxy.isProxyClass(proxy.getClass()));
+
+		button.addPropertyChangeListener(proxy);
+		String newLabel = "New Value: set text.";
+		button.setLabel(newLabel);
+		assertEquals(MockButton.defaultName, target.getText());
+		button.setLabel("New Value: set text2.");
+		assertEquals(newLabel, target.getText());
+	}
+
+	/*
+	 * listenerInterface is null
+	 */
+	public void testCreateClassObjectStringString_ClassNull() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		try {
+			PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+					.create(null, target, "text", "source.label");
+			fail("Should throw NullPointerException");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	/*
+	 * listenerInterface is not a interface
+	 */
+	public void testCreateClassObjectStringString_ClassInvalid() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		try {
+			PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+					.create(String.class, target, "text", "source.label");
+			fail("Should throw IllegalArgumentException");
+		} catch (IllegalArgumentException e) {
+		}
+	}
+
+	/*
+	 * the target object is null
+	 */
+	public void testCreateClassObjectStringString_TargetNull() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		try {
+			PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+					.create(PropertyChangeListener.class, null, "text",
+							"source.label");
+			fail("Should throw NullPointerException");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	/*
+	 * the action is null
+	 */
+	public void testCreateClassObjectStringString_ActionNull() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, null,
+						"source.label");
+		assertTrue(Proxy.isProxyClass(proxy.getClass()));
+
+		button.addPropertyChangeListener(proxy);
+		String newLabel = "New Value: set text.";
+		try {
+			button.setLabel(newLabel);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	/*
+	 * action is invalid
+	 */
+	public void testCreateClassObjectStringString_ActionInvalid() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "action_invalid",
+						"source.label");
+		assertTrue(Proxy.isProxyClass(proxy.getClass()));
+
+		button.addPropertyChangeListener(proxy);
+		String newLabel = "New Value: set text.";
+		try {
+			button.setLabel(newLabel);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	/*
+	 * propertyname is null
+	 */
+	public void testCreateClassObjectStringString_PropertyNameNull() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "text", null);
+		assertTrue(Proxy.isProxyClass(proxy.getClass()));
+
+		button.addPropertyChangeListener(proxy);
+		String newLabel = "New Value: set text.";
+		try {
+			button.setLabel(newLabel);
+			fail("Should throw NullPointerException.");
+		} catch (Exception e) {
+		}
+	}
+
+	/*
+	 * property name is invalid
+	 */
+	public void testCreateClassObjectStringString_PropertyNameInvalid() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "text",
+						"source.label_invalid");
+		assertTrue(Proxy.isProxyClass(proxy.getClass()));
+
+		button.addPropertyChangeListener(proxy);
+		String newLabel = "New Value: set text.";
+		try {
+			button.setLabel(newLabel);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	/*
+	 * Class under test for Object create(Class, Object, String, String, String)
+	 */
+	public void testCreateClassObjectStringStringString() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "text",
+						"source.label", "propertyChange");
+		assertTrue(Proxy.isProxyClass(proxy.getClass()));
+
+		button.addPropertyChangeListener(proxy);
+		String newLabel = "New Value: set text.";
+		button.setLabel(newLabel);
+		assertEquals(MockButton.defaultName, target.getText());
+		button.setLabel("New Value: set text2.");
+		assertEquals(newLabel, target.getText());
+	}
+
+	/*
+	 * listenerInterface is null
+	 */
+	public void testCreateClassObjectStringStringString_ClassNull() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		try {
+			PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+					.create(null, target, "text", "source.label",
+							"propertyChange");
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+
+		}
+	}
+
+	/*
+	 * listenerInterface is invalid
+	 */
+	public void testCreateClassObjectStringStringString_ClassInvalid() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		try {
+			PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+					.create(Serializable.class, target, "text", "source.label",
+							"propertyChange");
+			fail("Should throw ClassCastException.");
+		} catch (ClassCastException e) {
+		}
+	}
+
+	/*
+	 * the target object is null
+	 */
+	public void testCreateClassObjectStringStringString_TargetNull() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		try {
+			PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+					.create(PropertyChangeListener.class, null, "text",
+							"source.label", "propertyChange");
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	/*
+	 * action is null
+	 */
+	public void testCreateClassObjectStringStringString_ActionNull() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, null,
+						"source.label", "propertyChange");
+		assertTrue(Proxy.isProxyClass(proxy.getClass()));
+
+		button.addPropertyChangeListener(proxy);
+		String newLabel = "New Value: set text.";
+		try {
+			button.setLabel(newLabel);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	/*
+	 * action is invalid
+	 */
+	public void testCreateClassObjectStringStringString_ActionInvalid() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "text_invalid",
+						"source.label", "propertyChange");
+		assertTrue(Proxy.isProxyClass(proxy.getClass()));
+
+		button.addPropertyChangeListener(proxy);
+		String newLabel = "New Value: set text.";
+		try {
+			button.setLabel(newLabel);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	/*
+	 * property name is null
+	 */
+	public void testCreateClassObjectStringStringString_PropertyNull() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "text", null,
+						"propertyChange");
+		assertTrue(Proxy.isProxyClass(proxy.getClass()));
+
+		button.addPropertyChangeListener(proxy);
+		String newLabel = "New Value: set text.";
+		try {
+			button.setLabel(newLabel);
+			fail("Should throw NullPointerException.");
+		} catch (Exception e) {
+		}
+	}
+
+	/*
+	 * property name is invalid
+	 */
+	public void testCreateClassObjectStringStringString_PropertyInvalid() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "text",
+						"source.label.invalid", "propertyChange");
+		assertTrue(Proxy.isProxyClass(proxy.getClass()));
+
+		button.addPropertyChangeListener(proxy);
+		String newLabel = "New Value: set text.";
+		try {
+			button.setLabel(newLabel);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	/*
+	 * listenerMethodName is null
+	 */
+	public void testCreateClassObjectStringStringString_MethodNull() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "text",
+						"source.label", null);
+		assertTrue(Proxy.isProxyClass(proxy.getClass()));
+
+		button.addPropertyChangeListener(proxy);
+		String newLabel = "New Value: set text.";
+		button.setLabel(newLabel);
+		assertEquals(MockButton.defaultName, target.getText());
+		button.setLabel("New Value: set text2.");
+		assertEquals(newLabel, target.getText());
+	}
+
+	/*
+	 * listenerMethodName is invalid
+	 */
+	public void testCreateClassObjectStringStringString_MethodInvalid() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "text",
+						"source.label", "propertyChange_invalid");
+		assertTrue(Proxy.isProxyClass(proxy.getClass()));
+
+		button.addPropertyChangeListener(proxy);
+		String newLabel = "New Value: set text.";
+		button.setLabel(newLabel);
+		assertNull(target.getText());
+	}
+
+	/*
+	 * public EventHandler(Object target, String action, String
+	 * eventPropertyName, String listenerMethodName)
+	 */
+	public void testEventHandler() {
+		MockTarget target = new MockTarget();
+		String action = "text";
+		String eventPropertyName = "source.label";
+		String listenerMethodName = "propertyChange";
+		EventHandler handler = new EventHandler(target, action,
+				eventPropertyName, listenerMethodName);
+		assertSame(target, handler.getTarget());
+		assertSame(action, handler.getAction());
+		assertSame(eventPropertyName, handler.getEventPropertyName());
+		assertSame(listenerMethodName, handler.getListenerMethodName());
+	}
+
+	/*
+	 * target is null
+	 */
+	public void testEventHandler_TargetNull() {
+		String action = "text";
+		String eventPropertyName = "source.label";
+		String listenerMethodName = "propertyChange";
+		EventHandler handler = new EventHandler(null, action,
+				eventPropertyName, listenerMethodName);
+		assertNull(handler.getTarget());
+		assertSame(action, handler.getAction());
+		assertSame(eventPropertyName, handler.getEventPropertyName());
+		assertSame(listenerMethodName, handler.getListenerMethodName());
+	}
+
+	/*
+	 * action is null
+	 */
+	public void testEventHandler_ActionNull() {
+		MockTarget target = new MockTarget();
+		String eventPropertyName = "source.label";
+		String listenerMethodName = "propertyChange";
+		EventHandler handler = new EventHandler(target, null,
+				eventPropertyName, listenerMethodName);
+		assertSame(target, handler.getTarget());
+		assertNull(handler.getAction());
+		assertSame(eventPropertyName, handler.getEventPropertyName());
+		assertSame(listenerMethodName, handler.getListenerMethodName());
+	}
+
+	/*
+	 * EventProperty is null
+	 */
+	public void testEventHandler_EventPropertyNull() {
+		MockTarget target = new MockTarget();
+		String action = "text";
+		String listenerMethodName = "propertyChange";
+		EventHandler handler = new EventHandler(target, action, null,
+				listenerMethodName);
+		assertSame(target, handler.getTarget());
+		assertSame(action, handler.getAction());
+		assertNull(handler.getEventPropertyName());
+		assertSame(listenerMethodName, handler.getListenerMethodName());
+	}
+
+	/*
+	 * Method is null
+	 */
+	public void testEventHandler_MethodNull() {
+		MockTarget target = new MockTarget();
+		String action = "text";
+		String eventPropertyName = "source.label";
+		EventHandler handler = new EventHandler(target, action,
+				eventPropertyName, null);
+		assertSame(target, handler.getTarget());
+		assertSame(action, handler.getAction());
+		assertSame(eventPropertyName, handler.getEventPropertyName());
+		assertNull(handler.getListenerMethodName());
+	}
+
+	public void testInvoke_1() throws SecurityException, NoSuchMethodException {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "setCalled");
+
+		PropertyChangeListener proxy2 = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "setCalled");
+
+		String action = "text";
+		String eventPropertyName = "source.label";
+		EventHandler handler = new EventHandler(target, action,
+				eventPropertyName, null);
+		Method listenerMethod = PropertyChangeListener.class.getMethod(
+				"propertyChange", new Class[] { PropertyChangeEvent.class });
+		PropertyChangeEvent event = new PropertyChangeEvent(button, "label",
+				"1", "5");
+		handler.invoke(proxy, listenerMethod, new Object[] { event });
+		assertEquals(button.getLabel(), target.getText());
+		Method equalsMethod = Object.class.getMethod("equals",
+				new Class[] { Object.class });
+		assertEquals(Boolean.FALSE, handler.invoke(proxy, equalsMethod,
+				new String[] { "mock" }));
+	}
+
+	public void testIncompatibleMethod() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "Text", "source");
+		assertTrue(Proxy.isProxyClass(proxy.getClass()));
+
+		button.addPropertyChangeListener(proxy);
+		String newLabel = "New Value: set text.";
+		try {
+			button.setLabel(newLabel);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+
+		}
+	}
+
+	public void testCoverage_1() {
+		MockTarget target = new MockTarget();
+		MockButton button = new MockButton();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "Text", "");
+		assertTrue(Proxy.isProxyClass(proxy.getClass()));
+
+		button.addPropertyChangeListener(proxy);
+		String newLabel = "New Value: set text.";
+		try {
+			button.setLabel(newLabel);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+
+		}
+
+	}
+
+	public void testInvoke_extend1() {
+		MockFish fish = new MockFish();
+		MockFishTarget target = new MockFishTarget();
+		PropertyChangeSupport support = new PropertyChangeSupport(fish);
+		Object proxy = EventHandler.create(PropertyChangeListener.class,
+				target, "action1");
+		support.addPropertyChangeListener((PropertyChangeListener) proxy);
+		PropertyChangeEvent event = new PropertyChangeEvent(fish, "name", "1",
+				"5");
+		support.firePropertyChange(event);
+		assertEquals("action1", target.getActionRecord());
+	}
+
+	public void testInvoke_extend1_1() {
+		MockFish fish = new MockFish();
+		MockFishTarget target = new MockFishTarget();
+		PropertyChangeSupport support = new PropertyChangeSupport(fish);
+		Object proxy = EventHandler.create(PropertyChangeListener.class,
+				target, "action4");
+		support.addPropertyChangeListener((PropertyChangeListener) proxy);
+		PropertyChangeEvent event = new PropertyChangeEvent(fish, "name", "1",
+				"5");
+		try {
+			support.firePropertyChange(event);
+		} catch (Exception e) {
+
+		}
+		assertEquals("action4", target.getActionRecord());
+	}
+
+	public void testInvoke_extend2() {
+		MockFish fish = new MockFish();
+		MockFishTarget target = new MockFishTarget();
+		PropertyChangeSupport support = new PropertyChangeSupport(fish);
+		Object proxy = EventHandler.create(PropertyChangeListener.class,
+				target, "action2");
+		support.addPropertyChangeListener((PropertyChangeListener) proxy);
+		PropertyChangeEvent event = new PropertyChangeEvent(fish, "name", "1",
+				"5");
+		try {
+			support.firePropertyChange(event);
+			fail("Should throw exception");
+		} catch (Exception e) {
+			// e.printStackTrace();
+		}
+
+	}
+
+	public void testInvoke_extend2_2() {
+		MockFish fish = new MockFish();
+		MockFishTarget target = new MockFishTarget();
+		PropertyChangeSupport support = new PropertyChangeSupport(fish);
+		Object proxy = EventHandler.create(PropertyChangeListener.class,
+				target, "action3");
+		support.addPropertyChangeListener((PropertyChangeListener) proxy);
+		PropertyChangeEvent event = new PropertyChangeEvent(fish, "name", "1",
+				"5");
+		support.firePropertyChange(event);
+
+		assertEquals("action3", target.getActionRecord());
+	}
+
+	public void testInvoke_extend3() {
+		MockFish fish = new MockFish();
+		MockFishTarget target = new MockFishTarget();
+		PropertyChangeSupport support = new PropertyChangeSupport(fish);
+		Object proxy = EventHandler.create(PropertyChangeListener.class,
+				target, "a", "source.a");
+		support.addPropertyChangeListener((PropertyChangeListener) proxy);
+		PropertyChangeEvent event = new PropertyChangeEvent(fish, "name", "1",
+				"5");
+		support.firePropertyChange(event);
+		assertEquals("boolean:true", target.getActionRecord());
+	}
+
+	public void testInvoke_extend4() {
+		MockFish fish = new MockFish();
+		MockFishTarget target = new MockFishTarget();
+		PropertyChangeSupport support = new PropertyChangeSupport(fish);
+		Object proxy = EventHandler.create(PropertyChangeListener.class,
+				target, "b", "source.a");
+		support.addPropertyChangeListener((PropertyChangeListener) proxy);
+		PropertyChangeEvent event = new PropertyChangeEvent(fish, "name", "1",
+				"5");
+		support.firePropertyChange(event);
+		assertEquals("Boolean:true", target.getActionRecord());
+	}
+
+	public void testInvoke_extend4_BooleanObject() {
+		MockFish fish = new MockFish();
+		MockFishTarget target = new MockFishTarget();
+		PropertyChangeSupport support = new PropertyChangeSupport(fish);
+		Object proxy = EventHandler.create(PropertyChangeListener.class,
+				target, "a", "source.booleanObject");
+		support.addPropertyChangeListener((PropertyChangeListener) proxy);
+		PropertyChangeEvent event = new PropertyChangeEvent(fish, "name", "1",
+				"5");
+		support.firePropertyChange(event);
+		assertEquals("boolean:true", target.getActionRecord());
+	}
+
+	public void testInvoke_extend5() {
+		MockFish fish = new MockFish();
+		MockFishTarget target = new MockFishTarget();
+		PropertyChangeSupport support = new PropertyChangeSupport(fish);
+		Object proxy = EventHandler.create(PropertyChangeListener.class,
+				target, "int", "source.int");
+		support.addPropertyChangeListener((PropertyChangeListener) proxy);
+		PropertyChangeEvent event = new PropertyChangeEvent(fish, "name", "1",
+				"5");
+		support.firePropertyChange(event);
+		assertEquals("int:1", target.getActionRecord());
+	}
+
+	public void testInvoke_extend6() {
+		MockFish fish = new MockFish();
+		MockFishTarget target = new MockFishTarget();
+		PropertyChangeSupport support = new PropertyChangeSupport(fish);
+		Object proxy = EventHandler.create(PropertyChangeListener.class,
+				target, "char", "source.char");
+		support.addPropertyChangeListener((PropertyChangeListener) proxy);
+		PropertyChangeEvent event = new PropertyChangeEvent(fish, "name", "1",
+				"5");
+		support.firePropertyChange(event);
+		assertEquals("char:a", target.getActionRecord());
+	}
+
+	public void testInvoke_extend7() {
+		MockFish fish = new MockFish();
+		MockFishTarget target = new MockFishTarget();
+		PropertyChangeSupport support = new PropertyChangeSupport(fish);
+		Object proxy = EventHandler.create(PropertyChangeListener.class,
+				target, "byte", "source.byte");
+		support.addPropertyChangeListener((PropertyChangeListener) proxy);
+		PropertyChangeEvent event = new PropertyChangeEvent(fish, "name", "1",
+				"5");
+		support.firePropertyChange(event);
+		assertEquals("byte:10", target.getActionRecord());
+	}
+
+	public void testInvoke_extend8() {
+		MockFish fish = new MockFish();
+		MockFishTarget target = new MockFishTarget();
+		PropertyChangeSupport support = new PropertyChangeSupport(fish);
+		Object proxy = EventHandler.create(PropertyChangeListener.class,
+				target, "short", "source.short");
+		support.addPropertyChangeListener((PropertyChangeListener) proxy);
+		PropertyChangeEvent event = new PropertyChangeEvent(fish, "name", "1",
+				"5");
+		support.firePropertyChange(event);
+		assertEquals("short:100", target.getActionRecord());
+	}
+
+	public void testInvoke_extend9() {
+		MockFish fish = new MockFish();
+		MockFishTarget target = new MockFishTarget();
+		PropertyChangeSupport support = new PropertyChangeSupport(fish);
+		Object proxy = EventHandler.create(PropertyChangeListener.class,
+				target, "long", "source.long");
+		support.addPropertyChangeListener((PropertyChangeListener) proxy);
+		PropertyChangeEvent event = new PropertyChangeEvent(fish, "name", "1",
+				"5");
+		support.firePropertyChange(event);
+		assertEquals("long:1000", target.getActionRecord());
+	}
+
+	public void testInvoke_extend10() {
+		MockFish fish = new MockFish();
+		MockFishTarget target = new MockFishTarget();
+		PropertyChangeSupport support = new PropertyChangeSupport(fish);
+		Object proxy = EventHandler.create(PropertyChangeListener.class,
+				target, "float", "source.float");
+		support.addPropertyChangeListener((PropertyChangeListener) proxy);
+		PropertyChangeEvent event = new PropertyChangeEvent(fish, "name", "1",
+				"5");
+		support.firePropertyChange(event);
+		assertEquals("float:2.2", target.getActionRecord());
+	}
+
+	public void testInvoke_extend11() {
+		MockFish fish = new MockFish();
+		MockFishTarget target = new MockFishTarget();
+		PropertyChangeSupport support = new PropertyChangeSupport(fish);
+		Object proxy = EventHandler.create(PropertyChangeListener.class,
+				target, "double", "source.double");
+		support.addPropertyChangeListener((PropertyChangeListener) proxy);
+		PropertyChangeEvent event = new PropertyChangeEvent(fish, "name", "1",
+				"5");
+		support.firePropertyChange(event);
+		assertEquals("double:3.3", target.getActionRecord());
+	}
+
+	public void testEventHandlerCreate() {
+		((FredListener) EventHandler.create(FredListener.class,
+				new Untitled1(), "i", "i"))
+				.fireFredEvent(new FredEvent("bean2"));
+	}
+
+	public interface FredListener extends EventListener {
+		public void fireFredEvent(FredEvent event);
+	}
+
+	public static class FredEvent extends EventObject {
+
+		private static final long serialVersionUID = 1L;
+
+		private static int i;
+
+		public FredEvent(Object source) {
+			super(source);
+		}
+
+		public static int getI() {
+			return i;
+		}
+
+		public static void setI(int j) {
+			i = j;
+		}
+	}
+
+	public static class Untitled1 {
+		private int i;
+
+		public int getI() {
+			return i;
+		}
+
+		public void setI(int i) {
+			// System.out.println("Untitled1 : setI()");
+			this.i = i;
+		}
+	}
+
+	public static class MockFish {
+		String name;
+
+		public String getName() {
+			return name;
+		}
+
+		public void setName(String name) {
+			this.name = name;
+		}
+
+		public boolean isA() {
+			return true;
+		}
+
+		public Boolean isBooleanObject() {
+			return new Boolean(true);
+		}
+
+		public int getInt() {
+			return 1;
+		}
+
+		public char getChar() {
+			return 'a';
+		}
+
+		public byte getByte() {
+			return 10;
+		}
+
+		public short getShort() {
+			return 100;
+		}
+
+		public long getLong() {
+			return 1000;
+		}
+
+		public float getFloat() {
+			return 2.2f;
+		}
+
+		public double getDouble() {
+			return 3.3;
+		}
+	}
+
+	public static class MockFishTarget {
+		String actionRecord;
+
+		public void action1() {
+			this.actionRecord = "action1";
+		}
+
+		public void setAction2(String value) {
+			this.actionRecord = "action2";
+		}
+
+		public void setAction3() {
+			this.actionRecord = "action3";
+		}
+
+		public void action4() {
+			this.actionRecord = "action4";
+		}
+
+		public void action4(EventObject event) {
+			this.actionRecord = "action4";
+		}
+
+		public String getActionRecord() {
+			return actionRecord;
+		}
+
+		public void setA(boolean value) {
+			this.actionRecord = "boolean:" + Boolean.valueOf(value).toString();
+		}
+
+		public void setB(Boolean value) {
+			this.actionRecord = "Boolean:" + value.toString();
+		}
+
+		public void setInt(int value) {
+			this.actionRecord = "int:" + value;
+		}
+
+		public void setChar(char value) {
+			this.actionRecord = "char:" + value;
+		}
+
+		public void setShort(short value) {
+			this.actionRecord = "short:" + value;
+		}
+
+		public void setByte(byte value) {
+			this.actionRecord = "byte:" + value;
+		}
+
+		public void setLong(long value) {
+			this.actionRecord = "long:" + value;
+		}
+
+		public void setFloat(float value) {
+			this.actionRecord = "float:" + value;
+		}
+
+		public void setDouble(double value) {
+			this.actionRecord = "double:" + value;
+		}
+
+	}
+
+	public static class MockTarget {
+		private boolean called;
+
+		private String text;
+
+		public MockTarget() {
+			this.called = false;
+		}
+
+		public void setCalled() {
+			this.called = true;
+		}
+
+		public boolean isCalled() {
+			return this.called;
+		}
+
+		public void setText(String text) {
+			this.text = text;
+		}
+
+		public String getText() {
+			return this.text;
+		}
+	}
+}