From 1706a5cb83b213676ae10eb7d02fa3e21483513b Mon Sep 17 00:00:00 2001 From: Nena Raab Date: Mon, 3 Dec 2018 13:04:36 +0100 Subject: [PATCH] Spring ACL uses deprecated Mockito methods This change - replaces anyListOf(Class clazz). With Java 8 this method will be removed in Mockito 3.0. This method is only used for generic friendliness to avoid casting, this is not anymore needed in Java 8. - replaces anyObject with any or any(Class clazz) Fixes gh-6212 --- .../acls/AclPermissionEvaluatorTests.java | 16 +++++++--------- .../security/acls/jdbc/JdbcAclServiceTests.java | 6 +++--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/acl/src/test/java/org/springframework/security/acls/AclPermissionEvaluatorTests.java b/acl/src/test/java/org/springframework/security/acls/AclPermissionEvaluatorTests.java index 6fc6ebf4e4..bcfc3339d9 100644 --- a/acl/src/test/java/org/springframework/security/acls/AclPermissionEvaluatorTests.java +++ b/acl/src/test/java/org/springframework/security/acls/AclPermissionEvaluatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,6 @@ import org.springframework.security.acls.model.Acl; import org.springframework.security.acls.model.AclService; import org.springframework.security.acls.model.ObjectIdentity; import org.springframework.security.acls.model.ObjectIdentityRetrievalStrategy; -import org.springframework.security.acls.model.Permission; -import org.springframework.security.acls.model.Sid; import org.springframework.security.acls.model.SidRetrievalStrategy; import org.springframework.security.core.Authentication; @@ -44,13 +42,13 @@ public class AclPermissionEvaluatorTests { AclPermissionEvaluator pe = new AclPermissionEvaluator(service); ObjectIdentity oid = mock(ObjectIdentity.class); ObjectIdentityRetrievalStrategy oidStrategy = mock(ObjectIdentityRetrievalStrategy.class); - when(oidStrategy.getObjectIdentity(anyObject())).thenReturn(oid); + when(oidStrategy.getObjectIdentity(any(Object.class))).thenReturn(oid); pe.setObjectIdentityRetrievalStrategy(oidStrategy); pe.setSidRetrievalStrategy(mock(SidRetrievalStrategy.class)); Acl acl = mock(Acl.class); - when(service.readAclById(any(ObjectIdentity.class), anyListOf(Sid.class))).thenReturn(acl); - when(acl.isGranted(anyListOf(Permission.class), anyListOf(Sid.class), eq(false))).thenReturn(true); + when(service.readAclById(any(ObjectIdentity.class), anyList())).thenReturn(acl); + when(acl.isGranted(anyList(), anyList(), eq(false))).thenReturn(true); assertThat(pe.hasPermission(mock(Authentication.class), new Object(), "READ")).isTrue(); } @@ -64,13 +62,13 @@ public class AclPermissionEvaluatorTests { AclPermissionEvaluator pe = new AclPermissionEvaluator(service); ObjectIdentity oid = mock(ObjectIdentity.class); ObjectIdentityRetrievalStrategy oidStrategy = mock(ObjectIdentityRetrievalStrategy.class); - when(oidStrategy.getObjectIdentity(anyObject())).thenReturn(oid); + when(oidStrategy.getObjectIdentity(any(Object.class))).thenReturn(oid); pe.setObjectIdentityRetrievalStrategy(oidStrategy); pe.setSidRetrievalStrategy(mock(SidRetrievalStrategy.class)); Acl acl = mock(Acl.class); - when(service.readAclById(any(ObjectIdentity.class), anyListOf(Sid.class))).thenReturn(acl); - when(acl.isGranted(anyListOf(Permission.class), anyListOf(Sid.class), eq(false))).thenReturn(true); + when(service.readAclById(any(ObjectIdentity.class), anyList())).thenReturn(acl); + when(acl.isGranted(anyList(), anyList(), eq(false))).thenReturn(true); assertThat(pe.hasPermission(mock(Authentication.class), new Object(), "write")).isTrue(); diff --git a/acl/src/test/java/org/springframework/security/acls/jdbc/JdbcAclServiceTests.java b/acl/src/test/java/org/springframework/security/acls/jdbc/JdbcAclServiceTests.java index 804c15d920..5016ab290e 100644 --- a/acl/src/test/java/org/springframework/security/acls/jdbc/JdbcAclServiceTests.java +++ b/acl/src/test/java/org/springframework/security/acls/jdbc/JdbcAclServiceTests.java @@ -15,7 +15,7 @@ */ package org.springframework.security.acls.jdbc; -import static org.mockito.Matchers.anyListOf; +import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.Mockito.when; import java.util.Arrays; @@ -57,8 +57,8 @@ public class JdbcAclServiceTests { public void readAclByIdMissingAcl() { Map result = new HashMap<>(); when( - lookupStrategy.readAclsById(anyListOf(ObjectIdentity.class), - anyListOf(Sid.class))).thenReturn(result); + lookupStrategy.readAclsById(anyList(), + anyList())).thenReturn(result); ObjectIdentity objectIdentity = new ObjectIdentityImpl(Object.class, 1); List sids = Arrays. asList(new PrincipalSid("user"));