harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r465186 - in /incubator/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 Wed, 18 Oct 2006 09:28:23 GMT
Author: mloenko
Date: Wed Oct 18 02:28:23 2006
New Revision: 465186

URL: http://svn.apache.org/viewvc?view=rev&rev=465186
Log:
applied patch from HARMONY-1529
[classlib][beans] new fixes for DefaultPersistenceDelegate failures (2)

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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java?view=diff&rev=465186&r1=465185&r2=465186
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java
Wed Oct 18 02:28:23 2006
@@ -53,6 +53,13 @@
     @Override
     protected void initialize(Class<?> type, Object oldInstance,
             Object newInstance, Encoder out) {
+
+        if (newInstance == null) {
+            out.getExceptionListener().exceptionThrown(
+                    new NullPointerException(Messages.getString("beans.4A"))); //$NON-NLS-1$
+            return;
+        }
+
         try {
             PropertyDescriptor[] pds = Introspector.getBeanInfo(type)
                     .getPropertyDescriptors();

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java?view=diff&rev=465186&r1=465185&r2=465186
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java
Wed Oct 18 02:28:23 2006
@@ -27,6 +27,9 @@
 import java.beans.SimpleBeanInfo;
 import java.beans.Statement;
 
+import java.util.Vector;
+import java.util.Iterator;
+
 import junit.framework.TestCase;
 
 import org.apache.harmony.beans.tests.support.mock.MockFoo;
@@ -436,6 +439,8 @@
     public void testMutatesTo_Null() {
         MockPersistenceDelegate pd = new MockPersistenceDelegate();
 
+        assertFalse(pd.mutatesTo("test", null));
+        assertFalse(pd.mutatesTo(null, null));
         assertFalse(pd.mutatesTo(null, "test"));
     }
 
@@ -444,47 +449,38 @@
      * bean info class.
      */
     public void testInitialize_Normal() throws Exception {
-        MockEncoder enc = new MockEncoder();
+        CollectingEncoder enc = new CollectingEncoder();
         MockPersistenceDelegate pd = new MockPersistenceDelegate();
-        MockFoo b = new MockFoo();
-        b.setName("myName");
-        // b.setLabel("myLabel");
-
-        enc.writeObject(b);
-        CallVerificationStack.getInstance().clear();
-        MockFoo b2 = (MockFoo) enc.get(b);
-        b2.setName("YourName");
-
-        pd.initialize(MockFoo.class, b, b2, enc);
-
-        // should have called writeStatement()
-        Statement stm = (Statement) CallVerificationStack.getInstance().pop();
-        assertSame(b, stm.getTarget());
-        assertEquals("setName", stm.getMethodName());
-        assertEquals(1, stm.getArguments().length);
-        assertEquals("myName", stm.getArguments()[0]);
-
-        // should have called get()
-        assertEquals("myName", CallVerificationStack.getInstance().pop());
-
-        // should have called writeExpression()
-        Expression exp = (Expression) CallVerificationStack.getInstance().pop();
-        assertSame(b.getName(), exp.getValue());
-        assertSame(b, exp.getTarget());
-        assertEquals("getName", exp.getMethodName());
-        assertEquals(0, exp.getArguments().length);
-
-        // should have called get()
-        assertNull(CallVerificationStack.getInstance().pop());
-
-        // should have called writeExpression()
-        exp = (Expression) CallVerificationStack.getInstance().pop();
-        assertSame(b.getLabel(), exp.getValue());
-        assertSame(b, exp.getTarget());
-        assertEquals("getLabel", exp.getMethodName());
-        assertEquals(0, exp.getArguments().length);
-
-        assertTrue(CallVerificationStack.getInstance().empty());
+        MockFoo oldBean = new MockFoo();
+        Iterator<Statement> iter;
+        boolean found1 = false;
+        boolean found2 = false;
+
+        oldBean.setName("myName");
+        oldBean.setLabel("myLabel");
+        pd.initialize(MockFoo.class, oldBean, new MockFoo(), enc);
+        iter = enc.statements();
+
+        while (iter.hasNext()) {
+            Statement stmt = iter.next();
+            
+            if (stmt.getMethodName().equals("setName") ||
+                    stmt.getMethodName().equals("setLabel")) {
+                assertSame(oldBean, stmt.getTarget());
+                assertNotNull(stmt.getArguments());
+                assertEquals(1, stmt.getArguments().length);
+                    
+                if (stmt.getMethodName().equals("setName")) {
+                    assertEquals(oldBean.getName(), stmt.getArguments()[0]);
+                    found1 = true;
+                } else {
+                    assertEquals(oldBean.getLabel(), stmt.getArguments()[0]);
+                    found2 = true;
+                }
+            }
+        }
+        assertTrue("Required statement was not found", found1);
+        assertTrue("Required statement was not found", found2);
     }
 
     /*
@@ -984,4 +980,26 @@
         }
     }
 
+    public static class CollectingEncoder extends Encoder {
+        private Vector<Expression> expressions = new Vector<Expression>();
+        private Vector<Statement> statements = new Vector<Statement>();
+        
+        public void writeExpression(Expression exp) {
+            expressions.add(exp);
+            super.writeExpression(exp);
+        }
+
+        public void writeStatement(Statement stm) {
+            statements.add(stm);
+            super.writeStatement(stm);
+        }
+        
+        public Iterator<Expression> expressions() {
+            return expressions.iterator();
+        }
+
+        public Iterator<Statement> statements() {
+            return statements.iterator();
+        }
+    }
 }



Mime
View raw message