harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r534000 - in /harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/DefaultPersistenceDelegate.java test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java
Date Tue, 01 May 2007 10:45:37 GMT
Author: tellison
Date: Tue May  1 03:45:37 2007
New Revision: 534000

URL: http://svn.apache.org/viewvc?view=rev&rev=534000
Log:
Apply patch HARMONY-3782 ([classlib][beans]java.beans.DefaultPersistenceDelegate.mutates should
delegate the comparation to super class ...)

Modified:
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java
    harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java?view=diff&rev=534000&r1=533999&r2=534000
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java
Tue May  1 03:45:37 2007
@@ -17,6 +17,7 @@
 
 package java.beans;
 
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 import org.apache.harmony.beans.internal.nls.Messages;
@@ -165,23 +166,29 @@
 
     @Override
     protected boolean mutatesTo(Object oldInstance, Object newInstance) {
-        if (oldInstance != null) {
+        if (oldInstance != null && constructorPropertyNames != null
+                && constructorPropertyNames.length > 0) {
+
+            //Get explicitly declared equals method.
+            Method equalsMethod = null;
             try {
-                Method equalsMethod = oldInstance.getClass().getMethod(
+                equalsMethod = oldInstance.getClass().getDeclaredMethod(
                         "equals", new Class[] { Object.class }); //$NON-NLS-1$
 
-                if (equalsMethod != null) {
-                    Object result = equalsMethod.invoke(oldInstance,
-                            new Object[] { newInstance });
+            } catch (NoSuchMethodException e) {
+                // does not declare explicitly an equals method.
+            }
 
+            if (equalsMethod != null) {
+                    Object result;
+                    try {
+                        result = equalsMethod.invoke(oldInstance,
+                                new Object[] { newInstance });
+                    } catch (Exception e) {
+                        //should not happen here.
+                        throw new Error(e);
+                    }
                     return ((Boolean) result).booleanValue();
-                }
-            } catch (Exception e) {
-                // XXX bad style of logging
-                System.out.println(Messages.getString(
-                        "beans.02", e.getClass(), e.getMessage())); //$NON-NLS-1$
-
-                return false;
             }
         }
         return super.mutatesTo(oldInstance, newInstance);

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java?view=diff&rev=534000&r1=533999&r2=534000
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java
Tue May  1 03:45:37 2007
@@ -465,6 +465,102 @@
         assertFalse(pd.mutatesTo(null, null));
         assertFalse(pd.mutatesTo(null, "test"));
     }
+    
+    //Regression for HARMONY-3782
+    public void test_mutates_with_equals_true() {
+        MyObjectEqualsTrue o1 = new MyObjectEqualsTrue();
+        MyObjectEqualsTrue o2 = new MyObjectEqualsTrue();
+        MyDefaultPersistenceDelegate myDefaultPersistenceDelegate = new MyDefaultPersistenceDelegate();
+        assertTrue(myDefaultPersistenceDelegate.mutatesTo(o1, o2));
+        assertFalse(o1.equalsCalled);        
+        
+        o1 = new MyObjectEqualsTrue();
+        o2 = new MyObjectEqualsTrue();
+        myDefaultPersistenceDelegate = new MyDefaultPersistenceDelegate(new String[0]);
+        assertTrue(myDefaultPersistenceDelegate.mutatesTo(o1, o2));
+        assertFalse(o1.equalsCalled);
+        
+        o1 = new MyObjectEqualsTrue();
+        o2 = new MyObjectEqualsTrue();
+        myDefaultPersistenceDelegate = new MyDefaultPersistenceDelegate(new String[]{"TEST_ARUGMENT_NAME"});
+        assertTrue(myDefaultPersistenceDelegate.mutatesTo(o1, o2));
+        assertTrue(o1.equalsCalled);              
+    }
+    
+    
+    public void test_mutates_with_equals_false() {
+        MyObjectEqualsFalse o1 = new MyObjectEqualsFalse();
+        MyObjectEqualsFalse o2 = new MyObjectEqualsFalse();
+        MyDefaultPersistenceDelegate myDefaultPersistenceDelegate = new MyDefaultPersistenceDelegate();
+        assertTrue(myDefaultPersistenceDelegate.mutatesTo(o1, o2));
+        assertFalse(o1.equalsCalled);
+        
+        o1 = new MyObjectEqualsFalse();
+        o2 = new MyObjectEqualsFalse();
+        myDefaultPersistenceDelegate = new MyDefaultPersistenceDelegate(new String[0]);
+        assertTrue(myDefaultPersistenceDelegate.mutatesTo(o1, o2));
+        assertFalse(o1.equalsCalled);
+        
+        o1 = new MyObjectEqualsFalse();
+        o2 = new MyObjectEqualsFalse();
+        myDefaultPersistenceDelegate = new MyDefaultPersistenceDelegate(new String[]{"TEST_ARUGMENT_NAME"});
+        assertFalse(myDefaultPersistenceDelegate.mutatesTo(o1, o2));
+        assertTrue(o1.equalsCalled);        
+    }
+    
+    public void test_mutates_with_no_equals()
+    {
+        MyObjectNoExplicitEquals o1 = new MyObjectNoExplicitEquals();
+        MyObjectNoExplicitEquals o2 = new MyObjectNoExplicitEquals();
+        MyDefaultPersistenceDelegate myDefaultPersistenceDelegate = new MyDefaultPersistenceDelegate();
+        assertTrue(myDefaultPersistenceDelegate.mutatesTo(o1, o2));
+        assertFalse(o1.equalsCalled);
+        
+        o1 = new MyObjectNoExplicitEquals();
+        o2 = new MyObjectNoExplicitEquals();
+        myDefaultPersistenceDelegate = new MyDefaultPersistenceDelegate(new String[]{"TEST_ARUGMENT_NAME"});
+        assertTrue(myDefaultPersistenceDelegate.mutatesTo(o1, o2));
+        assertFalse(o1.equalsCalled);
+    }
+    
+    public class MyDefaultPersistenceDelegate extends
+            DefaultPersistenceDelegate {
+        public MyDefaultPersistenceDelegate() {
+            super();
+        }
+
+        public MyDefaultPersistenceDelegate(String[] constructorPropertyNames) {
+            super(constructorPropertyNames);
+        }
+
+        public boolean mutatesTo(Object oldInstance, Object newInstance) {
+            return super.mutatesTo(oldInstance, newInstance);
+        }
+    }
+
+    public class MyObjectEqualsTrue extends Object {
+        public boolean equalsCalled = false;
+
+        @Override
+        public boolean equals(Object object) {
+            equalsCalled = true;
+            return true;
+        }
+    }
+
+    public class MyObjectEqualsFalse extends Object {
+        public boolean equalsCalled = false;
+
+        @Override
+        public boolean equals(Object object) {
+            equalsCalled = true;
+            return false;
+        }
+    }
+
+    public class MyObjectNoExplicitEquals extends MyObjectEqualsFalse {
+
+    }
 
     /*
      * Test initialize() under normal conditions with a bean that does not have



Mime
View raw message