harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odea...@apache.org
Subject svn commit: r932371 - in /harmony/enhanced/java/trunk/classlib/modules/beans/src: main/java/java/beans/Statement.java test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java
Date Fri, 09 Apr 2010 12:01:58 GMT
Author: odeakin
Date: Fri Apr  9 12:01:58 2010
New Revision: 932371

URL: http://svn.apache.org/viewvc?rev=932371&view=rev
Log:
Apply patch for HARMONY-4392 ([classlib][beans]java.beans.Statement/Expression cannot handle
overloaded constructor properly)

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

Modified: harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/Statement.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/Statement.java?rev=932371&r1=932370&r2=932371&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/Statement.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/Statement.java
Fri Apr  9 12:01:58 2010
@@ -322,8 +322,30 @@ public class Statement {
                     }
                 }
                 if (found) {
-                    result = constructor;
-                    break;
+                    if (result == null) {
+                        // first time, set constructor
+                        result = constructor;
+                        continue;
+                    }
+                    // find out more suitable constructor
+                    Class<?>[] resultParameterTypes = result
+                            .getParameterTypes();
+                    boolean isAssignable = true;
+                    for (int j = 0; j < parameterTypes.length; ++j) {
+                        if (theArguments[j] != null
+                                && !(isAssignable &= resultParameterTypes[j]
+                                        .isAssignableFrom(parameterTypes[j]))) {
+                            break;
+                        }
+                        if (theArguments[j] == null
+                                && !(isAssignable &= parameterTypes[j]
+                                        .isAssignableFrom(resultParameterTypes[j]))) {
+                            break;
+                        }
+                    }
+                    if (isAssignable) {
+                        result = constructor;
+                    }
                 }
             }
         }

Modified: harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java?rev=932371&r1=932370&r2=932371&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java
Fri Apr  9 12:01:58 2010
@@ -19,6 +19,7 @@ package org.apache.harmony.beans.tests.j
 
 import java.beans.DefaultPersistenceDelegate;
 import java.beans.Expression;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Vector;
 
@@ -1201,4 +1202,176 @@ public class ExpressionTest extends Test
             return "haha";
         }
     }
+
+    public void test_Expression_Constructor_OneArgument_senario1()
+            throws Exception {
+        Object[] arguments = new Object[] { "test" };
+        Expression expression = new Expression(SampleObject.class, "new",
+                arguments);
+        assertTrue(expression.getValue() instanceof SampleObject);
+        SampleObject.assertCalled("string", arguments);
+    }
+
+    public void test_Expression_Constructor_OneArgument_senario2()
+            throws Exception {
+        Object[] arguments = new Object[] { new Integer(1) };
+        Expression expression = new Expression(SampleObject.class, "new",
+                arguments);
+        assertTrue(expression.getValue() instanceof SampleObject);
+        SampleObject.assertCalled("integer", arguments);
+    }
+
+    public void test_Expression_Constructor_OneArgument_senario3()
+            throws Exception {
+        Object[] arguments = new Object[] { new Object() };
+        Expression expression = new Expression(SampleObject.class, "new",
+                arguments);
+        assertTrue(expression.getValue() instanceof SampleObject);
+        SampleObject.assertCalled("object", arguments);
+    }
+
+    public void test_Expression_Constructor_OneArgument_senario4()
+            throws Exception {
+        Object[] arguments = new Object[] { null };
+        Expression expression = new Expression(SampleObject.class, "new",
+                arguments);
+        assertTrue(expression.getValue() instanceof SampleObject);
+        SampleObject.assertCalled("object", arguments);
+    }
+
+    public void test_Expression_Constructor_twoArguments_senario1()
+            throws Exception {
+        Object[] arguments = new Object[] { null, null };
+        Expression expression = new Expression(SampleObject.class, "new",
+                arguments);
+        assertTrue(expression.getValue() instanceof SampleObject);
+        SampleObject.assertCalled("object_object", arguments);
+    }
+
+    public void test_Expression_Constructor_twoArguments_senario2()
+            throws Exception {
+        Object[] arguments = new Object[] { null, "test" };
+        Expression expression = new Expression(SampleObject.class, "new",
+                arguments);
+        assertTrue(expression.getValue() instanceof SampleObject);
+        SampleObject.assertCalled("object_string", arguments);
+    }
+
+    public void test_Expression_Constructor_twoArguments_senario3()
+            throws Exception {
+        Object[] arguments = new Object[] { new Object(), "test" };
+        Expression expression = new Expression(SampleObject.class, "new",
+                arguments);
+        assertTrue(expression.getValue() instanceof SampleObject);
+        SampleObject.assertCalled("object_string", arguments);
+    }
+
+    public void test_Expression_Constructor_twoArguments_senario4()
+            throws Exception {
+        Object[] arguments = new Object[] { "test1", "test2" };
+        Expression expression = new Expression(SampleObject.class, "new",
+                arguments);
+        assertTrue(expression.getValue() instanceof SampleObject);
+        SampleObject.assertCalled("string_string", arguments);
+    }
+
+    public void test_Expression_Constructor_twoArguments_senario5()
+            throws Exception {
+        Object[] arguments = new Object[] { "test", new Integer(1) };
+        Expression expression = new Expression(SampleObject.class, "new",
+                arguments);
+        assertTrue(expression.getValue() instanceof SampleObject);
+        SampleObject.assertCalled("string_integer", arguments);
+    }
+
+    public void test_Expression_Constructor_twoArguments_senario6()
+            throws Exception {
+        Object[] arguments = new Object[] { "test", (String) null };
+        Expression expression = new Expression(SampleObject.class, "new",
+                arguments);
+        assertTrue(expression.getValue() instanceof SampleObject);
+        SampleObject.assertCalled("object_object", arguments);
+    }
+
+    public void test_Expression_Constructor_twoArguments_senario7()
+            throws Exception {
+        Object[] arguments = new Object[] { new Integer(1), "test" };
+        Expression expression = new Expression(SampleObject.class, "new",
+                arguments);
+        assertTrue(expression.getValue() instanceof SampleObject);
+        SampleObject.assertCalled("object_string", arguments);
+    }
+
+    public void test_Expression_Constructor_twoArguments_senario8()
+            throws Exception {
+        Object[] arguments = new Object[] { new Integer(1), new Integer(2) };
+        Expression expression = new Expression(SampleObject.class, "new",
+                arguments);
+        assertTrue(expression.getValue() instanceof SampleObject);
+        SampleObject.assertCalled("object_object", arguments);
+    }
+
+    public static class SampleObject {
+
+        public static String calledMethod = null;
+
+        public static ArrayList<Object> receivedArguments = new ArrayList<Object>();
+
+        public SampleObject(String o) {
+            reset();
+            calledMethod = "string";
+            receivedArguments.add(o);
+        }
+
+        public SampleObject(Object o) {
+            reset();
+            calledMethod = "object";
+            receivedArguments.add(o);
+        }
+
+        public SampleObject(Integer o) {
+            reset();
+            calledMethod = "integer";
+            receivedArguments.add(o);
+        }
+
+        public SampleObject(Object arg1, Object arg2) {
+            reset();
+            calledMethod = "object_object";
+            receivedArguments.add(arg1);
+            receivedArguments.add(arg2);
+        }
+
+        public SampleObject(Object arg1, String arg2) {
+            reset();
+            calledMethod = "object_string";
+            receivedArguments.add(arg1);
+            receivedArguments.add(arg2);
+        }
+
+        public SampleObject(String arg1, String arg2) {
+            reset();
+            calledMethod = "string_string";
+            receivedArguments.add(arg1);
+            receivedArguments.add(arg2);
+        }
+
+        public SampleObject(String arg1, Integer arg2) {
+            reset();
+            calledMethod = "string_integer";
+            receivedArguments.add(arg1);
+            receivedArguments.add(arg2);
+        }
+
+        public static void assertCalled(String methodName, Object[] arguments) {
+            assertEquals(methodName, calledMethod);
+            assertTrue(Arrays.equals(arguments, receivedArguments.toArray()));
+            reset();
+        }
+
+        public static void reset() {
+            receivedArguments.clear();
+            calledMethod = null;
+        }
+    }
 }



Mime
View raw message