You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by an...@apache.org on 2016/04/18 17:24:31 UTC

svn commit: r1739771 - /jackrabbit/oak/trunk/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalIdentityRefTest.java

Author: angela
Date: Mon Apr 18 15:24:31 2016
New Revision: 1739771

URL: http://svn.apache.org/viewvc?rev=1739771&view=rev
Log:
OAK-4223 : Minor improvements to ExternalIdentityRefTest

Modified:
    jackrabbit/oak/trunk/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalIdentityRefTest.java

Modified: jackrabbit/oak/trunk/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalIdentityRefTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalIdentityRefTest.java?rev=1739771&r1=1739770&r2=1739771&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalIdentityRefTest.java (original)
+++ jackrabbit/oak/trunk/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/ExternalIdentityRefTest.java Mon Apr 18 15:24:31 2016
@@ -16,10 +16,12 @@
  */
 package org.apache.jackrabbit.oak.spi.security.authentication.external;
 
+import java.util.HashMap;
 import java.util.Map;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import org.junit.Test;
@@ -28,7 +30,6 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
 
 public class ExternalIdentityRefTest {
 
@@ -93,22 +94,41 @@ public class ExternalIdentityRefTest {
 
     @Test
     public void testEquals() {
-        assertTrue(refNullProvider.equals(refNullProvider));
-        assertTrue(refNullProvider.equals(new ExternalIdentityRef(USERID, refNullProvider.getProviderName())));
-        assertTrue(refNullProvider.equals(new ExternalIdentityRef(USERID, refEmptyProvider.getProviderName())));
-
-        assertTrue(refNullProvider.equals(refEmptyProvider));
-        assertTrue(refEmptyProvider.equals(refNullProvider));
-
-        assertFalse(refNullProvider.equals(ref));
-        assertFalse(ref.equals(refNullProvider));
-
-        assertFalse(refNullProvider.equals(null));
-        assertFalse(refNullProvider.equals(new ExternalIdentityRef("anotherId", null)));
-
-        assertTrue(ref.equals(ref));
-        assertTrue(ref.equals(new ExternalIdentityRef(ref.getId(), ref.getProviderName())));
-        assertTrue(ref.equals(new ExternalIdentityRef(USERID, PROVIDER_NAME)));
+        assertEquals(refNullProvider, refNullProvider);
+        assertEquals(refNullProvider, new ExternalIdentityRef(USERID, refNullProvider.getProviderName()));
+        assertEquals(refNullProvider, new ExternalIdentityRef(USERID, refEmptyProvider.getProviderName()));
+
+        assertEquals(refNullProvider, refEmptyProvider);
+        assertEquals(refEmptyProvider, refNullProvider);
+
+        assertEquals(ref, ref);
+        assertEquals(ref, new ExternalIdentityRef(ref.getId(), ref.getProviderName()));
+        assertEquals(ref, new ExternalIdentityRef(USERID, PROVIDER_NAME));
+    }
+
+    @Test
+    public void testNotEquals() {
+        Map<ExternalIdentityRef, ExternalIdentityRef> notEqual = new HashMap();
+        notEqual.put(refNullProvider, ref);
+        notEqual.put(refEmptyProvider, ref);
+        notEqual.put(refNullProvider, null);
+        notEqual.put(refNullProvider, new ExternalIdentityRef("anotherId", null));
+        notEqual.put(ref, new ExternalIdentityRef("anotherId", PROVIDER_NAME));
+        notEqual.put(ref, new ExternalIdentityRef(USERID, "anotherProvider"));
+
+        for (Map.Entry<ExternalIdentityRef, ExternalIdentityRef> entry : notEqual.entrySet()) {
+            ExternalIdentityRef r1 = entry.getKey();
+            ExternalIdentityRef r2 = entry.getValue();
+
+            assertFalse(r1.equals(r2));
+            if (r2 != null) {
+                assertFalse(r2.equals(r1));
+            }
+        }
+    }
+
+    @Test
+    public void testNotEqualsExternalIdentity() {
         assertFalse(ref.equals(new ExternalIdentity() {
             @Nonnull
             @Override
@@ -136,7 +156,7 @@ public class ExternalIdentityRefTest {
 
             @Nonnull
             @Override
-            public Iterable<ExternalIdentityRef> getDeclaredGroups() throws ExternalIdentityException {
+            public Iterable<ExternalIdentityRef> getDeclaredGroups() {
                 return ImmutableSet.of();
             }
 
@@ -147,4 +167,11 @@ public class ExternalIdentityRefTest {
             }
         }));
     }
+
+    @Test
+    public void testToString() {
+        for (ExternalIdentityRef r : ImmutableList.of(ref, refEmptyProvider, refEmptyProvider)) {
+            assertEquals("ExternalIdentityRef{" + "id='" + r.getId() + '\'' + ", providerName='" + r.getProviderName() + '\'' + '}', r.toString());
+        }
+    }
 }