harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r470777 - in /incubator/harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/ main/java/org/apache/harmony/beans/internal/nls/ test/java/org/apache/harmony/beans/tests/java/beans/
Date Fri, 03 Nov 2006 12:22:57 GMT
Author: ayza
Date: Fri Nov  3 04:22:56 2006
New Revision: 470777

URL: http://svn.apache.org/viewvc?view=rev&rev=470777
Log:
applying patch from HARMONY-1827 "[classlib][beans] rework of EventHandlerTest (2)"

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventHandler.java
    incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
    incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventHandlerTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventHandler.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventHandler.java?view=diff&rev=470777&r1=470776&r2=470777
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventHandler.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventHandler.java
Fri Nov  3 04:22:56 2006
@@ -85,10 +85,18 @@
 
                         // we have a valid listener method at this point
                         result = m.invoke(target, args);
+                    } catch (RuntimeException e) {
+                        throw e;
                     } catch (Throwable t) {
                         System.out
                                 .println(t.getClass() + ": " + t.getMessage()); //$NON-NLS-1$
                     }
+                } else {
+                    // in order to be compatible with RI
+                    if (listenerMethodName.equals(method.getName())) {
+                        throw new IllegalArgumentException(Messages.getString(
+                                "beans.4D"));
+                    }
                 }
             }
         }
@@ -112,28 +120,28 @@
         return target;
     }
 
-    public static <T> T create(Class<T> listenerInterface, Object target, String
action,
-            String eventPropertyName, String listenerMethodName) {
-        Object proxy = Proxy.newProxyInstance(target.getClass().getClassLoader(),
-                new Class[] { listenerInterface }, new EventHandler(target, action,
-                        eventPropertyName, listenerMethodName));
-        return listenerInterface.cast(proxy);
-    }
-
-    public static <T> T create(Class<T> listenerInterface, Object target, String
action,
-            String eventPropertyName) {
-        Object proxy = Proxy.newProxyInstance(target.getClass().getClassLoader(),
-                new Class[] { listenerInterface }, new EventHandler(target, action,
-                        eventPropertyName, null));
-        return listenerInterface.cast(proxy);
-    }
-
-    public static <T> T create(Class<T> listenerInterface, Object target, String
action) {
-        Object proxy = Proxy
-                .newProxyInstance(target.getClass().getClassLoader(),
-                        new Class[] { listenerInterface }, new EventHandler(target, action,
-                                null, null));
-        return listenerInterface.cast(proxy);
+    @SuppressWarnings("unchecked")
+    public static <T> T create(Class<T> listenerInterface, Object target,
+            String action, String eventPropertyName, String listenerMethodName) {
+        return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(),
+                new Class[] { listenerInterface }, new EventHandler(target,
+                        action, eventPropertyName, listenerMethodName));
+    }
+
+    @SuppressWarnings("unchecked")
+    public static <T> T create(Class<T> listenerInterface, Object target,
+            String action, String eventPropertyName) {
+        return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(),
+                new Class[] { listenerInterface }, new EventHandler(target,
+                        action, eventPropertyName, null));
+    }
+
+    @SuppressWarnings("unchecked")
+    public static <T> T create(Class<T> listenerInterface, Object target,
+            String action) {
+        return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(),
+                new Class[] { listenerInterface }, new EventHandler(target,
+                        action, null, null));
     }
 
     private boolean isValidInvocation(Method method, Object[] arguments) {
@@ -164,8 +172,8 @@
     private Object[] getArgs(Object[] arguments) throws Exception {
         if (eventPropertyName == null) {
             return new Object[] {};
-        } else if ((arguments == null) || (arguments.length == 0)
-                || (arguments[0] == null)) {
+        } else if ((arguments == null) || (arguments.length == 0)) {
+//                || (arguments[0] == null)) {
             return arguments;
         } else {
             Object arg = arguments[0];
@@ -174,7 +182,7 @@
             while (st.hasMoreTokens()) {
                 String propertyName = st.nextToken();
                 PropertyDescriptor pd = findPropertyDescriptor(arg.getClass(),
-                        propertyName);
+                        propertyName);;
 
                 if (pd != null) {
                     Method getter = pd.getReadMethod();
@@ -192,7 +200,9 @@
                     if (method != null) {
                         arg = method.invoke(null, new Object[] {});
                     } else {
-                        throw new IntrospectionException(Messages.getString(
+                        // cannot access property getter
+                        // RI thorws NPE here so we should do the same
+                        throw new NullPointerException(Messages.getString(
                                 "beans.12", propertyName)); //$NON-NLS-1$
                     }
                 }
@@ -253,13 +263,15 @@
                                 "beans.13", action)); //$NON-NLS-1$
                     }
                 } else {
-                    throw new Exception(Messages.getString("beans.14")); //$NON-NLS-1$
+                    throw new IndexOutOfBoundsException(
+                            Messages.getString("beans.14")); //$NON-NLS-1$
                 }
             } else {
                 return result;
             }
         } catch (IntrospectionException ie) {
-            throw new Exception(Messages.getString("beans.14")); //$NON-NLS-1$
+            throw new IndexOutOfBoundsException(
+                    Messages.getString("beans.14")); //$NON-NLS-1$
         }
 
         return result;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties?view=diff&rev=470777&r1=470776&r2=470777
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
Fri Nov  3 04:22:56 2006
@@ -92,4 +92,4 @@
 beans.4A=newInstance is null
 beans.4B=type is null
 beans.4C=encoder is null
-
+beans.4D=Invalid method call

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventHandlerTest.java?view=diff&rev=470777&r1=470776&r2=470777
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventHandlerTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventHandlerTest.java
Fri Nov  3 04:22:56 2006
@@ -224,10 +224,10 @@
      * 
      */
     public static Test suite() {
-//         TestSuite suite = new TestSuite();
-//         
-//         suite.addTest(new EventHandlerTest("testInvokeWithNullPropertyName"));
-//         return suite;
+//        TestSuite suite = new TestSuite();
+//
+//        suite.addTest(new EventHandlerTest("testCreateClassObjectStringStringString_PropertyNull"));
+//        return suite;
         return new TestSuite(EventHandlerTest.class);
     }
 
@@ -453,10 +453,12 @@
         PropertyChangeListener proxy = EventHandler.create(
                 PropertyChangeListener.class, target, "text",
                 "source.label_invalid");
+
         assertTrue(Proxy.isProxyClass(proxy.getClass()));
 
         button.addPropertyChangeListener(proxy);
         String newLabel = "New Value: set text.";
+
         try {
             button.setLabel(newLabel);
             fail("Should throw NullPointerException.");
@@ -568,17 +570,18 @@
     public void testCreateClassObjectStringStringString_PropertyNull() {
         MockTarget target = new MockTarget();
         MockButton button = new MockButton();
+        String newLabel = "New Value: set text.";
         PropertyChangeListener proxy = EventHandler.create(
                 PropertyChangeListener.class, target, "text", null,
                 "propertyChange");
-        assertTrue(Proxy.isProxyClass(proxy.getClass()));
 
+        assertTrue(Proxy.isProxyClass(proxy.getClass()));
         button.addPropertyChangeListener(proxy);
-        String newLabel = "New Value: set text.";
+
         try {
             button.setLabel(newLabel);
-            fail("Should throw NullPointerException.");
-        } catch (Exception e) {
+            fail("Should throw RuntimeException.");
+        } catch (RuntimeException e) {
         }
     }
 
@@ -819,20 +822,6 @@
 
     }
 
-    public void testInvoke_extend2_2() {
-        MockFish fish = new MockFish();
-        MockFishTarget target = new MockFishTarget();
-        PropertyChangeSupport support = new PropertyChangeSupport(fish);
-        Object proxy = EventHandler.create(PropertyChangeListener.class,
-                target, "action3");
-        support.addPropertyChangeListener((PropertyChangeListener) proxy);
-        PropertyChangeEvent event = new PropertyChangeEvent(fish, "name", "1",
-                "5");
-        support.firePropertyChange(event);
-
-        assertEquals("action3", target.getActionRecord());
-    }
-
     public void testInvoke_extend3() {
         MockFish fish = new MockFish();
         MockFishTarget target = new MockFishTarget();
@@ -1070,10 +1059,6 @@
 
         public void setAction2(String value) {
             this.actionRecord = "action2";
-        }
-
-        public void setAction3() {
-            this.actionRecord = "action3";
         }
 
         public void action4() {



Mime
View raw message