harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r394923 [9/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...
Date Tue, 18 Apr 2006 12:11:45 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyEditorManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyEditorManagerTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyEditorManagerTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyEditorManagerTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,691 @@
+/* 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.awt.Component;
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyEditor;
+import java.beans.PropertyEditorManager;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+import tests.api.java.beans.mock.Foz;
+import tests.api.java.beans.mock.FozDefault;
+import tests.api.java.beans.mock.Fozz;
+import tests.api.java.beans.mock.FozzEditor;
+import tests.api.java.beans.mock.Fozzz;
+import tests.api.java.beans.mock.MockButton;
+import tests.api.java.beans.mock.MockFoo;
+
+/**
+ * Unit test for PropertyEditorManager
+ */
+public class PropertyEditorManagerTest extends TestCase {
+
+	/*
+	 * Constructors
+	 */
+	public void testPropertyEditorManager() {
+		PropertyEditorManager managers = new PropertyEditorManager();
+	}
+
+	/*
+	 * find the editor which has been registered through registerEditor.
+	 */
+	public void testFindEditor_registered() {
+		Class editorClass = FozRegisteredEditor.class;
+		Class type = Foz.class;
+		PropertyEditorManager.registerEditor(type, editorClass);
+		PropertyEditor editor = PropertyEditorManager.findEditor(type);
+		assertTrue(editor instanceof FozRegisteredEditor);
+		assertEquals(editorClass, editor.getClass());
+	}
+
+	/*
+	 * Find editor of which name is XXXEditor in the same package
+	 */
+	public void testFindEditor_SamePackage() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Fozz.class);
+		assertTrue(editor instanceof FozzEditor);
+		assertEquals(FozzEditor.class, editor.getClass());
+	}
+
+	/*
+	 * Find editor in search path
+	 */
+	public void testFindEditor_DifferentPackage() {
+		String[] original = PropertyEditorManager.getEditorSearchPath();
+		PropertyEditorManager
+				.setEditorSearchPath(new String[] { "tests.api.java.beans" });
+		PropertyEditor editor = PropertyEditorManager.findEditor(Fozzz.class);
+		assertTrue(editor instanceof FozzzEditor);
+		assertEquals(FozzzEditor.class, editor.getClass());
+
+		PropertyEditorManager.setEditorSearchPath(original);
+	}
+
+	/*
+	 * Find editor for Java primitive types and java.lang.String.
+	 * java.awt.Color, and java.awt.Font
+	 */
+	public void testFindEditor_DefaultType() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Integer.TYPE);
+	}
+
+	public void testFindEditor_TypeNull() {
+		try {
+			PropertyEditor editor = PropertyEditorManager.findEditor(null);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	public void testFindEditor_TypeNoEditor() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(MockFoo.class);
+		assertNull(editor);
+	}
+
+	public void testGetEditorSearchPath_default() {
+		String[] path = PropertyEditorManager.getEditorSearchPath();
+		assertEquals(1, path.length);
+		assertEquals("sun.beans.editors", path[0]);
+	}
+
+	public void testGetEditorSearchPath() {
+		String[] original = PropertyEditorManager.getEditorSearchPath();
+
+		String[] path = new String[] { "java.beans",
+				"tests.api.java.beans.editor", "", };
+		PropertyEditorManager.setEditorSearchPath(path);
+		String[] newPath = PropertyEditorManager.getEditorSearchPath();
+
+		assertTrue(Arrays.equals(path, newPath));
+
+		PropertyEditorManager.setEditorSearchPath(original);
+	}
+
+	/*
+	 * RegisterEditor
+	 */
+	public void testRegisterEditor() {
+		Class type = MockButton.class;
+
+		PropertyEditorManager.registerEditor(type, ButtonEditor.class);
+		PropertyEditor editor = PropertyEditorManager.findEditor(type);
+		assertEquals(ButtonEditor.class, editor.getClass());
+
+		PropertyEditorManager.registerEditor(type, FozRegisteredEditor.class);
+		editor = PropertyEditorManager.findEditor(type);
+		assertEquals(FozRegisteredEditor.class, editor.getClass());
+
+		PropertyEditorManager.registerEditor(type, null);
+		editor = PropertyEditorManager.findEditor(type);
+		assertNull(editor);
+	}
+
+	/*
+	 * registerEditor for type null
+	 */
+	public void testRegisterEditorType_Null() {
+		try {
+			PropertyEditorManager.registerEditor(null, ButtonEditor.class);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * set search path as {null}
+	 */
+	public void testSetEditorSearchPath_nullpath() {
+		String[] original = PropertyEditorManager.getEditorSearchPath();
+		PropertyEditorManager.setEditorSearchPath(new String[] { null });
+		assertEquals(1, PropertyEditorManager.getEditorSearchPath().length);
+		assertNull(PropertyEditorManager.getEditorSearchPath()[0]);
+		PropertyEditorManager.setEditorSearchPath(original);
+	}
+
+	/*
+	 * set search null
+	 */
+	public void testSetEditorSearchPath_null() {
+		String[] original = PropertyEditorManager.getEditorSearchPath();
+		PropertyEditorManager.setEditorSearchPath(null);
+		assertEquals(0, PropertyEditorManager.getEditorSearchPath().length);
+		PropertyEditorManager.setEditorSearchPath(original);
+	}
+
+	// Test internal Editor
+	public void testBoolEditor_setAsText() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Boolean.TYPE);
+		editor.setAsText("false");
+		assertEquals("false", editor.getAsText().toLowerCase());
+		assertEquals("false", editor.getJavaInitializationString());
+		assertEquals("True", editor.getTags()[0]);
+		assertEquals("False", editor.getTags()[1]);
+		assertEquals(Boolean.FALSE, editor.getValue());
+
+		editor.setAsText("TrUE");
+		assertEquals("true", editor.getAsText().toLowerCase());
+		assertEquals("true", editor.getJavaInitializationString());
+		assertEquals(Boolean.TRUE, editor.getValue());
+	}
+
+	public void testBoolEditor_setAsText_null() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Boolean.TYPE);
+		try {
+			editor.setAsText(null);
+			fail("Should throw a Exception");
+		} catch (Exception e) {
+		}
+	}
+
+	public void testBoolEditor_setAsText_Invalid() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Boolean.TYPE);
+		try {
+			editor.setAsText("***true***");
+			fail("Should throw a IllegalArgumentException");
+		} catch (IllegalArgumentException e) {
+		}
+	}
+
+	public void testByteEditor() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Byte.TYPE);
+		byte b = (byte) 0x7F;
+		editor.setAsText(Byte.toString(b));
+		assertEquals(Byte.toString(b), editor.getAsText());
+		assertEquals("((byte)127)", editor.getJavaInitializationString());
+		assertEquals(new Byte(b), editor.getValue());
+		assertNull(editor.getTags());
+	}
+
+	public void testByteEditor_null() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Byte.TYPE);
+		try {
+			editor.setAsText(null);
+			fail("Should throw a NumberFormatException");
+		} catch (NumberFormatException e) {
+
+		}
+	}
+
+	public void testByteEditor_invalid() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Byte.TYPE);
+		try {
+			editor.setAsText("invalid");
+			fail("Should throw a NumberFormatException");
+		} catch (NumberFormatException e) {
+
+		}
+	}
+
+	public void testByteEditor_invalid2() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Byte.TYPE);
+		try {
+			editor.setAsText("128");
+			fail("Should throw a NumberFormatException");
+		} catch (NumberFormatException e) {
+
+		}
+	}
+
+	public void testDoubleEditor() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Double.TYPE);
+		double d = 12345.678;
+		editor.setAsText(Double.toString(d));
+		assertEquals(Double.toString(d), editor.getAsText());
+		assertEquals(Double.toString(d), editor.getJavaInitializationString());
+		assertEquals(new Double(d), editor.getValue());
+		assertNull(editor.getTags());
+	}
+
+	public void testDoubleEditor_SetAsText_Null() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Double.TYPE);
+		try {
+			editor.setAsText(null);
+			fail("Should throw a NullPointerException");
+		} catch (NullPointerException e) {
+
+		}
+	}
+
+	public void testDoubleEditor_SetAsText_Invalid() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Double.TYPE);
+		try {
+			editor.setAsText("invalid");
+			fail("Should throw a NumberFormatException");
+		} catch (NumberFormatException e) {
+
+		}
+	}
+
+	public void testFloatEditor() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Float.TYPE);
+		float f = 12345.678f;
+		String text = Float.toString(f);
+		editor.setAsText(text);
+		assertEquals(text, editor.getAsText());
+		assertEquals(text + "F", editor.getJavaInitializationString());
+		assertEquals(new Float(f), editor.getValue());
+		assertNull(editor.getTags());
+	}
+
+	public void testFloatEditor_SetAsText_Null() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Float.TYPE);
+		try {
+			editor.setAsText(null);
+			fail("Should throw a NullPointerException");
+		} catch (NullPointerException e) {
+
+		}
+	}
+
+	public void testFloatEditor_SetAsText_Invalid() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Float.TYPE);
+		try {
+			editor.setAsText("invalid");
+			fail("Should throw a NumberFormatException");
+		} catch (NumberFormatException e) {
+
+		}
+	}
+
+	public void testLongEditor() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Long.TYPE);
+		long l = 123456789;
+		String text = Long.toString(l);
+		editor.setAsText(text);
+		assertEquals(text, editor.getAsText());
+		assertEquals(text + "L", editor.getJavaInitializationString());
+		assertEquals(new Long(l), editor.getValue());
+		assertNull(editor.getTags());
+	}
+
+	public void testLongEditor_SetAsText_Null() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Long.TYPE);
+		try {
+			editor.setAsText(null);
+			fail("Should throw a NumberFormatException");
+		} catch (NumberFormatException e) {
+
+		}
+	}
+
+	public void testLongEditor_SetAsText_Invalid() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Long.TYPE);
+		try {
+			editor.setAsText("invalid");
+			fail("Should throw a NumberFormatException");
+		} catch (NumberFormatException e) {
+
+		}
+	}
+
+	public void testShortEditor() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Short.TYPE);
+		short s = (short) 123456789;
+		String text = Short.toString(s);
+		editor.setAsText(text);
+		assertEquals(text, editor.getAsText());
+		assertEquals("((short)" + text + ")", editor
+				.getJavaInitializationString());
+		assertEquals(new Short(s), editor.getValue());
+		assertNull(editor.getTags());
+	}
+
+	public void testShortEditor_SetAsText_Null() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Short.TYPE);
+		try {
+			editor.setAsText(null);
+			fail("Should throw a NumberFormatException");
+		} catch (NumberFormatException e) {
+
+		}
+	}
+
+	public void testShortEditor_SetAsText_Invalid() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Short.TYPE);
+		try {
+			editor.setAsText("invalid");
+			fail("Should throw a NumberFormatException");
+		} catch (NumberFormatException e) {
+
+		}
+	}
+
+	public void testIntegerEditor() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Integer.TYPE);
+		int i = 123456789;
+		String text = Integer.toString(i);
+		editor.setAsText(text);
+		assertEquals(text, editor.getAsText());
+		assertEquals(text, editor.getJavaInitializationString());
+		assertEquals(new Integer(i), editor.getValue());
+		assertNull(editor.getTags());
+	}
+
+	public void testIntegerEditor_SetAsText_Null() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Integer.TYPE);
+		try {
+			editor.setAsText(null);
+			fail("Should throw a NumberFormatException");
+		} catch (NumberFormatException e) {
+
+		}
+	}
+
+	public void testIntegerEditor_SetAsText_Invalid() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(Integer.TYPE);
+		try {
+			editor.setAsText("invalid");
+			fail("Should throw a NumberFormatException");
+		} catch (NumberFormatException e) {
+
+		}
+	}
+
+	public void testStringEditor() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(String.class);
+		String text = "A sample string";
+		editor.setAsText(text);
+		assertEquals(text, editor.getAsText());
+		assertEquals("\"" + text + "\"", editor.getJavaInitializationString());
+		assertEquals(text, editor.getValue());
+		assertNull(editor.getTags());
+	}
+
+	public void testStringEditor_SetAsText_Null() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(String.class);
+
+		editor.setAsText("null");
+		assertEquals("null", editor.getAsText());
+		assertEquals("\"null\"", editor.getJavaInitializationString());
+		assertEquals("null", editor.getValue());
+
+		editor.setAsText("");
+		assertEquals("", editor.getAsText());
+		assertEquals("\"\"", editor.getJavaInitializationString());
+
+		editor.setAsText(null);
+		assertEquals("null", editor.getAsText());
+		assertEquals("null", editor.getJavaInitializationString());
+		assertNull(editor.getValue());
+	}
+
+	public void testStringEditor_SetAsText_SpecialChars() {
+		PropertyEditor editor = PropertyEditorManager.findEditor(String.class);
+		String str = "\n\t\\a\"";
+		editor.setAsText(str);
+		assertEquals(str, editor.getAsText());
+		assertEquals("\"\\n\\u0009\\\\a\\\"\"", editor
+				.getJavaInitializationString());
+	}
+
+	public static class FozRegisteredEditor implements PropertyEditor {
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#addPropertyChangeListener(java.beans.PropertyChangeListener)
+		 */
+		public void addPropertyChangeListener(PropertyChangeListener listener) {
+			// TO DO Auto-generated method stub
+
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#getAsText()
+		 */
+		public String getAsText() {
+			// TO DO Auto-generated method stub
+			return null;
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#getCustomEditor()
+		 */
+		public Component getCustomEditor() {
+			// TO DO Auto-generated method stub
+			return null;
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#getJavaInitializationString()
+		 */
+		public String getJavaInitializationString() {
+			// TO DO Auto-generated method stub
+			return null;
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#getTags()
+		 */
+		public String[] getTags() {
+			// TO DO Auto-generated method stub
+			return null;
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#getValue()
+		 */
+		public Object getValue() {
+			// TO DO Auto-generated method stub
+			return null;
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#isPaintable()
+		 */
+		public boolean isPaintable() {
+			// TO DO Auto-generated method stub
+			return false;
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#paintValue(java.awt.Graphics,
+		 *      java.awt.Rectangle)
+		 */
+		public void paintValue(Graphics graphics, Rectangle box) {
+			// TO DO Auto-generated method stub
+
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#removePropertyChangeListener(java.beans.PropertyChangeListener)
+		 */
+		public void removePropertyChangeListener(PropertyChangeListener listener) {
+			// TO DO Auto-generated method stub
+
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#setAsText(java.lang.String)
+		 */
+		public void setAsText(String text) throws IllegalArgumentException {
+			// TO DO Auto-generated method stub
+
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#setValue(java.lang.Object)
+		 */
+		public void setValue(Object value) {
+			// TO DO Auto-generated method stub
+
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#supportsCustomEditor()
+		 */
+		public boolean supportsCustomEditor() {
+			// TO DO Auto-generated method stub
+			return false;
+		}
+
+	}
+
+	public static class ButtonEditor implements PropertyEditor {
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#addPropertyChangeListener(java.beans.PropertyChangeListener)
+		 */
+		public void addPropertyChangeListener(PropertyChangeListener listener) {
+			// TO DO Auto-generated method stub
+
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#getAsText()
+		 */
+		public String getAsText() {
+			// TO DO Auto-generated method stub
+			return null;
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#getCustomEditor()
+		 */
+		public Component getCustomEditor() {
+			// TO DO Auto-generated method stub
+			return null;
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#getJavaInitializationString()
+		 */
+		public String getJavaInitializationString() {
+			// TO DO Auto-generated method stub
+			return null;
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#getTags()
+		 */
+		public String[] getTags() {
+			// TO DO Auto-generated method stub
+			return null;
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#getValue()
+		 */
+		public Object getValue() {
+			// TO DO Auto-generated method stub
+			return null;
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#isPaintable()
+		 */
+		public boolean isPaintable() {
+			// TO DO Auto-generated method stub
+			return false;
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#paintValue(java.awt.Graphics,
+		 *      java.awt.Rectangle)
+		 */
+		public void paintValue(Graphics graphics, Rectangle box) {
+			// TO DO Auto-generated method stub
+
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#removePropertyChangeListener(java.beans.PropertyChangeListener)
+		 */
+		public void removePropertyChangeListener(PropertyChangeListener listener) {
+			// TO DO Auto-generated method stub
+
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#setAsText(java.lang.String)
+		 */
+		public void setAsText(String text) throws IllegalArgumentException {
+			// TO DO Auto-generated method stub
+
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#setValue(java.lang.Object)
+		 */
+		public void setValue(Object value) {
+			// TO DO Auto-generated method stub
+
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see java.beans.PropertyEditor#supportsCustomEditor()
+		 */
+		public boolean supportsCustomEditor() {
+			// TO DO Auto-generated method stub
+			return false;
+		}
+
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyEditorSupportTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyEditorSupportTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyEditorSupportTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyEditorSupportTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,391 @@
+/* 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.PropertyEditorSupport;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit test of PropertyEditorSupport
+ */
+public class PropertyEditorSupportTest extends TestCase {
+
+	/*
+	 * Class under test for void PropertyEditorSupport()
+	 */
+	public void testPropertyEditorSupport() {
+		MockPropertyEditorSupport support = new MockPropertyEditorSupport();
+
+		assertEquals("null", support.getAsText());
+		assertNull(support.getValue());
+		assertNull(support.getCustomEditor());
+		assertEquals("???", support.getJavaInitializationString());
+		assertNull(support.getTags());
+		assertFalse(support.supportsCustomEditor());
+		assertFalse(support.isPaintable());
+	}
+
+	/*
+	 * Class under test for void PropertyEditorSupport(Object)
+	 */
+	public void testPropertyEditorSupportObject() {
+		MockSource source = new MockSource();
+		MockPropertyEditorSupport support = new MockPropertyEditorSupport(
+				source);
+
+		assertEquals("null", support.getAsText());
+		assertNull(support.getValue());
+		assertNull(support.getCustomEditor());
+		assertEquals("???", support.getJavaInitializationString());
+		assertNull(support.getTags());
+		assertFalse(support.supportsCustomEditor());
+		assertFalse(support.isPaintable());
+	}
+
+	/*
+	 * source null
+	 */
+	public void testPropertyEditorSupportObject_null() {
+		try {
+			MockPropertyEditorSupport support = new MockPropertyEditorSupport(
+					null);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * public void addPropertyChangeListener(PropertyChangeListener listener)
+	 */
+	public void testAddPropertyChangeListener() {
+		MockTarget target = new MockTarget();
+		MockPropertyEditorSupport support = new MockPropertyEditorSupport();
+		support.addPropertyChangeListener((PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "setCalled"));
+		support.firePropertyChange();
+
+		assertEquals("called", target.getLabel());
+	}
+
+	public void testAddPropertyChangeListener_source() {
+		MockTarget target = new MockTarget();
+		MockSource source = new MockSource();
+		MockPropertyEditorSupport support = new MockPropertyEditorSupport(
+				source);
+		support.addPropertyChangeListener((PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "eventSource",
+						"source"));
+		support.firePropertyChange();
+		assertSame(source, target.getEventSource());
+	}
+
+	public void testAddPropertyChangeListener_source_null() {
+		MockTarget target = new MockTarget();
+		MockPropertyEditorSupport support = new MockPropertyEditorSupport();
+		support
+				.addPropertyChangeListener((PropertyChangeListener) EventHandler
+						.create(PropertyChangeListener.class, target,
+								"eventSource", ""));
+		support.firePropertyChange();
+		PropertyChangeEvent event = (PropertyChangeEvent) target
+				.getEventSource();
+
+		assertNull(event.getPropertyName());
+		assertSame(support, event.getSource());
+	}
+
+	public void testFirePropertyChange_noListener() {
+		MockTarget target = new MockTarget();
+		MockPropertyEditorSupport support = new MockPropertyEditorSupport();
+		support.firePropertyChange();
+	}
+
+	/*
+	 * listener is null
+	 */
+	public void testAddPropertyChangeListener_null() {
+		MockTarget target = new MockTarget();
+		MockPropertyEditorSupport support = new MockPropertyEditorSupport();
+		support.addPropertyChangeListener(null);
+		try {
+			support.firePropertyChange();
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	public void testPaintValue() {
+		MockTarget target = new MockTarget();
+		MockPropertyEditorSupport support = new MockPropertyEditorSupport();
+		support.paintValue(null, null);
+	}
+
+	public void testRemovePropertyChangeListener() {
+		MockTarget target = new MockTarget();
+		MockPropertyEditorSupport support = new MockPropertyEditorSupport();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "eventSource",
+						"source");
+		support.addPropertyChangeListener(proxy);
+		support.firePropertyChange();
+		assertSame(support, target.getEventSource());
+
+		target.setEventSource(null);
+		support.removePropertyChangeListener(proxy);
+		support.firePropertyChange();
+		assertNull(target.getEventSource());
+	}
+
+	public void testRemovePropertyChangeListener_null() {
+		MockTarget target = new MockTarget();
+		MockPropertyEditorSupport support = new MockPropertyEditorSupport();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "eventSource",
+						"source");
+		support.addPropertyChangeListener(proxy);
+		support.firePropertyChange();
+		assertSame(support, target.getEventSource());
+
+		target.setEventSource(null);
+		support.removePropertyChangeListener(null);
+		support.firePropertyChange();
+		assertSame(support, target.getEventSource());
+	}
+
+	/*
+	 * remove a different listener
+	 */
+	public void testRemovePropertyChangeListener_diff() {
+		MockTarget target = new MockTarget();
+		MockPropertyEditorSupport support = new MockPropertyEditorSupport();
+		PropertyChangeListener proxy = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "eventSource",
+						"source");
+		support.addPropertyChangeListener(proxy);
+		support.firePropertyChange();
+		assertSame(support, target.getEventSource());
+
+		target.setEventSource(null);
+		PropertyChangeListener proxy2 = (PropertyChangeListener) EventHandler
+				.create(PropertyChangeListener.class, target, "eventSource",
+						"source");
+		support.removePropertyChangeListener(proxy2);
+		support.firePropertyChange();
+		assertSame(support, target.getEventSource());
+	}
+
+	/*
+	 * remove null listener
+	 */
+	public void testRemovePropertyChangeListener_null_null() {
+		MockTarget target = new MockTarget();
+		MockPropertyEditorSupport support = new MockPropertyEditorSupport();
+		support.addPropertyChangeListener(null);
+		try {
+			support.firePropertyChange();
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// expected
+		}
+
+		support.removePropertyChangeListener(null);
+		support.firePropertyChange();
+	}
+
+	public void testSetAsText() {
+		MockPropertyEditorSupport support = new MockPropertyEditorSupport();
+		String asText = "100";
+		try {
+			support.setAsText(asText);
+			fail("Should throw IllegalArgumentException.");
+		} catch (IllegalArgumentException e) {
+			// expected
+		}
+	}
+
+	public void testSetValue() {
+		MockPropertyEditorSupport support = new MockPropertyEditorSupport();
+		String[] value = new String[] { "This is a sample value." };
+		support.setValue(value);
+
+		assertEquals(value, support.getValue());
+		assertEquals(value.toString(), support.getAsText());
+
+		assertNull(support.getCustomEditor());
+		assertEquals("???", support.getJavaInitializationString());
+		assertNull(support.getTags());
+		assertFalse(support.supportsCustomEditor());
+		assertFalse(support.isPaintable());
+
+	}
+
+	public void testSetValue_null() {
+		MockPropertyEditorSupport support = new MockPropertyEditorSupport();
+		support.setValue(null);
+
+		assertEquals(null, support.getValue());
+		assertEquals("null", support.getAsText());
+
+		assertNull(support.getCustomEditor());
+		assertEquals("???", support.getJavaInitializationString());
+		assertNull(support.getTags());
+		assertFalse(support.supportsCustomEditor());
+		assertFalse(support.isPaintable());
+
+		MockTarget target = new MockTarget();
+		support.setValue(target);
+
+		assertSame(target, support.getValue());
+		assertEquals(target.toString(), support.getAsText());
+		assertNull(support.getCustomEditor());
+		assertEquals("???", support.getJavaInitializationString());
+		assertNull(support.getTags());
+		assertFalse(support.supportsCustomEditor());
+		assertFalse(support.isPaintable());
+	}
+
+	public static class MockPropertyEditorSupport extends PropertyEditorSupport {
+		public MockPropertyEditorSupport() {
+			super();
+		}
+
+		public MockPropertyEditorSupport(Object source) {
+			super(source);
+		}
+	}
+
+	public static class MockSource {
+		String id;
+
+		String text;
+
+		public MockSource() {
+			this.id = "0001";
+			this.text = getClass().getName();
+		}
+
+		/**
+		 * @return Returns the id.
+		 */
+		public String getId() {
+			return id;
+		}
+
+		/**
+		 * @param id
+		 *            The id to set.
+		 */
+		public void setId(String id) {
+			this.id = id;
+		}
+
+		/**
+		 * @return Returns the text.
+		 */
+		public String getText() {
+			return text;
+		}
+
+		/**
+		 * @param text
+		 *            The text to set.
+		 */
+		public void setText(String text) {
+			this.text = text;
+		}
+	}
+
+	public static class MockTarget {
+		String id;
+
+		String label;
+
+		Object eventSource;
+
+		public MockTarget() {
+			this.id = "0001";
+			this.label = getClass().getName();
+		}
+
+		/**
+		 * @return Returns the id.
+		 */
+		public String getId() {
+			return id;
+		}
+
+		/**
+		 * @param id
+		 *            The id to set.
+		 */
+		public void setId(String id) {
+			this.id = id;
+		}
+
+		/**
+		 * @return Returns the text.
+		 */
+		public String getLabel() {
+			return label;
+		}
+
+		/**
+		 * @param text
+		 *            The text to set.
+		 */
+		public void setLabel(String label) {
+			this.label = label;
+		}
+
+		public void setCalled() {
+			this.label = "called";
+		}
+
+		/**
+		 * @return Returns the eventSource.
+		 */
+		public Object getEventSource() {
+			return eventSource;
+		}
+
+		/**
+		 * @param eventSource
+		 *            The eventSource to set.
+		 */
+		public void setEventSource(Object eventSource) {
+			this.eventSource = eventSource;
+		}
+
+		public boolean equals(Object o) {
+			if (!(o instanceof MockTarget)) {
+				return false;
+			}
+
+			MockTarget other = (MockTarget) o;
+			return ((this.id == null ? other.id == null : this.id
+					.equals(other.id))
+					&& (this.eventSource == null ? other.eventSource == null
+							: this.eventSource.equals(other.eventSource)) && (this.label == null ? other.label == null
+					: this.label.equals(other.label)));
+		}
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyEditorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyEditorTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyEditorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyEditorTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,83 @@
+/* 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.awt.Component;
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyEditor;
+
+import tests.api.java.beans.PropertyChangeListenerTest.DummyPropertyChangeListener;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the signature of the interface PropertyEditor.
+ */
+public class PropertyEditorTest extends TestCase {
+
+	public void testSignature() {
+		DummyPropertyEditor o = new DummyPropertyEditor();
+		assertTrue(o instanceof PropertyEditor);
+	}
+
+	static class DummyPropertyEditor implements PropertyEditor {
+
+		public void addPropertyChangeListener(PropertyChangeListener listener) {
+		}
+
+		public String getAsText() {
+			return null;
+		}
+
+		public Component getCustomEditor() {
+			return null;
+		}
+
+		public String getJavaInitializationString() {
+			return null;
+		}
+
+		public String[] getTags() {
+			return null;
+		}
+
+		public Object getValue() {
+			return null;
+		}
+
+		public boolean isPaintable() {
+			return false;
+		}
+
+		public void paintValue(Graphics graphics, Rectangle box) {
+		}
+
+		public void removePropertyChangeListener(PropertyChangeListener listener) {
+		}
+
+		public void setAsText(String text) throws IllegalArgumentException {
+		}
+
+		public void setValue(Object value) {
+		}
+
+		public boolean supportsCustomEditor() {
+			return false;
+		}
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyVetoException.ser
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyVetoException.ser?rev=394923&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyVetoException.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyVetoExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyVetoExceptionTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyVetoExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyVetoExceptionTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,107 @@
+/* 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.PropertyChangeEvent;
+import java.beans.PropertyVetoException;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+import tests.util.SerializationTester;
+
+/**
+ * Unit test for class PropertyVetoException
+ */
+public class PropertyVetoExceptionTest extends TestCase {
+
+	private PropertyChangeEvent event;
+
+	protected void setUp() throws Exception {
+		super.setUp();
+		MockJavaBean myBean = new MockJavaBean("Bean_PropertyVetoExceptionTest");
+		event = new PropertyChangeEvent(myBean, "propertyOne", "value_old",
+				"value_one");
+	}
+
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	public void testPropertyVetoException() {
+		String message = "testPropertyVetoException";
+		PropertyVetoException e = new PropertyVetoException(message, event);
+		assertSame(message, e.getMessage());
+		assertSame(event, e.getPropertyChangeEvent());
+	}
+
+	public void testPropertyVetoException_MessageNull() {
+		String message = null;
+		PropertyVetoException e = new PropertyVetoException(message, event);
+		assertNull(e.getMessage());
+		assertSame(event, e.getPropertyChangeEvent());
+	}
+
+	public void testPropertyVetoException_EventNull() {
+		String message = "testPropertyVetoException";
+		PropertyVetoException e = new PropertyVetoException(message, null);
+		assertSame(message, e.getMessage());
+		assertNull(e.getPropertyChangeEvent());
+	}
+
+	public void testSerializablization() throws IOException,
+			ClassNotFoundException {
+		String message = "testPropertyVetoException";
+		PropertyVetoException e = new PropertyVetoException(message, event);
+		assertSame(message, e.getMessage());
+		assertSame(event, e.getPropertyChangeEvent());
+
+		PropertyVetoException deserializedException = (PropertyVetoException) SerializationTester
+				.getDeserilizedObject(e);
+
+		assertEquals(message, deserializedException.getMessage());
+		assertEquals(event.getNewValue(), deserializedException
+				.getPropertyChangeEvent().getNewValue());
+		assertEquals(event.getOldValue(), deserializedException
+				.getPropertyChangeEvent().getOldValue());
+		assertEquals(event.getPropertyName(), deserializedException
+				.getPropertyChangeEvent().getPropertyName());
+		assertEquals(event.getPropagationId(), deserializedException
+				.getPropertyChangeEvent().getPropagationId());
+		assertNull(deserializedException.getPropertyChangeEvent().getSource());
+	}
+
+	public void testSerializablization_Compatibility() throws Exception {
+		String message = "testPropertyVetoException";
+		PropertyVetoException e = new PropertyVetoException(message, event);
+		assertSame(message, e.getMessage());
+		assertSame(event, e.getPropertyChangeEvent());
+
+		PropertyVetoException deserializedException = (PropertyVetoException) SerializationTester
+				.readObject(e, "tests/api/java/beans/PropertyVetoException.ser");
+
+		assertEquals(message, deserializedException.getMessage());
+		assertEquals(event.getNewValue(), deserializedException
+				.getPropertyChangeEvent().getNewValue());
+		assertEquals(event.getOldValue(), deserializedException
+				.getPropertyChangeEvent().getOldValue());
+		assertEquals(event.getPropertyName(), deserializedException
+				.getPropertyChangeEvent().getPropertyName());
+		assertEquals(event.getPropagationId(), deserializedException
+				.getPropertyChangeEvent().getPropagationId());
+		assertNull(deserializedException.getPropertyChangeEvent().getSource());
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/SampleBean_StringCodec.xml
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/SampleBean_StringCodec.xml?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/SampleBean_StringCodec.xml (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/SampleBean_StringCodec.xml Tue Apr 18 05:11:09 2006
@@ -0,0 +1,30 @@
+<?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.EncoderTest$SampleBean"> 
+  <void property="myid"> 
+   <string>&lt;Li Yang&gt; &amp; &quot;liyang&apos;</string> 
+  </void> 
+  <void property="ref"> 
+   <object class="tests.api.java.beans.EncoderTest$SampleBean"> 
+    <void property="myid"> 
+     <string>a child</string> 
+    </void> 
+   </object> 
+  </void> 
+ </object> 
+</java> 

Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/SimpleBeanInfoTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/SimpleBeanInfoTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/SimpleBeanInfoTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/SimpleBeanInfoTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,76 @@
+/* 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.awt.Image;
+import java.beans.SimpleBeanInfo;
+
+import tests.api.java.beans.mock.MockSimpleBeanInfo;
+import junit.framework.TestCase;
+
+/**
+ * Unit test for SimpleBeanInfo
+ */
+public class SimpleBeanInfoTest extends TestCase {
+
+	public void testGetAdditionalBeanInfo() {
+		SimpleBeanInfo info = new SimpleBeanInfo();
+		assertNull(info.getAdditionalBeanInfo());
+	}
+
+	public void testGetBeanDescriptor() {
+		SimpleBeanInfo info = new SimpleBeanInfo();
+		assertNull(info.getBeanDescriptor());
+	}
+
+	public void testGetDefaultEventIndex() {
+		SimpleBeanInfo info = new SimpleBeanInfo();
+		assertEquals(-1, info.getDefaultEventIndex());
+	}
+
+	public void testGetDefaultPropertyIndex() {
+		SimpleBeanInfo info = new SimpleBeanInfo();
+		assertEquals(-1, info.getDefaultPropertyIndex());
+	}
+
+	public void testGetEventSetDescriptors() {
+		SimpleBeanInfo info = new SimpleBeanInfo();
+		assertNull(info.getEventSetDescriptors());
+	}
+
+	public void testGetIcon() {
+		SimpleBeanInfo info = new SimpleBeanInfo();
+		assertNull(info.getIcon(SimpleBeanInfo.ICON_COLOR_16x16));
+	}
+
+	public void testGetMethodDescriptors() {
+		SimpleBeanInfo info = new SimpleBeanInfo();
+		assertNull(info.getMethodDescriptors());
+	}
+
+	public void testGetPropertyDescriptors() {
+		SimpleBeanInfo info = new SimpleBeanInfo();
+		assertNull(info.getPropertyDescriptors());
+	}
+
+	public void testLoadImage() {
+		// TODO The bahavior is not implemented
+		MockSimpleBeanInfo info = new MockSimpleBeanInfo();
+		Image image = info.loadImage("harmony-logo.gif");
+		// assertTrue(image instanceof Image);
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/StatementTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/StatementTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/StatementTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/StatementTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,866 @@
+/* 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.Statement;
+import java.beans.DefaultPersistenceDelegate;
+import java.util.Arrays;
+import java.util.Vector;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the class java.beans.Statement.
+ */
+public class StatementTest extends TestCase {
+
+	/*
+	 * Test the constructor under normal conditions.
+	 */
+	public void testConstructor_Normal() {
+		Object arg1 = new Object();
+		Object arg2 = "string";
+		Object[] oa = new Object[] { arg1, arg2 };
+		Statement t = new Statement(arg1, "method", oa);
+		assertSame(arg1, t.getTarget());
+		assertSame("method", t.getMethodName());
+		assertSame(oa, t.getArguments());
+		assertSame(arg1, t.getArguments()[0]);
+		assertSame(arg2, t.getArguments()[1]);
+
+		Pattern p = Pattern
+				.compile("Object[0-9]+\\.method\\(Object[0-9]+, \"string\"\\);");
+		Matcher m = p.matcher(t.toString());
+		assertTrue(m.matches());
+	}
+
+	/*
+	 * Test the constructor with null target.
+	 */
+	public void testConstructor_NullTarget() {
+		Object arg = new Object();
+		Object[] oa = new Object[] { arg };
+		Statement t = new Statement(null, "method", oa);
+		assertSame(null, t.getTarget());
+		assertSame("method", t.getMethodName());
+		assertSame(oa, t.getArguments());
+		assertSame(arg, t.getArguments()[0]);
+
+		Pattern p = Pattern.compile("null\\.method\\(Object[0-9]+\\);");
+		Matcher m = p.matcher(t.toString());
+		assertTrue(m.matches());
+	}
+
+	/*
+	 * Test the constructor with an array target.
+	 */
+	public void testConstructor_ArrayTarget() {
+		Object arg = new Object();
+		Object[] oa = new Object[] { arg };
+		Statement t = new Statement(oa, "method", oa);
+		assertSame(oa, t.getTarget());
+		assertSame("method", t.getMethodName());
+		assertSame(oa, t.getArguments());
+		assertSame(arg, t.getArguments()[0]);
+
+		Pattern p = Pattern
+				.compile("ObjectArray[0-9]+\\.method\\(Object[0-9]+\\);");
+		Matcher m = p.matcher(t.toString());
+		assertTrue(m.matches());
+	}
+
+	/*
+	 * Test the constructor with null method name.
+	 */
+	public void testConstructor_NullMethodName() {
+		Object target = new Object();
+		Object[] oa = new Object[] { new Object() };
+		Statement t = new Statement(target, null, oa);
+		assertSame(target, t.getTarget());
+		assertSame(null, t.getMethodName());
+		assertSame(oa, t.getArguments());
+
+		Pattern p = Pattern.compile("Object[0-9]+\\.null\\(Object[0-9]+\\);");
+		Matcher m = p.matcher(t.toString());
+		assertTrue(m.matches());
+	}
+
+	/*
+	 * Test the constructor with the method name "new".
+	 */
+	public void testConstructor_NewMethodName() {
+		Object target = new Object();
+		Object[] oa = new Object[] { new Object() };
+		Statement t = new Statement(target, "new", oa);
+		assertSame(target, t.getTarget());
+		assertSame("new", t.getMethodName());
+		assertSame(oa, t.getArguments());
+
+		Pattern p = Pattern.compile("Object[0-9]+\\.new\\(Object[0-9]+\\);");
+		Matcher m = p.matcher(t.toString());
+		assertTrue(m.matches());
+	}
+
+	/*
+	 * Test the constructor with empty method name.
+	 */
+	public void testConstructor_EmptyMethodName() {
+		Object target = new Object();
+		Object[] oa = new Object[] { new Object() };
+		Statement t = new Statement(target, "", oa);
+		assertSame(target, t.getTarget());
+		assertSame("", t.getMethodName());
+		assertSame(oa, t.getArguments());
+
+		Pattern p = Pattern.compile("Object[0-9]+\\.\\(Object[0-9]+\\);");
+		Matcher m = p.matcher(t.toString());
+		assertTrue(m.matches());
+	}
+
+	/*
+	 * Test the constructor with null arguments.
+	 */
+	public void testConstructor_NullArguments() {
+		Object target = new Object();
+		Statement t = new Statement(target, "method", null);
+		assertSame(target, t.getTarget());
+		assertSame("method", t.getMethodName());
+		assertEquals(0, t.getArguments().length);
+
+		Pattern p = Pattern.compile("Object[0-9]+\\.method\\(\\);");
+		Matcher m = p.matcher(t.toString());
+		assertTrue(m.matches());
+	}
+
+	/*
+	 * Test the constructor with a null argument.
+	 */
+	public void testConstructor_NullArgument() {
+		Object target = new Object();
+		Object[] oa = new Object[] { null };
+		Statement t = new Statement(target, "method", oa);
+		assertSame(target, t.getTarget());
+		assertSame("method", t.getMethodName());
+		assertSame(oa, t.getArguments());
+		assertNull(t.getArguments()[0]);
+
+		Pattern p = Pattern.compile("Object[0-9]+\\.method\\(null\\);");
+		Matcher m = p.matcher(t.toString());
+		assertTrue(m.matches());
+	}
+
+	public void testGetArguments() {
+		// Covered in the testcases for the constructor
+	}
+
+	public void testGetMethodName() {
+		// Covered in the testcases for the constructor
+	}
+
+	public void testGetTarget() {
+		// Covered in the testcases for the constructor
+	}
+
+	public void testToString() {
+		// Covered in the testcases for the constructor
+	}
+
+	/*
+	 * Test the method execute() with a normal object, a valid method name and
+	 * valid arguments.
+	 */
+	public void testExecute_NormalInstanceMethod() throws Exception {
+		MockObject mo = new MockObject(false);
+		Statement t = new Statement(mo, "method", new Object[0]);
+		t.execute();
+		MockObject.assertCalled("method1", new Object[0]);
+		t = new Statement(mo, "method", null);
+		t.execute();
+		MockObject.assertCalled("method1", new Object[0]);
+	}
+
+	/*
+	 * Test the method execute() with a normal object, a valid method that
+	 * throws an exception and valid arguments.
+	 */
+	public void testExecute_ExceptionalMethod() throws Exception {
+		MockObject mo = new MockObject(false);
+		Statement t = new Statement(mo, "method", new Object[] { null, null });
+		try {
+			t.execute();
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException ex) {
+			// expected
+		}
+		MockObject.assertCalled("method4", new Object[] { null, null });
+	}
+
+	/*
+	 * Test the method execute() with a normal object and a non-existing method
+	 * name.
+	 */
+	public void testExecute_NonExistingMethod() throws Exception {
+		MockObject mo = new MockObject(false);
+		Statement t = new Statement(mo, "method_not_existing", new Object[] {
+				null, null });
+		try {
+			t.execute();
+			fail("Should throw NoSuchMethodException!");
+		} catch (NoSuchMethodException ex) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method execute() with a null object.
+	 */
+	public void testExecute_NullTarget() throws Exception {
+		Statement t = new Statement(null, "method_not_existing", new Object[] {
+				null, null });
+		try {
+			t.execute();
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException ex) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method execute() with a null method name.
+	 */
+	public void testExecute_NullMethodName() throws Exception {
+		MockObject mo = new MockObject(false);
+		Statement t = new Statement(mo, null, new Object[] { null, null });
+		try {
+			t.execute();
+			fail("Should throw NoSuchMethodException!");
+		} catch (NoSuchMethodException ex) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method execute() with a normal object, a valid method and
+	 * invalid arguments (in terms of type, numbers, etc.).
+	 */
+	public void testExecute_InvalidArguments() throws Exception {
+		MockObject mo = new MockObject(false);
+		Statement t = new Statement(mo, "method", new Object[] { new Object(),
+				new Object(), new Object() });
+		try {
+			t.execute();
+			fail("Should throw NoSuchMethodException!");
+		} catch (NoSuchMethodException ex) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method execute() with a normal object, an overloaded method and
+	 * valid arguments. 
+	 */
+	public void testExecute_OverloadedMethods() throws Exception {
+		MockObject mo = new MockObject(false);
+		Object[] arguments = new Object[] { new Object() };
+		Statement t = new Statement(mo, "method", arguments);
+		t.execute();
+		MockObject.assertCalled("method2", arguments);
+
+		arguments = new Object[] { "test" };
+		t = new Statement(mo, "method", arguments);
+		t.execute();
+		MockObject.assertCalled("method3", arguments);
+	}
+
+	/*
+	 * Test the method execute() with a normal object, an overloaded method and
+	 * null arguments. See Java Language Specification (15.11) for reference.
+	 */
+	public void testExecute_OverloadedMethodsNull() throws Exception {
+		MockObject mo = new MockObject(false);
+		Object[] arguments = new Object[] { null };
+		Statement t = new Statement(mo, "method", arguments);
+		t.execute();
+		MockObject.assertCalled("method1-2", arguments);
+	}
+
+	/*
+	 * Test the method execute() with a normal object, the method name "new" and
+	 * valid arguments.
+	 */
+	public void testExecute_NormalConstructor() throws Exception {
+		Statement t = new Statement(MockObject.class, "new", new Object[0]);
+		t.execute();
+		MockObject.assertCalled("new0", new Object[0]);
+		t = new Statement(MockObject.class, "new", null);
+		t.execute();
+		MockObject.assertCalled("new0", new Object[0]);
+	}
+
+	/*
+	 * Test the method execute() with a normal object, the method name "new"
+	 * that throws an exception and valid arguments.
+	 */
+	public void testExecute_ExceptionalConstructor() throws Exception {
+		Statement t = new Statement(MockObject.class, "new", new Object[] {
+				null, null });
+		try {
+			t.execute();
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException ex) {
+			// expected
+		}
+		MockObject.assertCalled("new4", new Object[] { null, null });
+	}
+
+	/*
+	 * Test the method execute() with a normal object, the method name "new" and
+	 * invalid arguments (in terms of type, numbers, etc.).
+	 */
+	public void testExecute_NonExistingConstructor() throws Exception {
+		Statement t = new Statement(MockObject.class, "new", new Object[] {
+				null, null, null });
+		try {
+			t.execute();
+			fail("Should throw NoSuchMethodException!");
+		} catch (NoSuchMethodException ex) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method execute() with a normal object with overloaded
+	 * constructors, the method name "new" and valid arguments. 
+	 */
+	public void testExecute_OverloadedConstructors() throws Exception {
+		Object[] arguments = new Object[] { new Object() };
+		Statement t = new Statement(MockObject.class, "new", arguments);
+		t.execute();
+		MockObject.assertCalled("new2", arguments);
+
+		arguments = new Object[] { "test" };
+		t = new Statement(MockObject.class, "new", arguments);
+		t.execute();
+		// MockObject.assertCalled("new2", arguments);
+
+		arguments = new Object[] { new Integer(1) };
+		t = new Statement(MockObject.class, "new", arguments);
+		t.execute();
+		MockObject.assertCalled("new1-2", arguments);
+	}
+
+	/*
+	 * Test the method execute() with a normal object with overloaded
+	 * constructors, the method name "new" and null arguments.
+	 */
+	public void testExecute_OverloadedConstructorsNull() throws Exception {
+		Object[] arguments = new Object[] { null };
+		Statement t = new Statement(MockObject.class, "new", arguments);
+		try {
+			t.execute();
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException ex) {
+			// expected
+		}
+		// MockObject.assertCalled("new2", arguments);
+	}
+
+	/*
+	 * Test the method execute() with the Class object, a static method name and
+	 * valid arguments.
+	 */
+	public void testExecute_NormalStaticMethodViaClass() throws Exception {
+		Object[] arguments = new Object[] { new Object() };
+		Statement t = new Statement(MockObject.class, "staticMethod", arguments);
+		t.execute();
+		MockObject.assertCalled("staticMethod", arguments);
+	}
+
+	/*
+	 * Test the method execute() with an object, a static method name and valid
+	 * arguments.
+	 */
+	public void testExecute_NormalStaticMethodViaObject() throws Exception {
+		MockObject mo = new MockObject(false);
+		Object[] arguments = new Object[] { new Object() };
+		Statement t = new Statement(mo, "staticMethod", arguments);
+		t.execute();
+		MockObject.assertCalled("staticMethod", arguments);
+	}
+
+	/*
+	 * Test the method execute() with a Class object of a normal class that has
+	 * a method of the same signature as Class.forName(String), a static method
+	 * name "forName" and valid argument "string".
+	 */
+	public void testExecute_AmbitiousStaticMethod() throws Exception {
+		Object[] arguments = new String[] { "test" };
+		Statement t = new Statement(MockObject.class, "forName", arguments);
+		t.execute();
+		MockObject.assertCalled("forName", arguments);
+
+		t = new Statement(String.class, "forName",
+				new Object[] { "java.lang.String" });
+		t.execute();
+	}
+
+	/*
+	 * Test the method execute() with the special method Class.forName().
+	 */
+	public void testExecute_ClassForName() throws Exception {
+		Object[] arguments = new String[] { this.getClass().getName() };
+		Statement t = new Statement(Class.class, "forName", arguments);
+		t.execute();
+
+		t = new Statement(String.class, "forName",
+				new Object[] { "java.lang.String" });
+		t.execute();
+	}
+
+	/*
+	 * Test the method execute() with a normal array object, the method name
+	 * "get" and valid and invalid arguments.
+	 */
+	public void testExecute_ArrayGet() throws Exception {
+		Object[] array = new Object[] { "test" };
+		Statement t = new Statement(array, "get", new Object[] {
+				new Integer(0), new Object() });
+		t.execute();
+
+		array = new Object[] { "test" };
+		t = new Statement(array, "get", new Object[0]);
+		try {
+			t.execute();
+			fail("Should throw ArrayIndexOutOfBoundsException!");
+		} catch (ArrayIndexOutOfBoundsException ex) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method execute() with a normal array object, the method name
+	 * "set" and valid arguments.
+	 */
+	public void testExecute_ArraySet() throws Exception {
+		Object[] array = new Object[] { "test" };
+		Statement t = new Statement(array, "set", new Object[] {
+				new Integer(0), "test2" });
+		t.execute();
+		assertEquals("test2", array[0]);
+	}
+
+	/*
+	 * Test the method execute() with a normal array object, the method name
+	 * "set" and null index argument.
+	 */
+	public void testExecute_ArrayNullIndex() throws Exception {
+		Object[] array = new Object[] { "test" };
+		Statement t = new Statement(array, "set",
+				new Object[] { null, "test2" });
+		try {
+			t.execute();
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException ex) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method execute() with a normal array object, the method name
+	 * "set" and invalid arguments.
+	 */
+	public void testExecute_ArrayInvalidSet() throws Exception {
+		Object[] array = new Object[] { "test" };
+		Statement t = new Statement(array, "set", new Object[] {
+				new Integer(0), "test2", new Object() });
+		t.execute();
+		assertEquals("test2", array[0]);
+
+		try {
+			t = new Statement(array, "set", new Object[] { "testtest", "test2",
+					new Object() });
+			t.execute();
+			fail("Should throw ClassCastException!");
+		} catch (ClassCastException ex) {
+			// expected
+		}
+
+		t = new Statement(array, "set", new Object[] { new Integer(0) });
+		try {
+			t.execute();
+			fail("Should throw ArrayIndexOutOfBoundsException!");
+		} catch (ArrayIndexOutOfBoundsException ex) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method execute() with a normal array object, the method name
+	 * "getInt" and invalid arguments.
+	 */
+	public void testExecute_ArrayInvalidSetInt() throws Exception {
+		int[] array = new int[] { 1 };
+		Statement t = new Statement(array, "getInt",
+				new Object[] { new Integer(0) });
+		try {
+			t.execute();
+			fail("Should throw NoSuchMethodException!");
+		} catch (NoSuchMethodException ex) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method execute() with a normal array object, the method name
+	 * "gets".
+	 */
+	public void testExecute_ArrayInvalidName() throws Exception {
+		Object[] array = new Object[] { "test" };
+		Statement t = new Statement(array, "gets", new Object[] {
+				new Integer(0), new Object() });
+		try {
+			t.execute();
+			fail("Should throw NoSuchMethodException!");
+		} catch (NoSuchMethodException ex) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method execute() with a normal object with overloaded methods
+	 * (primitive type VS wrapper class), a valid method name and valid
+	 * arguments.
+	 * 
+	 * Note: decided by definition position!
+	 */
+	public void testExecute_PrimitiveVSWrapper() throws Exception {
+		MockObject mo = new MockObject(false);
+		Object[] arguments = new Object[] { new Integer(1) };
+		Statement t = new Statement(mo, "methodB", arguments);
+		t.execute();
+		MockObject.assertCalled("methodB1", arguments);
+
+		arguments = new Object[] { Boolean.FALSE };
+		t = new Statement(mo, "methodB", arguments);
+		t.execute();
+		MockObject.assertCalled("methodB4", arguments);
+	}
+
+	/*
+	 * Test the method execute() with a protected method but within java.beans
+	 * package.
+	 */
+	public void testExecute_ProtectedMethodWithPackage() throws Exception {
+		DefaultPersistenceDelegate dpd = new DefaultPersistenceDelegate();
+		Object[] arguments = new Object[] { "test", "test" };
+		Statement t = new Statement(dpd, "mutatesTo", arguments);
+		try {
+			t.execute();
+			fail("Should throw NoSuchMethodException!");
+		} catch (NoSuchMethodException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method execute() with a method that is applicable via type
+	 * conversion.
+	 */
+	public void testExecute_ApplicableViaTypeConversion() throws Exception {
+		MockObject mo = new MockObject(false);
+		// mo.methodB('c');
+		Object[] arguments = new Object[] { new Character((char) 1) };
+		Statement t = new Statement(mo, "methodB", arguments);
+		try {
+			t.execute();
+			fail("Should throw NoSuchMethodException!");
+		} catch (NoSuchMethodException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method execute() with two equal specific methods.
+	 * 
+	 * Note: decided by definition position!
+	 */
+	public void testExecute_EqualSpecificMethods() throws Exception {
+		MockObject mo = new MockObject(false);
+		Object[] arguments = new Object[] { new MockObject(false),
+				new MockObject(false) };
+		Statement t = new Statement(mo, "equalSpecificMethod", arguments);
+		t.execute();
+		MockObject.assertCalled("equalSpecificMethod1", arguments);
+	}
+
+	/*
+	 * Test the method execute() with two equal specific methods but one
+	 * declaring thrown exception.
+	 * 
+	 * Note: decided by definition position!
+	 */
+	public void testExecute_EqualSpecificMethodsException() throws Exception {
+		MockObject mo = new MockObject(false);
+		Object[] arguments = new Object[] { new MockObject(false),
+				new MockObject(false), new Object() };
+		Statement t = new Statement(mo, "equalSpecificMethod", arguments);
+		t.execute();
+		MockObject.assertCalled("equalSpecificMethod4", arguments);
+	}
+
+	/*
+	 * Test the method execute() with int method while providing a null
+	 * parameter.
+	 */
+	public void testExecute_IntMethodNullParameter() throws Exception {
+		MockObject mo = new MockObject(false);
+		Object[] arguments = new Object[] { null };
+		Statement t = new Statement(mo, "intMethod", arguments);
+		try {
+			t.execute();
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException ex) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method execute() with int array method while providing an
+	 * Integer array parameter.
+	 */
+	public void testExecute_IntArrayMethod() throws Exception {
+		MockObject mo = new MockObject(false);
+		Object[] arguments = new Object[] { new Integer[] { new Integer(1) } };
+		Statement t = new Statement(mo, "intArrayMethod", arguments);
+		try {
+			t.execute();
+			fail("Should throw NoSuchMethodException!");
+		} catch (NoSuchMethodException ex) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method execute() with Integer array method while providing an
+	 * int array parameter.
+	 */
+	public void testExecute_IntegerArrayMethod() throws Exception {
+		MockObject mo = new MockObject(false);
+		Object[] arguments = new Object[] { new int[] { 1 } };
+		Statement t = new Statement(mo, "integerArrayMethod", arguments);
+		try {
+			t.execute();
+			fail("Should throw NoSuchMethodException!");
+		} catch (NoSuchMethodException ex) {
+			// expected
+		}
+	}
+
+	/*
+	 * Super class of MockObject.
+	 */
+	public static class MockParent {
+
+		protected static String calledMethod = null;
+
+		protected static Vector receivedArguments = new Vector();
+
+		public void method() {
+			reset();
+			calledMethod = "method1";
+		}
+
+		protected void method(Boolean o) {
+			reset();
+			calledMethod = "method1-1";
+			receivedArguments.add(o);
+		}
+
+		public void method(Integer o) {
+			reset();
+			calledMethod = "method1-2";
+			receivedArguments.add(o);
+		}
+
+		public void method(Object o) {
+			reset();
+			calledMethod = "method2";
+			receivedArguments.add(o);
+		}
+
+		public void method(String o) {
+			reset();
+			calledMethod = "method3";
+			receivedArguments.add(o);
+		}
+
+		public void method(Object o, Object o2) {
+			reset();
+			calledMethod = "method4";
+			receivedArguments.add(o);
+			receivedArguments.add(o2);
+			throw new NullPointerException();
+		}
+
+		public static void reset() {
+			receivedArguments.clear();
+			calledMethod = null;
+		}
+	}
+
+	/*
+	 * Mock object.
+	 */
+	public static class MockObject extends MockParent {
+
+		public MockObject() {
+			reset();
+			calledMethod = "new0";
+		}
+
+		public MockObject(boolean testingConstructor) {
+			reset();
+			if (testingConstructor) {
+				calledMethod = "new1";
+			}
+		}
+
+		public MockObject(Integer o) {
+			reset();
+			calledMethod = "new1-2";
+			receivedArguments.add(o);
+		}
+
+		public MockObject(Object o) {
+			reset();
+			calledMethod = "new2";
+			receivedArguments.add(o);
+		}
+
+		public MockObject(String o) {
+			reset();
+			calledMethod = "new3";
+			receivedArguments.add(o);
+		}
+
+		public MockObject(Object o, Object o2) {
+			reset();
+			calledMethod = "new4";
+			receivedArguments.add(o);
+			receivedArguments.add(o2);
+			throw new NullPointerException();
+		}
+
+		public void intMethod(int i) {
+			reset();
+			calledMethod = "intMethod";
+			receivedArguments.add(new Integer(i));
+		}
+
+		public void intArrayMethod(int[] ia) {
+			reset();
+			calledMethod = "intArrayMethod";
+			receivedArguments.add(ia);
+		}
+
+		public void integerArrayMethod(Integer[] ia) {
+			reset();
+			calledMethod = "integerArrayMethod";
+			receivedArguments.add(ia);
+		}
+
+		public void methodB(Integer i) {
+			reset();
+			calledMethod = "methodB1";
+			receivedArguments.add(i);
+		}
+
+		public void methodB(int i) {
+			reset();
+			calledMethod = "methodB2";
+			receivedArguments.add(new Integer(i));
+		}
+
+		public void methodB(boolean b) {
+			reset();
+			calledMethod = "methodB3";
+			receivedArguments.add(new Boolean(b));
+		}
+
+		public void methodB(Boolean b) {
+			reset();
+			calledMethod = "methodB4";
+			receivedArguments.add(b);
+		}
+
+		public static void staticMethod(Object o) {
+			reset();
+			calledMethod = "staticMethod";
+			receivedArguments.add(o);
+		}
+
+		public void equalSpecificMethod(MockObject o, MockParent p) {
+			reset();
+			calledMethod = "equalSpecificMethod1";
+			receivedArguments.add(o);
+			receivedArguments.add(p);
+		}
+
+		public void equalSpecificMethod(MockParent p, MockObject o) {
+			reset();
+			calledMethod = "equalSpecificMethod2";
+			receivedArguments.add(p);
+			receivedArguments.add(o);
+		}
+
+		public void equalSpecificMethod(MockParent p, MockObject o, Object o2)
+				throws Exception {
+			reset();
+			calledMethod = "equalSpecificMethod4";
+			receivedArguments.add(p);
+			receivedArguments.add(o);
+			receivedArguments.add(o2);
+		}
+
+		public void equalSpecificMethod(MockObject o, MockParent p, Object o2) {
+			reset();
+			calledMethod = "equalSpecificMethod3";
+			receivedArguments.add(o);
+			receivedArguments.add(p);
+			receivedArguments.add(o2);
+		}
+
+		public static Class forName(String o) {
+			reset();
+			calledMethod = "forName";
+			receivedArguments.add(o);
+			return null;
+		}
+
+		public static void assertCalled(String methodName, Object[] arguments) {
+			assertEquals(methodName, calledMethod);
+			assertTrue(Arrays.equals(arguments, receivedArguments.toArray()));
+			reset();
+		}
+
+		public static void assertNotCalled() {
+			assertEquals(null, calledMethod);
+			assertTrue(receivedArguments.isEmpty());
+		}
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeListenerProxyTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeListenerProxyTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeListenerProxyTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeListenerProxyTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,106 @@
+/* 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.PropertyChangeEvent;
+import java.beans.PropertyChangeListenerProxy;
+import java.beans.PropertyVetoException;
+import java.beans.VetoableChangeListener;
+import java.beans.VetoableChangeListenerProxy;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit test for VetoableChangeListenerProxy
+ */
+public class VetoableChangeListenerProxyTest extends TestCase {
+	VetoableChangeListenerProxy proxy;
+
+	VetoableChangeListener listener = new MockVetoableChangeListener();
+
+	String name = "mock";
+
+	private static PropertyChangeEvent event = null;
+
+	/*
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+		proxy = new VetoableChangeListenerProxy(name, listener);
+	}
+
+	/*
+	 * @see TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	public void testVetoableChangeListenerProxy() throws PropertyVetoException {
+		proxy = new VetoableChangeListenerProxy(null, listener);
+		assertSame(listener, proxy.getListener());
+		assertNull(proxy.getPropertyName());
+		PropertyChangeEvent newevent = new PropertyChangeEvent(new Object(),
+				"name", new Object(), new Object());
+		proxy.vetoableChange(newevent);
+		assertSame(newevent, event);
+		proxy = new VetoableChangeListenerProxy(name, null);
+		assertSame(name, proxy.getPropertyName());
+		assertNull(proxy.getListener());
+		try {
+			proxy.vetoableChange(new PropertyChangeEvent(new Object(), "name",
+					new Object(), new Object()));
+			fail("should null pointer");
+		} catch (NullPointerException e) {
+		}
+
+		proxy = new VetoableChangeListenerProxy(name, listener);
+		assertSame(listener, proxy.getListener());
+		assertSame(name, proxy.getPropertyName());
+		newevent = new PropertyChangeEvent(new Object(), "name", new Object(),
+				new Object());
+		assertSame(name, proxy.getPropertyName());
+		proxy.vetoableChange(newevent);
+		assertSame(newevent, event);
+	}
+
+	public void testVetoableChange() throws PropertyVetoException {
+		PropertyChangeEvent newevent = new PropertyChangeEvent(new Object(),
+				"exception", new Object(), new Object());
+		try {
+			proxy.vetoableChange(newevent);
+			fail("should throw exception");
+		} catch (PropertyVetoException e) {
+		}
+		proxy.vetoableChange(null);
+		assertNull(event);
+	}
+
+	public static class MockVetoableChangeListener implements
+			VetoableChangeListener {
+
+		public void vetoableChange(PropertyChangeEvent newevent)
+				throws PropertyVetoException {
+			event = newevent;
+			if (event != null && event.getPropertyName().equals("exception")) {
+				throw new PropertyVetoException("", newevent);
+			}
+		}
+
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeListenerTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeListenerTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeListenerTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeListenerTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,44 @@
+/* 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.PropertyChangeEvent;
+import java.beans.PropertyEditor;
+import java.beans.PropertyVetoException;
+import java.beans.VetoableChangeListener;
+
+import tests.api.java.beans.PropertyEditorTest.DummyPropertyEditor;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the signature of the interface VetoableChangeListener.
+ */
+public class VetoableChangeListenerTest extends TestCase {
+
+	public void testSignature() {
+		DummyVetoableChangeListener o = new DummyVetoableChangeListener();
+		assertTrue(o instanceof VetoableChangeListener);
+	}
+
+	static class DummyVetoableChangeListener implements VetoableChangeListener {
+
+		public void vetoableChange(PropertyChangeEvent event)
+				throws PropertyVetoException {
+		}
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeSupport.ser
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeSupport.ser?rev=394923&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/VetoableChangeSupport.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message