Skip to content

Commit

Permalink
OAK-11239: Remove usage of Guava newArrayList(vargargs) in test class…
Browse files Browse the repository at this point in the history
…es (#1836)
  • Loading branch information
reschke authored Oct 31, 2024
1 parent 14ca2b2 commit 2a93e9f
Show file tree
Hide file tree
Showing 118 changed files with 406 additions and 441 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.guava.common.collect.ImmutableMap;
import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.Group;
import org.apache.jackrabbit.api.security.user.User;
Expand Down Expand Up @@ -53,6 +52,7 @@
import java.math.BigDecimal;
import java.security.Principal;
import java.text.Normalizer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
Expand Down Expand Up @@ -1459,7 +1459,7 @@ public void testCreateValuesEmptyCollection() throws Exception {

@Test
public void testCreateValuesSkipsNull() throws Exception {
List<String> strings = Lists.newArrayList("s", null, null, "t");
List<String> strings = new ArrayList<>(Arrays.asList("s", null, null, "t"));
Value[] vs = syncCtx.createValues(strings);
assertNotNull(vs);
assertEquals(2, vs.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.apache.jackrabbit.api.security.user.Group;
import org.apache.jackrabbit.api.security.user.User;
import org.apache.jackrabbit.api.security.user.UserManager;
import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest;
import org.apache.jackrabbit.oak.spi.security.authentication.external.SyncContext;
Expand All @@ -36,6 +35,7 @@

import javax.jcr.ValueFactory;
import java.util.Collection;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -47,7 +47,7 @@ class AutoMembershipTest extends AbstractExternalAuthTest {

@Parameterized.Parameters(name = "name={1}")
public static Collection<Object[]> parameters() {
return Lists.newArrayList(
return List.of(
new Object[]{true, "DynamicSync=true"},
new Object[]{false, "DynamicSync=false"});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.jackrabbit.oak.spi.security.authentication.external.impl;

import org.apache.jackrabbit.api.security.user.User;
import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.Group;
import org.apache.jackrabbit.oak.api.Tree;
Expand All @@ -33,6 +32,7 @@
import javax.jcr.ValueFactory;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.stream.StreamSupport;

import static org.apache.jackrabbit.oak.spi.security.authentication.external.impl.ExternalIdentityConstants.REP_EXTERNAL_ID;
Expand All @@ -48,7 +48,7 @@ public class DynamicAutomembershipTest extends DynamicSyncContextTest {

@Parameterized.Parameters(name = "name={1}")
public static Collection<Object[]> parameters() {
return Lists.newArrayList(
return List.of(
new Object[] { false, "DynamicGroups=false" },
new Object[] { true, "DynamicGroups=true" });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class DynamicGroupsTest extends DynamicSyncContextTest {

@Parameterized.Parameters(name = "name={2}")
public static Collection<Object[]> parameters() {
return Lists.newArrayList(
return List.of(
new Object[] { DefaultSyncConfigImpl.PARAM_USER_MEMBERSHIP_NESTING_DEPTH_DEFAULT, false, "Membership-Nesting-Depth=0" },
new Object[] { DefaultSyncConfigImpl.PARAM_USER_MEMBERSHIP_NESTING_DEPTH_DEFAULT+1, false, "Membership-Nesting-Depth=1" },
// NOTE: shortcut for PrincipalNameResolver is ignored if dynamic-groups are enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class DelegateeTest extends AbstractJmxTest {

@Parameterized.Parameters(name = "name={1}")
public static Collection<Object[]> parameters() {
return Lists.newArrayList(
return List.of(
new Object[] { 100, "BatchSize 100" },
new Object[] { 1, "BatchSize 1" },
new Object[] { 2, "BatchSize 2" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.apache.jackrabbit.guava.common.collect.ImmutableMap;
import org.apache.jackrabbit.guava.common.collect.ImmutableSet;
import org.apache.jackrabbit.guava.common.collect.Iterators;
import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.Group;
import org.apache.jackrabbit.api.security.user.User;
Expand All @@ -39,6 +38,7 @@
import java.text.ParseException;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand All @@ -63,7 +63,7 @@ public class AutoMembershipProviderTest extends AbstractAutoMembershipTest {

@Parameterized.Parameters(name = "name={1}")
public static Collection<Object[]> parameters() {
return Lists.newArrayList(
return List.of(
new Object[] { false, "Dynamic-Groups = false" },
new Object[] { true, "Dynamic-Groups = true" });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class ExternalAuthorizableActionProviderTest extends AbstractExternalAuth

@Parameterized.Parameters(name = "name={1}")
public static Collection<Object[]> parameters() {
return Lists.newArrayList(
return List.of(
new Object[] { true, "Fail" },
new Object[] { false, "Only Warn" });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.apache.jackrabbit.guava.common.collect.ImmutableMap;
import org.apache.jackrabbit.guava.common.collect.Iterators;
import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.api.security.principal.GroupPrincipal;
import org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal;
import org.apache.jackrabbit.api.security.principal.PrincipalManager;
Expand Down Expand Up @@ -50,6 +49,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -79,7 +79,7 @@ public class ExternalGroupPrincipalProviderDMTest extends AbstractPrincipalTest

@Parameterized.Parameters(name = "name={2}")
public static Collection<Object[]> parameters() {
return Lists.newArrayList(
return List.of(
new Object[] { true, DefaultSyncConfigImpl.PARAM_USER_MEMBERSHIP_NESTING_DEPTH_DEFAULT+1, "Dynamic Groups Enabled, Membership-Nesting-Depth=1" },
new Object[] { true, DefaultSyncConfigImpl.PARAM_USER_MEMBERSHIP_NESTING_DEPTH_DEFAULT+2, "Dynamic Groups Enabled, Membership-Nesting-Depth=2" },
new Object[] { false, DefaultSyncConfigImpl.PARAM_USER_MEMBERSHIP_NESTING_DEPTH_DEFAULT, "Dynamic Groups NOT Enabled" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.guava.common.collect.ImmutableMap;
import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.User;
import org.apache.jackrabbit.oak.api.CommitFailedException;
Expand All @@ -37,6 +36,7 @@
import org.jetbrains.annotations.NotNull;
import org.junit.Test;

import java.util.List;
import java.util.Set;

import static org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT;
Expand Down Expand Up @@ -150,7 +150,7 @@ public void testRemoveExternalPrincipalNamesAsSystem() throws Exception {
public void testModifyExternalPrincipalNames() throws Exception {
Tree userTree = root.getTree(externalUserPath);
try {
userTree.setProperty(ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES, Lists.newArrayList("principalNames"), Type.STRINGS);
userTree.setProperty(ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES, List.of("principalNames"), Type.STRINGS);
root.commit();
fail("Changing rep:externalPrincipalNames must be detected.");
} catch (CommitFailedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal;

import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
import org.apache.jackrabbit.api.security.JackrabbitAccessControlManager;
import org.apache.jackrabbit.api.security.user.Authorizable;
Expand Down Expand Up @@ -62,6 +61,7 @@
import javax.security.auth.login.Configuration;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
Expand All @@ -87,7 +87,7 @@ public class ExternalUserValidatorTest extends ExternalLoginTestBase {

@Parameterized.Parameters(name = "name={2}")
public static Collection<Object[]> parameters() {
return Lists.newArrayList(
return List.of(
new Object[] { IdentityProtectionType.NONE, false, "None, Default Sync" },
new Object[] { IdentityProtectionType.WARN, true, "Warn, Dynamic Sync" },
new Object[] { IdentityProtectionType.WARN, false, "Warn, Default Sync" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class PrincipalProviderAutoMembershipTest extends ExternalGroupPrincipalP

@Parameterized.Parameters(name = "name={2}")
public static Collection<Object[]> parameters() {
return Lists.newArrayList(
return List.of(
new Object[] { true, false, "Nested automembership = true, Dynamic Groups = false" },
new Object[] { false, false, "Nested automembership = false, Dynamic Groups = false" },
new Object[] { false, true, "Nested automembership = false, Dynamic Groups = true" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public SystemPrincipalConfigTest(String[] systemUserNames, String name) {

@Parameterized.Parameters(name = "name={1}")
public static Collection<Object[]> parameters() {
return Lists.newArrayList(
return List.of(
new Object[] { null, "Null" },
new Object[] { new String[0], "Empty names" },
new Object[] { new String[] {SYSTEM_USER_NAME_1}, "Single name" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.jackrabbit.oak.security.authentication.ldap.impl;

import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -26,6 +25,7 @@
import org.junit.runners.Parameterized;

import java.util.Collection;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand All @@ -41,7 +41,7 @@ public class LdapIdentityProviderUseSSLTest extends AbstractLdapIdentityProvider

@Parameterized.Parameters(name = "LdapConfiguration with {2}")
public static Collection<Object[]> parameters() {
return Lists.newArrayList(
return List.of(
new Object[] {false, false, null, "useSSL=false, useTLS=false, enabled_protocols=NA"},
new Object[] {true, false, null, "useSSL=true, useTLS=false, enabled_protocols=NA"},
new Object[] {true, false, new String[] {PROTOCOL}, "useSSL=true, useTLS=false, enabled_protocols=["+PROTOCOL+"]"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
*/
package org.apache.jackrabbit.oak.security.authentication.ldap.impl;

import org.apache.jackrabbit.guava.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import javax.jcr.SimpleCredentials;
import java.util.Collection;
import java.util.List;

@RunWith(Parameterized.class)
public class LookupOnValidateTest extends AbstractLdapIdentityProviderTest {

@Parameterized.Parameters(name = "name={1}")
public static Collection<Object[]> parameters() {
return Lists.newArrayList(
return List.of(
new Object[] { false, false, false, "False False" },
new Object[] { false, true, false, "False True" },
new Object[] { true, false, false, "True False"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import org.apache.jackrabbit.guava.common.base.Strings;
import org.apache.jackrabbit.guava.common.collect.Iterators;
import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.guava.common.collect.Maps;
import com.microsoft.azure.storage.StorageException;

Expand Down Expand Up @@ -262,7 +261,7 @@ public void testBackendWriteDifferentSizedRecords() throws IOException, NoSuchAl
// 16500 - over 8K and 16K but under 64K (another reasonably expected stream buffer size)
// 66000 - over 64K but under 128K (probably the largest reasonably expected stream buffer size)
// 132000 - over 128K
for (int size : Lists.newArrayList(0, 10, 1000, 4100, 16500, 66000, 132000)) {
for (int size : List.of(0, 10, 1000, 4100, 16500, 66000, 132000)) {
File testFile = folder.newFile();
copyInputStreamToFile(randomStream(size, size), testFile);
DataIdentifier identifier = new DataIdentifier(getIdForInputStream(new FileInputStream(testFile)));
Expand Down Expand Up @@ -387,7 +386,7 @@ public void testBackendGetAllIdentifiersNoRecordsReturnsNone() throws DataStoreE

@Test
public void testBackendGetAllIdentifiers() throws DataStoreException, IOException, NoSuchAlgorithmException {
for (int expectedRecCount : Lists.newArrayList(1, 2, 5)) {
for (int expectedRecCount : List.of(1, 2, 5)) {
final List<DataIdentifier> ids = new ArrayList<>();
for (int i=0; i<expectedRecCount; i++) {
File testfile = folder.newFile();
Expand Down Expand Up @@ -444,7 +443,7 @@ public void testBackendGetRecordInvalidIdentifierThrowsDataStoreException() {

@Test
public void testBackendGetAllRecordsReturnsAll() throws DataStoreException, IOException {
for (int recCount : Lists.newArrayList(0, 1, 2, 5)) {
for (int recCount : List.of(0, 1, 2, 5)) {
Map<DataIdentifier, String> addedRecords = Maps.newHashMap();
if (0 < recCount) {
for (int i = 0; i < recCount; i++) {
Expand Down Expand Up @@ -479,9 +478,9 @@ public void testBackendGetAllRecordsReturnsAll() throws DataStoreException, IOEx

@Test
public void testBackendAddMetadataRecordsFromInputStream() throws DataStoreException, IOException, NoSuchAlgorithmException {
for (boolean fromInputStream : Lists.newArrayList(false, true)) {
for (boolean fromInputStream : List.of(false, true)) {
String prefix = String.format("%s.META.", getClass().getSimpleName());
for (int count : Lists.newArrayList(1, 3)) {
for (int count : List.of(1, 3)) {
Map<String, String> records = Maps.newHashMap();
for (int i = 0; i < count; i++) {
String recordName = String.format("%sname.%d", prefix, i);
Expand Down Expand Up @@ -552,8 +551,8 @@ public void testBackendAddMetadataRecordNullFileThrowsNullPointerException() thr
@Test
public void testBackendAddMetadataRecordNullEmptyNameThrowsIllegalArgumentException() throws DataStoreException, IOException {
final String data = "testData";
for (boolean fromInputStream : Lists.newArrayList(false, true)) {
for (String name : Lists.newArrayList(null, "")) {
for (boolean fromInputStream : List.of(false, true)) {
for (String name : Arrays.asList(null, "")) {
try {
if (fromInputStream) {
backend.addMetadataRecord(new ByteArrayInputStream(data.getBytes()), name);
Expand All @@ -576,7 +575,7 @@ public void testBackendAddMetadataRecordNullEmptyNameThrowsIllegalArgumentExcept
public void testBackendGetMetadataRecordInvalidName() throws DataStoreException {
backend.addMetadataRecord(randomStream(0, 10), "testRecord");
assertNull(backend.getMetadataRecord("invalid"));
for (String name : Lists.newArrayList("", null)) {
for (String name : Arrays.asList("", null)) {
try {
backend.getMetadataRecord(name);
fail("Expect to throw");
Expand Down Expand Up @@ -631,7 +630,7 @@ public void testBackendGetAllMetadataRecordsNullPrefixThrowsNullPointerException
@Test
public void testBackendDeleteMetadataRecord() throws DataStoreException {
backend.addMetadataRecord(randomStream(0, 10), "name");
for (String name : Lists.newArrayList("invalid", "", null)) {
for (String name : Arrays.asList("invalid", "", null)) {
if (Strings.isNullOrEmpty(name)) {
try {
backend.deleteMetadataRecord(name);
Expand All @@ -649,7 +648,7 @@ public void testBackendDeleteMetadataRecord() throws DataStoreException {
@Test
public void testBackendMetadataRecordExists() throws DataStoreException {
backend.addMetadataRecord(randomStream(0, 10), "name");
for (String name : Lists.newArrayList("invalid", "", null)) {
for (String name : Arrays.asList("invalid", "", null)) {
if (Strings.isNullOrEmpty(name)) {
try {
backend.metadataRecordExists(name);
Expand Down
Loading

0 comments on commit 2a93e9f

Please sign in to comment.