### Question:
IsAdministrableObjectPermissionArgumentVoter extends BasicObjectPermissionArgumentVoter { @Override protected boolean isPermitted(Authentication authentication, ObjectPermission objectPermission, Object object) { SidRetrievalStrategy sidStrategy = new JasperServerSidRetrievalStrategyImpl(); Acl acl; try { acl = resourcesAclService.readAclById(getSecureObject(authentication, objectPermission), sidStrategy.getSids(authentication)); } catch (JSException e) { acl=null; } List<Permission> requiredPermissionsList = new ArrayList<Permission>(); requiredPermissionsList.add(JasperServerPermission.ADMINISTRATION); if (acl!=null && acl.isGranted(requiredPermissionsList,sidStrategy.getSids(authentication),false)) { return true; } return false; }  @Override boolean supports(ConfigAttribute attribute);  }### Answer:
@Test public void testSupports_not() throws Exception { List entries = new ArrayList<AccessControlEntry>(); Acl acl = new JasperServerAclImpl(oid,null); entries.add(new AccessControlEntryImpl(null,acl, sid,JasperServerPermission.READ,true,false,false)); acl = new JasperServerAclImpl(oid,entries); when(provider.readAclById(any(ObjectIdentity.class),anyListOf(Sid.class))).thenReturn(acl); when(authentication.getPrincipal()).thenReturn(user); assertFalse(voter.isPermitted(authentication, permission, object)); }
@Test public void testSupports_notMany() throws Exception { List entries = new ArrayList<AccessControlEntry>(); Acl acl = new JasperServerAclImpl(oid,null); entries.add(new AccessControlEntryImpl(null,acl, sid,JasperServerPermission.READ,true,false,false)); entries.add(new AccessControlEntryImpl(null,acl, sid,JasperServerPermission.WRITE,true,false,false)); acl = new JasperServerAclImpl(oid,entries); when(provider.readAclById(any(ObjectIdentity.class),anyListOf(Sid.class))).thenReturn(acl); when(authentication.getPrincipal()).thenReturn(user); assertFalse(voter.isPermitted(authentication, permission, object)); }
@Test public void testSupports_many() throws Exception { List entries = new ArrayList<AccessControlEntry>(); Acl acl = new JasperServerAclImpl(oid,null); entries.add(new AccessControlEntryImpl(null,acl, sid,JasperServerPermission.READ,true,false,false)); entries.add(new AccessControlEntryImpl(null,acl, sid,JasperServerPermission.ADMINISTRATION,true,false,false)); acl = new JasperServerAclImpl(oid,entries); when(provider.readAclById(any(ObjectIdentity.class),anyListOf(Sid.class))).thenReturn(acl); when(authentication.getPrincipal()).thenReturn(user); assertFalse(voter.isPermitted(authentication, permission, object)); }
@Test public void testSupports_empty() throws Exception { Acl acl = new JasperServerAclImpl(oid,null); when(provider.readAclById(any(ObjectIdentity.class),anyListOf(Sid.class))).thenReturn(acl); assertFalse(voter.isPermitted(authentication, permission, object)); }
@Test public void testSupports_null() throws Exception { when(provider.readAclById(any(ObjectIdentity.class),anyListOf(Sid.class))).thenReturn(null); assertFalse(voter.isPermitted(authentication, permission, object)); }