From 412cad0bd43ffc420df2ecde81ddbfadebeaeade Mon Sep 17 00:00:00 2001 From: Rishabh Kumar Date: Fri, 20 Dec 2024 13:06:19 +0530 Subject: [PATCH] OAK-11317 : removed conversion to unmodifiableSet for test classes --- .../ExternalGroupPrincipalProviderTest.java | 28 +++++++++---------- .../PrincipalProviderDeepNestingTest.java | 5 ++-- .../SyncHandlerMappingTrackerTest.java | 15 +++++----- .../cug/impl/AbstractCugTest.java | 5 ++-- .../security/ConfigurationParametersTest.java | 8 +++--- 5 files changed, 29 insertions(+), 32 deletions(-) diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProviderTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProviderTest.java index 0df66b4beb1..838ba958aaf 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProviderTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProviderTest.java @@ -213,7 +213,7 @@ public void testGetPrincipalDynamicGroup() throws Exception { @Test public void testGetPrincipalInheritedGroups() throws Exception { - Set declared = Collections.unmodifiableSet(CollectionUtils.toSet(idp.getUser(USER_ID).getDeclaredGroups())); + Set declared = CollectionUtils.toSet(idp.getUser(USER_ID).getDeclaredGroups()); for (ExternalIdentityRef ref : declared) { for (ExternalIdentityRef inheritedGroupRef : idp.getIdentity(ref).getDeclaredGroups()) { @@ -526,7 +526,7 @@ public void testFindPrincipalsContainingPercentSign() throws Exception { sync(externalUser); Set expected = buildExpectedPrincipals("g%r%"); - Set res = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals("%", PrincipalManager.SEARCH_TYPE_ALL))); + Set res = CollectionUtils.toSet(principalProvider.findPrincipals("%", PrincipalManager.SEARCH_TYPE_ALL)); assertEquals(expected, res); Set res2 = CollectionUtils.toSet(principalProvider.findPrincipals("%", false, PrincipalManager.SEARCH_TYPE_ALL, 0, -1)); assertEquals(expected, res2); @@ -540,16 +540,16 @@ public void testFindPrincipalsByTypeNotGroup() { @Test public void testFindPrincipalsByTypeGroup() throws Exception { - Set res = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(PrincipalManager.SEARCH_TYPE_GROUP))); + Set res = CollectionUtils.toSet(principalProvider.findPrincipals(PrincipalManager.SEARCH_TYPE_GROUP)); assertEquals(getExpectedAllSearchResult(USER_ID), res); - Set res2 = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, 0, -1))); + Set res2 = CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, 0, -1)); assertEquals(getExpectedAllSearchResult(USER_ID), res2); } @Test public void testFindPrincipalsByTypeAll() throws Exception { - Set res = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(PrincipalManager.SEARCH_TYPE_ALL))); + Set res = CollectionUtils.toSet(principalProvider.findPrincipals(PrincipalManager.SEARCH_TYPE_ALL)); assertEquals(getExpectedAllSearchResult(USER_ID), res); } @@ -569,10 +569,10 @@ public void testFindPrincipalsFiltersDuplicates() throws Exception { } Iterator res = principalProvider.findPrincipals("a", PrincipalManager.SEARCH_TYPE_ALL); - assertEquals(expected, Collections.unmodifiableSet(CollectionUtils.toSet(res))); + assertEquals(expected, CollectionUtils.toSet(res)); Iterator res2 = principalProvider.findPrincipals("a", false, PrincipalManager.SEARCH_TYPE_ALL, 0, -1); - assertEquals(expected, Collections.unmodifiableSet(CollectionUtils.toSet(res2))); + assertEquals(expected, CollectionUtils.toSet(res2)); } @Test @@ -597,7 +597,7 @@ public void testFindPrincipalsWithOffset() throws Exception { long offset = 2; long expectedSize = (all.size() <= offset) ? 0 : all.size()-offset; - Set result = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, offset, -1))); + Set result = CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, offset, -1)); assertEquals(expectedSize, result.size()); } @@ -605,7 +605,7 @@ public void testFindPrincipalsWithOffset() throws Exception { public void testFindPrincipalsWithOffsetEqualsResultSize() throws Exception { Set all = getExpectedAllSearchResult(USER_ID); - Set result = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, all.size(), -1))); + Set result = CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, all.size(), -1)); assertTrue(result.isEmpty()); } @@ -613,13 +613,13 @@ public void testFindPrincipalsWithOffsetEqualsResultSize() throws Exception { public void testFindPrincipalsWithOffsetExceedsResultSize() throws Exception { Set all = getExpectedAllSearchResult(USER_ID); - Set result = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, all.size()+1, -1))); + Set result = CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, all.size()+1, -1)); assertTrue(result.isEmpty()); } @Test public void testFindPrincipalsWithLimit() { - Set result = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, 0, 1))); + Set result = CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, 0, 1)); int expectedSize = (hasDynamicGroups()) ? 0 : 1; assertEquals(expectedSize, result.size()); } @@ -628,13 +628,13 @@ public void testFindPrincipalsWithLimit() { public void testFindPrincipalsWithLimitExceedsResultSize() throws Exception { Set all = getExpectedAllSearchResult(USER_ID); - Set result = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, 0, all.size()+1))); + Set result = CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, 0, all.size()+1)); assertEquals(all, result); } @Test public void testFindPrincipalsWithZeroLimit() { - Set result = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, 0, 0))); + Set result = CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, 0, 0)); assertTrue(result.isEmpty()); } @@ -644,7 +644,7 @@ public void testFindPrincipalsWithOffsetAndLimit() throws Exception { long offset = all.size()-1; long limit = all.size(); - Set result = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, offset, limit))); + Set result = CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, offset, limit)); int expectedSize = (hasDynamicGroups()) ? 0 : 1; assertEquals(expectedSize, result.size()); } diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/PrincipalProviderDeepNestingTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/PrincipalProviderDeepNestingTest.java index 2f0ba7809c0..f4dfc848a79 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/PrincipalProviderDeepNestingTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/PrincipalProviderDeepNestingTest.java @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal; import java.security.Principal; -import java.util.Collections; import java.util.Set; import org.apache.jackrabbit.api.security.principal.GroupPrincipal; @@ -86,7 +85,7 @@ public void testGetPrincipalInheritedGroups() throws Exception { @Test public void testFindPrincipalsByHintTypeGroup() { Set expected = Set.of(new PrincipalImpl("a"), new PrincipalImpl("aa"), new PrincipalImpl("aaa")); - Set res = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals("a", PrincipalManager.SEARCH_TYPE_GROUP))); + Set res = CollectionUtils.toSet(principalProvider.findPrincipals("a", PrincipalManager.SEARCH_TYPE_GROUP)); assertEquals(expected, res); } @@ -98,7 +97,7 @@ public void testFindPrincipalsByHintTypeAll() { new PrincipalImpl("a"), new PrincipalImpl("aa"), new PrincipalImpl("aaa")); - Set res = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals("a", PrincipalManager.SEARCH_TYPE_ALL))); + Set res = CollectionUtils.toSet(principalProvider.findPrincipals("a", PrincipalManager.SEARCH_TYPE_ALL)); assertEquals(expected, res); } diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTrackerTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTrackerTest.java index 3f1bd3b6112..9274ba15d8d 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTrackerTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTrackerTest.java @@ -24,7 +24,6 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; -import java.util.Collections; import java.util.Set; import static org.apache.jackrabbit.oak.spi.security.authentication.external.impl.SyncHandlerMapping.PARAM_IDP_NAME; @@ -73,23 +72,23 @@ public void testAddingServiceWithProperties() { when(ref.getProperty(PARAM_IDP_NAME)).thenReturn("testIDP"); tracker.addingService(ref); - assertEquals(Set.of("testIDP"), Collections.unmodifiableSet(CollectionUtils.toSet(tracker.getIdpNames("testSH")))); + assertEquals(Set.of("testIDP"), CollectionUtils.toSet(tracker.getIdpNames("testSH"))); ServiceReference ref2 = mock(ServiceReference.class); when(ref2.getProperty(PARAM_SYNC_HANDLER_NAME)).thenReturn("testSH-2"); when(ref2.getProperty(PARAM_IDP_NAME)).thenReturn("testIDP-2"); tracker.addingService(ref2); - assertEquals(Set.of("testIDP"), Collections.unmodifiableSet(CollectionUtils.toSet(tracker.getIdpNames("testSH")))); - assertEquals(Set.of("testIDP-2"), Collections.unmodifiableSet(CollectionUtils.toSet(tracker.getIdpNames("testSH-2")))); + assertEquals(Set.of("testIDP"), CollectionUtils.toSet(tracker.getIdpNames("testSH"))); + assertEquals(Set.of("testIDP-2"), CollectionUtils.toSet(tracker.getIdpNames("testSH-2"))); ServiceReference ref3 = mock(ServiceReference.class); when(ref3.getProperty(PARAM_SYNC_HANDLER_NAME)).thenReturn("testSH"); when(ref3.getProperty(PARAM_IDP_NAME)).thenReturn("testIDP-3"); tracker.addingService(ref3); - assertEquals(Set.of("testIDP", "testIDP-3"), Collections.unmodifiableSet(CollectionUtils.toSet(tracker.getIdpNames("testSH")))); - assertEquals(Set.of("testIDP-2"), Collections.unmodifiableSet(CollectionUtils.toSet(tracker.getIdpNames("testSH-2")))); + assertEquals(Set.of("testIDP", "testIDP-3"), CollectionUtils.toSet(tracker.getIdpNames("testSH"))); + assertEquals(Set.of("testIDP-2"), CollectionUtils.toSet(tracker.getIdpNames("testSH-2"))); } @Test @@ -122,13 +121,13 @@ public void testModifiedServiceWithProperties() { when(ref.getProperty(PARAM_SYNC_HANDLER_NAME)).thenReturn("testSH"); when(ref.getProperty(PARAM_IDP_NAME)).thenReturn("testIDP-2"); tracker.modifiedService(ref, service); - assertEquals(Set.of("testIDP-2"), Collections.unmodifiableSet(CollectionUtils.toSet(tracker.getIdpNames("testSH")))); + assertEquals(Set.of("testIDP-2"), CollectionUtils.toSet(tracker.getIdpNames("testSH"))); when(ref.getProperty(PARAM_SYNC_HANDLER_NAME)).thenReturn("testSH-3"); when(ref.getProperty(PARAM_IDP_NAME)).thenReturn("testIDP-3"); tracker.modifiedService(ref, service); assertTrue(Iterables.isEmpty(tracker.getIdpNames("testSH"))); - assertEquals(Set.of("testIDP-3"), Collections.unmodifiableSet(CollectionUtils.toSet(tracker.getIdpNames("testSH-3")))); + assertEquals(Set.of("testIDP-3"), CollectionUtils.toSet(tracker.getIdpNames("testSH-3"))); } @Test diff --git a/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/AbstractCugTest.java b/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/AbstractCugTest.java index 00045c0596e..a0f575f73fa 100644 --- a/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/AbstractCugTest.java +++ b/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/AbstractCugTest.java @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.spi.security.authorization.cug.impl; import java.security.Principal; -import java.util.Collections; import java.util.Map; import java.util.Set; import java.util.UUID; @@ -270,7 +269,7 @@ static void assertNestedCugs(@NotNull Root root, @NotNull RootProvider rootProvi assertFalse(tree.hasProperty(HIDDEN_NESTED_CUGS)); } else { assertTrue(tree.hasProperty(HIDDEN_NESTED_CUGS)); - assertEquals(Set.of(expectedNestedPaths), Collections.unmodifiableSet(CollectionUtils.toSet(tree.getProperty(HIDDEN_NESTED_CUGS).getValue(Type.PATHS)))); + assertEquals(Set.of(expectedNestedPaths), CollectionUtils.toSet(tree.getProperty(HIDDEN_NESTED_CUGS).getValue(Type.PATHS))); assertTrue(tree.hasProperty(HIDDEN_TOP_CUG_CNT)); assertEquals(Long.valueOf(expectedNestedPaths.length), tree.getProperty(HIDDEN_TOP_CUG_CNT).getValue(Type.LONG)); @@ -283,7 +282,7 @@ static void assertNestedCugs(@NotNull Root root, @NotNull RootProvider rootProvi assertFalse(tree.hasProperty(HIDDEN_NESTED_CUGS)); } else { assertTrue(tree.hasProperty(HIDDEN_NESTED_CUGS)); - assertEquals(Set.of(expectedNestedPaths), Collections.unmodifiableSet(CollectionUtils.toSet(tree.getProperty(HIDDEN_NESTED_CUGS).getValue(Type.PATHS)))); + assertEquals(Set.of(expectedNestedPaths), CollectionUtils.toSet(tree.getProperty(HIDDEN_NESTED_CUGS).getValue(Type.PATHS))); } } diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/ConfigurationParametersTest.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/ConfigurationParametersTest.java index 49bc7757e9b..63d0c9078d0 100644 --- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/ConfigurationParametersTest.java +++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/ConfigurationParametersTest.java @@ -109,8 +109,8 @@ public void testCreationFromDictionary() { dict.put("a", "b"); ConfigurationParameters cp = ConfigurationParameters.of(dict); - assertEquals(Collections.unmodifiableSet(CollectionUtils.toSet(Iterators.forEnumeration(dict.keys()))), Set.copyOf(cp.keySet())); - assertEquals(Collections.unmodifiableSet(CollectionUtils.toSet(Iterators.forEnumeration(dict.elements()))), Set.copyOf(cp.values())); + assertEquals(CollectionUtils.toSet(Iterators.forEnumeration(dict.keys())), Set.copyOf(cp.keySet())); + assertEquals(CollectionUtils.toSet(Iterators.forEnumeration(dict.elements())), Set.copyOf(cp.values())); } @@ -463,10 +463,10 @@ public void testInvalidConversionToBoolean() { @Test public void testConversionToStringArray() { String[] stringArray = new String[] {"a", "b"}; - Set stringSet = Collections.unmodifiableSet(CollectionUtils.toSet(stringArray)); + Set stringSet = CollectionUtils.toSet(stringArray); TestObject[] testObjectArray = new TestObject[] {new TestObject("a"), new TestObject("b")}; - Set testObjectSet = Collections.unmodifiableSet(CollectionUtils.toSet(testObjectArray)); + Set testObjectSet = CollectionUtils.toSet(testObjectArray); String[] defaultStrings = new String[]{"abc", "def", "ghi"};