/*
 * Copyright 2002-2016 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.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.security.acls;

import static org.assertj.core.api.Assertions.*;

import static org.mockito.Mockito.*;

import java.util.Locale;

import org.junit.Test;
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.SidRetrievalStrategy;
import org.springframework.security.core.Authentication;

/**
 *
 * @author Luke Taylor
 * @since 3.0
 */
public class AclPermissionEvaluatorTests {

	@Test
	@SuppressWarnings("unchecked")
	public void hasPermissionReturnsTrueIfAclGrantsPermission() throws Exception {
		AclService service = mock(AclService.class);
		AclPermissionEvaluator pe = new AclPermissionEvaluator(service);
		ObjectIdentity oid = mock(ObjectIdentity.class);
		ObjectIdentityRetrievalStrategy oidStrategy = mock(ObjectIdentityRetrievalStrategy.class);
		when(oidStrategy.getObjectIdentity(anyObject())).thenReturn(oid);
		pe.setObjectIdentityRetrievalStrategy(oidStrategy);
		pe.setSidRetrievalStrategy(mock(SidRetrievalStrategy.class));
		Acl acl = mock(Acl.class);

		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();
	}

	@Test
	public void resolvePermissionNonEnglishLocale() {
		Locale systemLocale = Locale.getDefault();
		Locale.setDefault(new Locale("tr"));

		AclService service = mock(AclService.class);
		AclPermissionEvaluator pe = new AclPermissionEvaluator(service);
		ObjectIdentity oid = mock(ObjectIdentity.class);
		ObjectIdentityRetrievalStrategy oidStrategy = mock(ObjectIdentityRetrievalStrategy.class);
		when(oidStrategy.getObjectIdentity(anyObject())).thenReturn(oid);
		pe.setObjectIdentityRetrievalStrategy(oidStrategy);
		pe.setSidRetrievalStrategy(mock(SidRetrievalStrategy.class));
		Acl acl = mock(Acl.class);

		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();

		Locale.setDefault(systemLocale);
	}
}

@@ -1041,32 +1041,143 @@
 rievalStrategy;%0A
+import org.springframework.security.acls.model.Permission;%0Aimport org.springframework.security.acls.model.Sid;%0A
 import org.sprin
@@ -1221,32 +1221,32 @@
 rievalStrategy;%0A
-
 import org.sprin
@@ -1390,40 +1390,8 @@
 est%0A
-%09@SuppressWarnings(%22unchecked%22)%0A
 %09pub
@@ -1993,33 +1993,44 @@
 .class), anyList
-(
+Of(Sid.class
 ))).thenReturn(a
@@ -2058,36 +2058,65 @@
 nted(anyList
-(), anyList(
+Of(Permission.class), anyListOf(Sid.class
 ), eq(false)
@@ -2910,17 +2910,28 @@
  anyList
-(
+Of(Sid.class
 ))).then
@@ -2975,20 +2975,49 @@
 List
-(), anyList(
+Of(Permission.class), anyListOf(Sid.class
 ), e

Use anyListOf