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 [7/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/MockJavaBean.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/MockJavaBean.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/MockJavaBean.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/MockJavaBean.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,229 @@
+/* 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.io.Serializable;
+
+public class MockJavaBean implements Serializable {
+ /**
+ * Comment for <code>serialVersionUID</code>
+ */
+ private static final long serialVersionUID = 1L;
+
+ private String beanName;
+
+ private String propertyOne;
+
+ private Integer propertyTwo;
+
+ private String propertyThree;
+
+ private String[] propertyFour;
+
+ private String[] propertyFive;
+
+ private Integer[] propertySix;
+
+ private String protectedProp;
+
+ public MockJavaBean() {
+ this.beanName = getClass().getName();
+ }
+
+ public MockJavaBean(String beanName) {
+ this.beanName = beanName;
+ }
+
+ /**
+ * @return Returns the beanName.
+ */
+ public String getBeanName() {
+ return beanName;
+ }
+
+ /**
+ * @param beanName
+ * The beanName to set.
+ */
+ public void setBeanName(String beanName) {
+ this.beanName = beanName;
+ }
+
+ /**
+ * @return Returns the propertyOne.
+ */
+ public String getPropertyOne() {
+ return propertyOne;
+ }
+
+ /**
+ * @param propertyOne
+ * The propertyOne to set.
+ */
+ public void setPropertyOne(String propertyOne) {
+ this.propertyOne = propertyOne;
+ }
+
+ /**
+ * @return Returns the propertyTwo.
+ */
+ public Integer getPropertyTwo() {
+ return propertyTwo;
+ }
+
+ /**
+ * @param propertyTwo
+ * The propertyTwo to set.
+ */
+ public void setPropertyTwo(Integer propertyTwo) {
+ this.propertyTwo = propertyTwo;
+ }
+
+ public String invalidGetMethod(String arg) {
+ // for PropertyDescriptorTest: with args
+ return arg;
+ }
+
+ public void invalidGetMethod() {
+ // for PropertyDescriptorTest
+ // return void
+ }
+
+ /**
+ * @return Returns the propertyThree.
+ */
+ public String getPropertyThree() {
+ return propertyThree;
+ }
+
+ /**
+ * @param propertyThree
+ * The propertyThree to set.
+ */
+ public void setPropertyThree(String propertyThree) {
+ this.propertyThree = propertyThree;
+ }
+
+ /**
+ * @return Returns the propertyFour.
+ */
+ public String[] getPropertyFour() {
+ return propertyFour;
+ }
+
+ /**
+ * @param propertyFour
+ * The propertyFour to set.
+ */
+ public void setPropertyFour(String[] propertyFour) {
+ this.propertyFour = propertyFour;
+ }
+
+ public String getPropertyFour(int i) {
+ return getPropertyFour()[i];
+ }
+
+ public void getPropertyFourInvalid(int i) {
+
+ }
+
+ public void setPropertyFour(int i, String value) {
+ propertyFour[i] = value;
+ }
+
+ public void setPropertyFour(int i, int value) {
+ propertyFour[i] = "";
+ }
+
+ public int setPropertyFourInvalid(int i, String value) {
+ return i;
+ }
+
+ public void setPropertyFourInvalid2(String i, String value) {
+ // return i;
+ }
+
+ /**
+ * @return Returns the propertyFive.
+ */
+ public String[] getPropertyFive() {
+ return propertyFive;
+ }
+
+ /**
+ * @param propertyFive
+ * The propertyFive to set.
+ */
+ public void setPropertyFive(String[] propertyFive) {
+ this.propertyFive = propertyFive;
+ }
+
+ public String getPropertyFive(int i) {
+ return getPropertyFive()[i];
+ }
+
+ public void setPropertyFive(int i, String value) {
+ propertyFive[i] = value;
+ }
+
+ /**
+ * @return Returns the protectedProp.
+ */
+ protected String getProtectedProp() {
+ return protectedProp;
+ }
+
+ /**
+ * @param protectedProp
+ * The protectedProp to set.
+ */
+ protected void setProtectedProp(String protectedProp) {
+ this.protectedProp = protectedProp;
+ }
+
+ /**
+ * @return Returns the propertySix.
+ */
+ public Integer[] getPropertySix() {
+ return propertySix;
+ }
+
+ public Integer getPropertySix(int i) {
+ return null;
+ }
+
+ /**
+ * @param propertySix
+ * The propertySix to set.
+ */
+ public void setPropertySix(Integer[] propertySix) {
+ this.propertySix = propertySix;
+ }
+
+ public void setPropertySix(int i, Integer value) {
+
+ }
+
+ public void addMockPropertyChangeListener(
+ MockPropertyChangeListener listener) {
+
+ }
+
+ public void removeMockPropertyChangeListener(
+ MockPropertyChangeListener listener) {
+
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/MockPropertyChangeEvent.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/MockPropertyChangeEvent.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/MockPropertyChangeEvent.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/MockPropertyChangeEvent.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,37 @@
+/* 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.util.EventObject;
+
+/**
+ * This is a mock class for EventSetDescriptor testing
+ */
+public class MockPropertyChangeEvent extends EventObject {
+
+ /**
+ * Comment for <code>serialVersionUID</code>
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * @param source
+ */
+ public MockPropertyChangeEvent(Object source) {
+ super(source);
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/MockPropertyChangeListener.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/MockPropertyChangeListener.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/MockPropertyChangeListener.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/MockPropertyChangeListener.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,36 @@
+/* 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;
+
+/**
+ * TODO Type description
+ */
+public interface MockPropertyChangeListener {
+ /*
+ * fire MockPropertyChange event.
+ */
+
+ public void mockPropertyChange(MockPropertyChangeEvent e);
+
+ public void mockPropertyChange2(MockPropertyChangeEvent e);
+
+ public void mockPropertyChange3(MockPropertyChangeEvent e);
+
+ public void mockNotAEventObject(MockFakeEvent event);
+
+ public void mockPropertyChange_Invalid();
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/ParameterDescriptorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/ParameterDescriptorTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/ParameterDescriptorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/ParameterDescriptorTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,40 @@
+/* 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.ParameterDescriptor;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit test for ParameterDescriptor.
+ */
+public class ParameterDescriptorTest extends TestCase {
+
+ public void testParameterDescriptor() {
+ ParameterDescriptor pd = new ParameterDescriptor();
+ assertNull(pd.getDisplayName());
+ assertNull(pd.getName());
+ assertNull(pd.getShortDescription());
+
+ assertNotNull(pd.attributeNames());
+
+ assertFalse(pd.isExpert());
+ assertFalse(pd.isHidden());
+ assertFalse(pd.isPreferred());
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PersistenceDelegateTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PersistenceDelegateTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PersistenceDelegateTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PersistenceDelegateTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,452 @@
+/* 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.Encoder;
+import java.beans.ExceptionListener;
+import java.beans.Expression;
+import java.beans.PersistenceDelegate;
+import java.beans.Statement;
+
+import junit.framework.TestCase;
+import tests.api.java.beans.mock.MockFoo;
+import tests.api.java.beans.mock.MockFooStop;
+import tests.util.CallVerificationStack;
+
+/**
+ * Test java.beans.PersistenceDelegate
+ */
+public class PersistenceDelegateTest extends TestCase {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ CallVerificationStack.getInstance().clear();
+ }
+
+ /*
+ * Test the constructor.
+ */
+ public void testConstructor() {
+ new DummyPersistenceDelegate();
+ }
+
+ /*
+ * Tests writeObject() under normal condition when mutatesTo() returns True.
+ */
+ public void testWriteObject_NormalMutatesToTrue() {
+ MockPersistenceDelegate pd = new MockPersistenceDelegate(true, true);
+ MockEncoder enc = new MockEncoder();
+ MockFoo oldInstance = new MockFoo();
+ enc.setPersistenceDelegate(MockFooStop.class, pd);
+
+ pd.writeObject(oldInstance, enc);
+
+ // should have called initialize()
+ assertSame(enc, CallVerificationStack.getInstance().pop());
+ assertSame(null, CallVerificationStack.getInstance().pop());
+ assertSame(oldInstance, CallVerificationStack.getInstance().pop());
+ assertEquals(
+ "tests.api.java.beans.PersistenceDelegateTest$MockPersistenceDelegate",
+ CallVerificationStack.getInstance().getCurrentSourceClass());
+ assertEquals("initialize", CallVerificationStack.getInstance()
+ .getCurrentSourceMethod());
+ assertSame(MockFoo.class, CallVerificationStack.getInstance().pop());
+
+ // should have called mutatesTo()
+ assertSame(null, CallVerificationStack.getInstance().pop());
+ assertEquals(
+ "tests.api.java.beans.PersistenceDelegateTest$MockPersistenceDelegate",
+ CallVerificationStack.getInstance().getCurrentSourceClass());
+ assertEquals("mutatesTo", CallVerificationStack.getInstance()
+ .getCurrentSourceMethod());
+ assertSame(oldInstance, CallVerificationStack.getInstance().pop());
+
+ // should have called Encoder.get()
+ assertEquals(
+ "tests.api.java.beans.PersistenceDelegateTest$MockEncoder",
+ CallVerificationStack.getInstance().getCurrentSourceClass());
+ assertEquals("get", CallVerificationStack.getInstance()
+ .getCurrentSourceMethod());
+ assertSame(oldInstance, CallVerificationStack.getInstance().pop());
+
+ assertTrue(CallVerificationStack.getInstance().empty());
+ }
+
+ /*
+ * Tests writeObject() under normal condition when mutatesTo() returns
+ * false.
+ */
+ public void testWriteObject_NormalMutatesToFalse() {
+ MockPersistenceDelegate pd = new MockPersistenceDelegate(false, true);
+ MockEncoder enc = new MockEncoder();
+ MockFoo oldInstance = new MockFoo();
+ enc.setPersistenceDelegate(MockFooStop.class, pd);
+
+ pd.writeObject(oldInstance, enc);
+
+ // should have called writeExpression()
+ assertEquals(
+ "tests.api.java.beans.PersistenceDelegateTest$MockEncoder",
+ CallVerificationStack.getInstance().getCurrentSourceClass());
+ assertEquals("writeExpression", CallVerificationStack.getInstance()
+ .getCurrentSourceMethod());
+ assertTrue(CallVerificationStack.getInstance().pop() instanceof Expression);
+
+ // should have called instantiate()
+ assertSame(enc, CallVerificationStack.getInstance().pop());
+ assertEquals(
+ "tests.api.java.beans.PersistenceDelegateTest$MockPersistenceDelegate",
+ CallVerificationStack.getInstance().getCurrentSourceClass());
+ assertEquals("instantiate", CallVerificationStack.getInstance()
+ .getCurrentSourceMethod());
+ assertSame(oldInstance, CallVerificationStack.getInstance().pop());
+
+ // should have called Encoder.remove()
+ assertEquals(
+ "tests.api.java.beans.PersistenceDelegateTest$MockEncoder",
+ CallVerificationStack.getInstance().getCurrentSourceClass());
+ assertEquals("remove", CallVerificationStack.getInstance()
+ .getCurrentSourceMethod());
+ assertSame(oldInstance, CallVerificationStack.getInstance().pop());
+
+ // should have called mutatesTo()
+ assertSame(null, CallVerificationStack.getInstance().pop());
+ assertEquals(
+ "tests.api.java.beans.PersistenceDelegateTest$MockPersistenceDelegate",
+ CallVerificationStack.getInstance().getCurrentSourceClass());
+ assertEquals("mutatesTo", CallVerificationStack.getInstance()
+ .getCurrentSourceMethod());
+ assertSame(oldInstance, CallVerificationStack.getInstance().pop());
+
+ // should have called Encoder.get()
+ assertEquals(
+ "tests.api.java.beans.PersistenceDelegateTest$MockEncoder",
+ CallVerificationStack.getInstance().getCurrentSourceClass());
+ assertEquals("get", CallVerificationStack.getInstance()
+ .getCurrentSourceMethod());
+ assertSame(oldInstance, CallVerificationStack.getInstance().pop());
+
+ assertTrue(CallVerificationStack.getInstance().empty());
+ }
+
+ /*
+ * Tests writeObject() when object is null.
+ */
+ public void testWriteObject_NullObject() {
+ MockPersistenceDelegate pd = new MockPersistenceDelegate();
+ MockEncoder enc = new MockEncoder();
+ enc.setPersistenceDelegate(MockFooStop.class, pd);
+
+ try {
+ pd.writeObject(null, enc);
+ fail("Should throw NullPointerException!");
+ } catch (NullPointerException ex) {
+ // expected
+ }
+ }
+
+ /*
+ * Tests writeObject() when encoder is null.
+ */
+ public void testWriteObject_NullEncoder() {
+ MockPersistenceDelegate pd = new MockPersistenceDelegate();
+ MockEncoder enc = new MockEncoder();
+ enc.setPersistenceDelegate(MockFooStop.class, pd);
+
+ try {
+ pd.writeObject(new MockFoo(), null);
+ fail("Should throw NullPointerException!");
+ } catch (NullPointerException ex) {
+ // expected
+ }
+ }
+
+ /*
+ * Tests initialize() under normal conditions.
+ */
+ public void testInitialize_Normal() {
+ DummyPersistenceDelegate pd = new DummyPersistenceDelegate();
+ Encoder enc = new Encoder();
+ Object o1 = new Object();
+ Object o2 = new Object();
+ enc.setPersistenceDelegate(MockFooStop.class,
+ new MockPersistenceDelegate());
+ pd.initialize(MockFoo.class, o1, o2, enc);
+ assertSame(enc, CallVerificationStack.getInstance().pop());
+ assertSame(o2, CallVerificationStack.getInstance().pop());
+ assertSame(o1, CallVerificationStack.getInstance().pop());
+ assertEquals(
+ "tests.api.java.beans.PersistenceDelegateTest$MockPersistenceDelegate",
+ CallVerificationStack.getInstance().getCurrentSourceClass());
+ assertEquals("initialize", CallVerificationStack.getInstance()
+ .getCurrentSourceMethod());
+ assertSame(MockFooStop.class, CallVerificationStack.getInstance().pop());
+ assertTrue(CallVerificationStack.getInstance().empty());
+ // test interface
+ o1 = new MockObject();
+ enc.setPersistenceDelegate(MockInterface.class,
+ new MockPersistenceDelegate());
+ pd.initialize(MockObject.class, o1, o1, enc);
+ assertTrue(CallVerificationStack.getInstance().empty());
+ }
+
+ /*
+ * Tests initialize() with null class.
+ */
+ public void testInitialize_NullClass() {
+ DummyPersistenceDelegate pd = new DummyPersistenceDelegate();
+ Encoder enc = new Encoder();
+ Object o1 = new Object();
+ Object o2 = new Object();
+ enc.setPersistenceDelegate(MockFooStop.class,
+ new MockPersistenceDelegate());
+ try {
+ pd.initialize(null, o1, o2, enc);
+ fail("Should throw NullPointerException!");
+ } catch (NullPointerException ex) {
+ // expected
+ }
+ }
+
+ /*
+ * Tests initialize() with null old and new instances.
+ */
+ public void testInitialize_NullInstances() {
+ DummyPersistenceDelegate pd = new DummyPersistenceDelegate();
+ Encoder enc = new Encoder();
+ enc.setPersistenceDelegate(MockFooStop.class,
+ new MockPersistenceDelegate());
+ pd.initialize(MockFoo.class, null, null, enc);
+ assertSame(enc, CallVerificationStack.getInstance().pop());
+ assertSame(null, CallVerificationStack.getInstance().pop());
+ assertSame(null, CallVerificationStack.getInstance().pop());
+ assertEquals(
+ "tests.api.java.beans.PersistenceDelegateTest$MockPersistenceDelegate",
+ CallVerificationStack.getInstance().getCurrentSourceClass());
+ assertEquals("initialize", CallVerificationStack.getInstance()
+ .getCurrentSourceMethod());
+ assertSame(MockFooStop.class, CallVerificationStack.getInstance().pop());
+ assertTrue(CallVerificationStack.getInstance().empty());
+ }
+
+ /*
+ * Tests initialize() with null encoder.
+ */
+ public void testInitialize_NullEncoder() {
+ DummyPersistenceDelegate pd = new DummyPersistenceDelegate();
+ Object o1 = new Object();
+ Object o2 = new Object();
+ try {
+ pd.initialize(MockFoo.class, o1, o2, null);
+ fail("Should throw NullPointerException!");
+ } catch (NullPointerException ex) {
+ // expected
+ }
+ }
+
+ /*
+ * Tests mutatesTo() under normal conditions.
+ */
+ public void testMutatesTo_Normal() {
+ DummyPersistenceDelegate pd = new DummyPersistenceDelegate();
+ 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()));
+ // DummyEncoder enc = new DummyEncoder();
+ // pd.writeObject(new MockFoo(), enc);
+ }
+
+ /*
+ * Tests mutatesTo() with null parameters.
+ */
+ public void testMutatesTo_Null() {
+ DummyPersistenceDelegate pd = new DummyPersistenceDelegate();
+ assertFalse(pd.mutatesTo("test", null));
+ assertFalse(pd.mutatesTo(null, null));
+ try {
+ pd.mutatesTo(null, "test");
+ fail("Should throw NullPointerException!");
+ } catch (NullPointerException ex) {
+ // expected
+ }
+ }
+
+ /*
+ * Mock interface.
+ */
+ static interface MockInterface {
+
+ }
+
+ /*
+ * Mock interface.
+ */
+ static class MockObject implements MockInterface {
+
+ }
+
+ /*
+ * Mock Encoder.
+ */
+ static class MockEncoder extends Encoder {
+
+ public Object get(Object oldInstance) {
+ StackTraceElement[] eles = (new Throwable()).getStackTrace();
+ if (eles[2].getClassName().equals(
+ MockPersistenceDelegate.class.getName())) {
+ CallVerificationStack.getInstance().push(oldInstance);
+ }
+ return super.get(oldInstance);
+ }
+
+ public ExceptionListener getExceptionListener() {
+ return super.getExceptionListener();
+ }
+
+ public PersistenceDelegate getPersistenceDelegate(Class type) {
+ return super.getPersistenceDelegate(type);
+ }
+
+ public Object remove(Object oldInstance) {
+ StackTraceElement[] eles = (new Throwable()).getStackTrace();
+ if (eles[2].getClassName().equals(
+ MockPersistenceDelegate.class.getName())) {
+ CallVerificationStack.getInstance().push(oldInstance);
+ }
+ return super.remove(oldInstance);
+ }
+
+ public void setExceptionListener(ExceptionListener exceptionListener) {
+ super.setExceptionListener(exceptionListener);
+ }
+
+ public void setPersistenceDelegate(Class type,
+ PersistenceDelegate persistenceDelegate) {
+ super.setPersistenceDelegate(type, persistenceDelegate);
+ }
+
+ public void writeExpression(Expression oldExp) {
+ StackTraceElement[] eles = (new Throwable()).getStackTrace();
+ if (eles[2].getClassName().equals(
+ MockPersistenceDelegate.class.getName())) {
+ CallVerificationStack.getInstance().push(oldExp);
+ }
+ super.writeExpression(oldExp);
+ }
+
+ public void writeStatement(Statement oldStm) {
+ StackTraceElement[] eles = (new Throwable()).getStackTrace();
+ if (eles[2].getClassName().equals(
+ MockPersistenceDelegate.class.getName())) {
+ CallVerificationStack.getInstance().push(oldStm);
+ }
+ super.writeStatement(oldStm);
+ }
+
+ public void writeObject(Object o) {
+ super.writeObject(o);
+ }
+ }
+
+ /*
+ * Mock PersistenceDelegate subclass.
+ */
+ static class MockPersistenceDelegate extends PersistenceDelegate {
+ private boolean filter = false;
+
+ private boolean mutatesToResult = true;
+
+ public MockPersistenceDelegate() {
+ // empty
+ }
+
+ public MockPersistenceDelegate(boolean mutatesToResult, boolean filter) {
+ this.mutatesToResult = mutatesToResult;
+ this.filter = filter;
+ }
+
+ public void setMutatesToResult(boolean ret) {
+ this.mutatesToResult = ret;
+ }
+
+ public Expression instantiate(Object oldInstance, Encoder out) {
+ StackTraceElement[] eles = (new Throwable()).getStackTrace();
+ if (!this.filter
+ || eles[2].getClassName().equals(this.getClass().getName())) {
+ CallVerificationStack.getInstance().push(oldInstance);
+ CallVerificationStack.getInstance().push(out);
+ }
+ return new Expression(oldInstance, MockFoo.class, "new", null);
+ }
+
+ public void initialize(Class type, Object oldInstance,
+ Object newInstance, Encoder enc) {
+ StackTraceElement[] eles = (new Throwable()).getStackTrace();
+ if (!this.filter
+ || eles[2].getClassName().equals(this.getClass().getName())) {
+ CallVerificationStack.getInstance().push(type);
+ CallVerificationStack.getInstance().push(oldInstance);
+ CallVerificationStack.getInstance().push(newInstance);
+ CallVerificationStack.getInstance().push(enc);
+ }
+ }
+
+ public boolean mutatesTo(Object oldInstance, Object newInstance) {
+ StackTraceElement[] eles = (new Throwable()).getStackTrace();
+ if (!this.filter
+ || eles[2].getClassName().equals(this.getClass().getName())) {
+ CallVerificationStack.getInstance().push(oldInstance);
+ CallVerificationStack.getInstance().push(newInstance);
+ }
+ return this.mutatesToResult;
+ }
+
+ public void writeObject(Object oldInstance, Encoder enc) {
+ // CallVerificationStack.getInstance().push(oldInstance);
+ // CallVerificationStack.getInstance().push(enc);
+ super.writeObject(oldInstance, enc);
+ }
+
+ }
+
+ /*
+ * Dummy PersistenceDelegate subclass.
+ */
+ static class DummyPersistenceDelegate extends PersistenceDelegate {
+ public Expression instantiate(Object oldInstance, Encoder out) {
+ return new Expression(oldInstance.getClass(), "new", null);
+ }
+
+ 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);
+ }
+
+ public void writeObject(Object oldInstance, Encoder enc) {
+ super.writeObject(oldInstance, enc);
+ }
+
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyChangeEvent.ser
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyChangeEvent.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/PropertyChangeEvent.ser
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyChangeEventTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyChangeEventTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyChangeEventTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyChangeEventTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,179 @@
+/* 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.PropertyChangeSupport;
+import java.util.EventObject;
+
+import tests.util.SerializationTester;
+
+import junit.framework.TestCase;
+
+/**
+ * Test class java.beans.PropertyChangeEvent.
+ */
+public class PropertyChangeEventTest extends TestCase {
+ /*
+ * Test the constructor with normal parameters.
+ */
+ public void testConstructor_Normal() {
+ Object src = new Object();
+ Object oldValue = new Object();
+ Object newValue = new Object();
+
+ PropertyChangeEvent event = new PropertyChangeEvent(src, "myPropName",
+ oldValue, newValue);
+ assertTrue(event instanceof EventObject);
+ assertSame(src, event.getSource());
+ assertEquals("myPropName", event.getPropertyName());
+ assertSame(oldValue, event.getOldValue());
+ assertSame(newValue, event.getNewValue());
+ assertNull(event.getPropagationId());
+ }
+
+ /*
+ * Test the constructor with null parameters except the source parameter.
+ */
+ public void testConstructor_Null() {
+ Object src = new Object();
+ PropertyChangeEvent event = new PropertyChangeEvent(src, null, null,
+ null);
+ assertSame(src, event.getSource());
+ assertEquals(null, event.getPropertyName());
+ assertSame(null, event.getOldValue());
+ assertSame(null, event.getNewValue());
+ assertNull(event.getPropagationId());
+ }
+
+ /*
+ * Test the constructor with null properties but non-null old and new
+ * values.
+ */
+ public void testConstructor_NullProperty() {
+ Object src = new Object();
+ Object oldValue = new Object();
+ Object newValue = new Object();
+ PropertyChangeEvent event = new PropertyChangeEvent(src, null,
+ oldValue, newValue);
+ assertSame(src, event.getSource());
+ assertEquals(null, event.getPropertyName());
+ assertSame(oldValue, event.getOldValue());
+ assertSame(newValue, event.getNewValue());
+ assertNull(event.getPropagationId());
+ }
+
+ /*
+ * Test the constructor with null source parameter.
+ */
+ public void testConstructor_NullSrc() {
+ try {
+ new PropertyChangeEvent(null, "prop", new Object(), new Object());
+ fail("Should throw IllegalArgumentException!");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+ }
+
+ /*
+ * Test the method setPropagationId() with a normal value.
+ */
+ public void testSetPropagationId_Normal() {
+ Object src = new Object();
+ Object oldValue = new Object();
+ Object newValue = new Object();
+
+ PropertyChangeEvent event = new PropertyChangeEvent(src, "myPropName",
+ oldValue, newValue);
+ assertNull(event.getPropagationId());
+
+ Object pid = new Object();
+ event.setPropagationId(pid);
+
+ assertSame(src, event.getSource());
+ assertEquals("myPropName", event.getPropertyName());
+ assertSame(oldValue, event.getOldValue());
+ assertSame(newValue, event.getNewValue());
+ assertSame(pid, event.getPropagationId());
+ }
+
+ /*
+ * Test the method setPropagationId() with a null value.
+ */
+ public void testSetPropagationId_Null() {
+ Object src = new Object();
+ Object oldValue = new Object();
+ Object newValue = new Object();
+
+ PropertyChangeEvent event = new PropertyChangeEvent(src, "myPropName",
+ oldValue, newValue);
+ assertNull(event.getPropagationId());
+
+ // set null when already null
+ event.setPropagationId(null);
+ assertNull(event.getPropagationId());
+
+ // set a non-null value
+ Object pid = new Object();
+ event.setPropagationId(pid);
+ assertSame(src, event.getSource());
+ assertEquals("myPropName", event.getPropertyName());
+ assertSame(oldValue, event.getOldValue());
+ assertSame(newValue, event.getNewValue());
+ assertSame(pid, event.getPropagationId());
+
+ // reset to null
+ event.setPropagationId(null);
+ assertNull(event.getPropagationId());
+ }
+
+ /*
+ * Test serialization/deserialization.
+ */
+ public void testSerialization() throws Exception {
+ Object src = new Object();
+ Object oldValue = "oldValue";
+ Object newValue = "newValue";
+
+ PropertyChangeEvent event = new PropertyChangeEvent(src, "myPropName",
+ oldValue, newValue);
+ PropertyChangeEvent deEvent = (PropertyChangeEvent) SerializationTester
+ .getDeserilizedObject(event);
+ assertEquals(event.getNewValue(), deEvent.getNewValue());
+ assertEquals(event.getOldValue(), deEvent.getOldValue());
+ assertEquals(event.getPropagationId(), deEvent.getPropagationId());
+ assertEquals(event.getPropertyName(), deEvent.getPropertyName());
+ }
+
+ /*
+ * Test serialization compatibility.
+ */
+ public void testSerializationCompatibility() throws Exception {
+ Object src = new Object();
+ Object oldValue = "oldValue";
+ Object newValue = "newValue";
+
+ PropertyChangeEvent event = new PropertyChangeEvent(src, "myPropName",
+ oldValue, newValue);
+ PropertyChangeEvent deEvent = (PropertyChangeEvent) SerializationTester
+ .readObject(event,
+ "tests/api/java/beans/PropertyChangeEvent.ser");
+ assertEquals(event.getNewValue(), deEvent.getNewValue());
+ assertEquals(event.getOldValue(), deEvent.getOldValue());
+ assertEquals(event.getPropagationId(), deEvent.getPropagationId());
+ assertEquals(event.getPropertyName(), deEvent.getPropertyName());
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyChangeListenerProxyTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyChangeListenerProxyTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyChangeListenerProxyTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyChangeListenerProxyTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,86 @@
+/* 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.PropertyChangeListener;
+import java.beans.PropertyChangeListenerProxy;
+
+import junit.framework.TestCase;
+
+/**
+ * Test for PropertyChangeListenerProxy
+ */
+public class PropertyChangeListenerProxyTest extends TestCase {
+
+ PropertyChangeListenerProxy proxy;
+
+ PropertyChangeListener listener = new MockPropertyChangeListener();
+
+ String name = "mock";
+
+ static PropertyChangeEvent event = null;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ proxy = new PropertyChangeListenerProxy(name, listener);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testPropertyChangeListenerProxy() {
+ proxy = new PropertyChangeListenerProxy(null, listener);
+ assertSame(listener, proxy.getListener());
+ assertNull(proxy.getPropertyName());
+ PropertyChangeEvent newevent = new PropertyChangeEvent(new Object(),
+ "name", new Object(), new Object());
+ proxy.propertyChange(newevent);
+ assertSame(newevent, event);
+ proxy = new PropertyChangeListenerProxy(name, null);
+ assertSame(name, proxy.getPropertyName());
+ assertNull(proxy.getListener());
+ try {
+ proxy.propertyChange(new PropertyChangeEvent(new Object(), "name",
+ new Object(), new Object()));
+ fail("should null pointer");
+ } catch (NullPointerException e) {
+ }
+
+ proxy = new PropertyChangeListenerProxy(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.propertyChange(newevent);
+ assertSame(newevent, event);
+ }
+
+ public void testPropertyChange() {
+ proxy.propertyChange(null);
+ assertNull(event);
+ }
+
+ public static class MockPropertyChangeListener implements
+ PropertyChangeListener {
+ public void propertyChange(PropertyChangeEvent newevent) {
+ event = newevent;
+ }
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyChangeListenerTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyChangeListenerTest.java?rev=394923&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyChangeListenerTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyChangeListenerTest.java Tue Apr 18 05:11:09 2006
@@ -0,0 +1,39 @@
+/* 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.PropertyChangeListener;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the signature of the interface PropertyChangeListener.
+ *
+ */
+public class PropertyChangeListenerTest extends TestCase {
+
+ public void testSignature() {
+ DummyPropertyChangeListener o = new DummyPropertyChangeListener();
+ assertTrue(o instanceof PropertyChangeListener);
+ }
+
+ static class DummyPropertyChangeListener implements PropertyChangeListener {
+
+ public void propertyChange(PropertyChangeEvent event) {
+ }
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyChangeSupport.ser
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyChangeSupport.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/PropertyChangeSupport.ser
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream