harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r399949 - in /incubator/harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/VetoableChangeSupport.java test/java/org/apache/harmony/tests/java/beans/VetoableChangeSupportTest.java
Date Fri, 05 May 2006 04:22:06 GMT
Author: mloenko
Date: Thu May  4 21:22:05 2006
New Revision: 399949

URL: http://svn.apache.org/viewcvs?rev=399949&view=rev
Log:
The second patch from HARMONY-441 applied
[classlib] java.beans.PropertyChangeSupport.addPropertyChangeListener(String, PropertyChangeListener)
should not throw NPE if propertyName == null

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/VetoableChangeSupport.java
    incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/tests/java/beans/VetoableChangeSupportTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/VetoableChangeSupport.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/VetoableChangeSupport.java?rev=399949&r1=399948&r2=399949&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/VetoableChangeSupport.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/VetoableChangeSupport.java
Thu May  4 21:22:05 2006
@@ -85,19 +85,17 @@
     /**
      * @com.intel.drl.spec_ref
      */
-    public synchronized void addVetoableChangeListener(
-            String propertyName, VetoableChangeListener listener) {
-        if(propertyName == null) {
-            throw new NullPointerException("propertyName is null");
-        } else if(listener != null) {
-            ArrayList listeners =
-                (ArrayList) selectedVetoableChangeListeners.get(propertyName);
-            
+    public synchronized void addVetoableChangeListener(String propertyName,
+            VetoableChangeListener listener) {
+        if (propertyName != null && listener != null) {
+            ArrayList listeners = (ArrayList) selectedVetoableChangeListeners
+                    .get(propertyName);
+
             if (listeners == null) {
                 listeners = new ArrayList();
                 selectedVetoableChangeListeners.put(propertyName, listeners);
             }
-            
+
             listeners.add(listener);
         }
     }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/tests/java/beans/VetoableChangeSupportTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/tests/java/beans/VetoableChangeSupportTest.java?rev=399949&r1=399948&r2=399949&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/tests/java/beans/VetoableChangeSupportTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/tests/java/beans/VetoableChangeSupportTest.java
Thu May  4 21:22:05 2006
@@ -33,7 +33,7 @@
 /**
  * The test checks the class java.beans.VetoableChangeSupport
  * @author Maxim V. Berkultsev
- * @version $Revision: 1.2.6.3 $
+ * @version $Revision$
  */
 
 public class VetoableChangeSupportTest extends TestCase {
@@ -57,14 +57,24 @@
      *        java.lang.Object)
      */
     public void testVetoableChangeSupport_null() {
+        // Regression for HARMONY-228
         try {
-            // Regression for HARMONY-228
             new VetoableChangeSupport(null);
             fail("Should throw NullPointerException.");
         } catch (NullPointerException e) {
         }
     }
-    
+
+    /**
+     * @tests java.beans.VetoableChangeSupport#addVetoableChangeListener(java.lang.String,
+     *        java.beans.VetoableChangeListener)
+     */
+    public void test_addPropertyChangeListenerNullNull() throws Exception {
+        // Regression for HARMONY-441
+        new VetoableChangeSupport("bean1")
+                .addVetoableChangeListener(null, null);
+    }
+
     /**
      * The test checks the method add() with no property specified
      */
@@ -76,13 +86,10 @@
         };
         vcs.addVetoableChangeListener(vcl);
         VetoableChangeListener[] vcls = vcs.getVetoableChangeListeners();
-        if(vcls == null) {
-            fail("Returned listeners is null.");
-        } else if(vcls.length != 1) {
-            fail("Number of listeners is not equal to 1.");
-        } else {
-            assertEquals(vcl, vcls[0]);
-        }
+
+        assertNotNull("Returned listeners is null.", vcls);
+        assertEquals(1, vcls.length);
+        assertEquals(vcl, vcls[0]);
     }
     
     /**
@@ -97,13 +104,10 @@
         vcs.addVetoableChangeListener("property1", vcl);
         VetoableChangeListener[] vcls = vcs.getVetoableChangeListeners(
                 "property1");
-        if(vcls == null) {
-            fail("Returned listeners is null.");
-        } else if(vcls.length != 1) {
-            fail("Number of listeners is not equal to 1.");
-        } else {
-            assertEquals(vcl, vcls[0]);
-        }
+
+        assertNotNull("Returned listeners is null.", vcls);
+        assertEquals(1, vcls.length);
+        assertEquals(vcl, vcls[0]);
     }
     
     /**
@@ -112,23 +116,19 @@
     public void testAddVetoableChangeListenerProxy() {
         VetoableChangeSupport vcs = new VetoableChangeSupport("bean1");
         VetoableChangeListener vcl = new VetoableChangeListener() {
-            public void vetoableChange(PropertyChangeEvent pce) {
-            }
+            public void vetoableChange(PropertyChangeEvent pce) {}
         };
         vcs.addVetoableChangeListener("property1", vcl);
         VetoableChangeListener[] vcls = vcs.getVetoableChangeListeners();
-        if(vcls == null) {
-            fail("Returned listeners is null.");
-        } else if(vcls.length != 1) {
-            fail("Number of listeners is not equal to 1.");
-        } else if(!(vcls[0] instanceof VetoableChangeListenerProxy)) {
-            fail("Listener is not of VetoableChangeListenerProxy type");
-        } else {
-            assertEquals(vcl,
-                    ((VetoableChangeListenerProxy) vcls[0]).getListener());
-            assertEquals("property1",
-                    ((VetoableChangeListenerProxy) vcls[0]).getPropertyName());
-        }
+
+        assertNotNull("Returned listeners is null.", vcls);
+        assertEquals(1, vcls.length);
+
+        assertTrue("Listener is not of VetoableChangeListenerProxy type",
+                vcls[0] instanceof VetoableChangeListenerProxy);
+        assertEquals(vcl, ((VetoableChangeListenerProxy) vcls[0]).getListener());
+        assertEquals("property1", ((VetoableChangeListenerProxy) vcls[0])
+                .getPropertyName());
     }
     
     /**



Mime
View raw message