harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r691250 - /harmony/enhanced/classlib/trunk/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java
Date Tue, 02 Sep 2008 14:06:43 GMT
Author: tellison
Date: Tue Sep  2 07:06:42 2008
New Revision: 691250

URL: http://svn.apache.org/viewvc?rev=691250&view=rev
Log:
Apply alternate patch for HARMONY-5962 ([classlib][support] Fail on UnresolvedPermissionTest
and UnresolvedPermissionCollectionTest with Sun JDK) in place of r689792


Modified:
    harmony/enhanced/classlib/trunk/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java

Modified: harmony/enhanced/classlib/trunk/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java?rev=691250&r1=691249&r2=691250&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java
(original)
+++ harmony/enhanced/classlib/trunk/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java
Tue Sep  2 07:06:42 2008
@@ -37,7 +37,9 @@
 import java.security.PermissionCollection;
 import java.security.UnresolvedPermission;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 
 import junit.framework.Assert;
 import junit.framework.TestCase;
@@ -292,89 +294,93 @@
             Assert.assertEquals(initPC.isReadOnly(), dserPC.isReadOnly());
 
             // verify collection of permissions
-            ArrayList<Permission> refList = Collections.list(initPC.elements());
-            ArrayList<Permission> tstList = Collections.list(dserPC.elements());
-            Assert.assertEquals(refList.size(), refList.size());
+            Collection<Permission> refCollection = new HashSet<Permission>(
+                    Collections.list(initPC.elements()));
+            Collection<Permission> tstCollection = new HashSet<Permission>(
+                    Collections.list(dserPC.elements()));
 
-            int size = refList.size();
+            Assert.assertEquals(refCollection.size(), tstCollection.size());
+            int size = refCollection.size();
             if (size > 0) {
-                if (refList.get(0) instanceof UnresolvedPermission) {
-                    boolean found;
-                    UnresolvedPermission refPerm, tstPerm;
-                    for (int i = 0; i < size; i++) {
-                        found = false;
-                        refPerm = (UnresolvedPermission)refList.get(i);
-                        for(int j = 0; j < size; j++){
-                            tstPerm = (UnresolvedPermission)tstList.get(i);
-                            if(equalsUnresolvedPermission(refPerm, tstPerm)){
-                                found = true;
-                                break;
-                            }
-                        }
-                        
-                        Assert.assertTrue(found);
-                    }
-                } else {
-                    Assert.assertEquals(refList, tstList);
-                }
-            }
-        }
-        
-        /*
-         * check whether the given two UnresolvedPermission objects equal to each other
-         */
-        private boolean equalsUnresolvedPermission(UnresolvedPermission up1,
-                UnresolvedPermission up2) {
-            
-            java.security.cert.Certificate[] certs = up1.getUnresolvedCerts();
-            if (certs != null && certs.length == 0) {
-                if(null == up2.getUnresolvedCerts()){
-                    if (up1.getName().equals(up2.getName())){
-                        String up1Name = up1.getUnresolvedName();
-                        String up2Name = up2.getUnresolvedName();
-                        if(up1Name == null ? up2Name == null : up1Name.equals(up2Name)){
-                            String up1Actions = up1.getUnresolvedActions();
-                            String up2Actions = up2.getUnresolvedActions();
-                            return up1Actions == null ? up2Actions == null : up1Actions.equals(up2Actions);
-                        }
-                    }
-                }
-                
-                return false;
-            }
-            
-            return up1.equals(up2);
-            
+				ArrayList<Permission> refList = Collections.list(initPC
+						.elements());
+				ArrayList<Permission> tstList = Collections.list(dserPC
+						.elements());
+				if (refList.get(0) instanceof UnresolvedPermission
+						&& tstList.get(0) instanceof UnresolvedPermission) {
+					boolean found;
+					UnresolvedPermission refPerm, tstPerm;
+					for (int i = 0; i < size; i++) {
+						found = false;
+						refPerm = (UnresolvedPermission) refList.get(i);
+						for (int j = 0; j < size; j++) {
+							tstPerm = (UnresolvedPermission) tstList.get(i);
+							if (equalsUnresolvedPermission(refPerm, tstPerm)) {
+								found = true;
+								break;
+							}
+						}
+
+						Assert.assertTrue(found);
+					}
+				} else {
+					Assert.assertEquals(refCollection, tstCollection);
+				}
+			}
         }
-    };
     
-    /**
-     * Comparator for java.security.UnresolvedPermission objects
-     */
-    public final static SerializableAssert UNRESOLVED_PERMISSION_COMPARATOR = new SerializableAssert()
{
-
-        public void assertDeserialized(Serializable initial,
-                Serializable deserialized) {
-            UnresolvedPermission initPerm = (UnresolvedPermission) initial;
-            UnresolvedPermission dserPerm = (UnresolvedPermission) deserialized;
-            
-            java.security.cert.Certificate[] certs = initPerm.getUnresolvedCerts();
-            if (certs != null && certs.length == 0) {
-                Assert.assertEquals(initPerm.getUnresolvedType(), dserPerm
-                        .getUnresolvedType());
-                Assert.assertEquals(initPerm.getUnresolvedName(), dserPerm
-                        .getUnresolvedName());
-                Assert.assertEquals(initPerm.getUnresolvedActions(), dserPerm
-                        .getUnresolvedActions());
-                Assert.assertNull(dserPerm.getUnresolvedCerts());
-            } else {
-                Assert.assertEquals(initPerm, dserPerm);
-            }
-        }
-
+        /*
+		 * check whether the given two UnresolvedPermission objects equal to
+		 * each other
+		 */
+		private boolean equalsUnresolvedPermission(UnresolvedPermission up1,
+				UnresolvedPermission up2) {
+			java.security.cert.Certificate[] certs = up1.getUnresolvedCerts();
+			if (certs != null && certs.length == 0) {
+				if (null == up2.getUnresolvedCerts()) {
+					if (up1.getName().equals(up2.getName())) {
+						String up1Name = up1.getUnresolvedName();
+						String up2Name = up2.getUnresolvedName();
+						if (up1Name == null ? up2Name == null : up1Name
+								.equals(up2Name)) {
+							String up1Actions = up1.getUnresolvedActions();
+							String up2Actions = up2.getUnresolvedActions();
+							return up1Actions == null ? up2Actions == null
+									: up1Actions.equals(up2Actions);
+						}
+					}
+				}
+				return false;
+			}
+			return up1.equals(up2);
+		}
     };
 
     /**
+	 * Comparator for java.security.UnresolvedPermission objects
+	 */
+	public final static SerializableAssert UNRESOLVED_PERMISSION_COMPARATOR = new SerializableAssert()
{
+		public void assertDeserialized(Serializable initial,
+				Serializable deserialized) {
+			UnresolvedPermission initPerm = (UnresolvedPermission) initial;
+			UnresolvedPermission dserPerm = (UnresolvedPermission) deserialized;
+			java.security.cert.Certificate[] certs = initPerm
+					.getUnresolvedCerts();
+			if (certs != null && certs.length == 0) {
+				Assert.assertEquals(initPerm.getUnresolvedType(), dserPerm
+						.getUnresolvedType());
+				Assert.assertEquals(initPerm.getUnresolvedName(), dserPerm
+						.getUnresolvedName());
+				Assert.assertEquals(initPerm.getUnresolvedActions(), dserPerm
+						.getUnresolvedActions());
+				Assert.assertNull(dserPerm.getUnresolvedCerts());
+			} else {
+				Assert.assertEquals(initPerm, dserPerm);
+			}
+		}
+	};
+    
+    /**
      * Returns <code>comparator</code> for provided serializable
      * <code>object</code>.
      * 
@@ -405,11 +411,13 @@
                 new Class[] { Object.class });
 
         if (m.getDeclaringClass() != Object.class) {
+        	if (object instanceof UnresolvedPermission) {
+				// object is an instance of UnresolvedPermission, use
+				// UNRESOLVED_PERMISSION_COMPARATOR
+				return UNRESOLVED_PERMISSION_COMPARATOR;
+			}
             // one of classes overrides Object.equals(Object) method
             // use default comparator
-        	if (object instanceof UnresolvedPermission) {
-                return UNRESOLVED_PERMISSION_COMPARATOR;
-            }
             return DEFAULT_COMPARATOR;
         }
 



Mime
View raw message