### Question:
IsRecipientOwnPermissionArgumentVoter extends BasicObjectPermissionArgumentVoter { @Override protected boolean isPermitted(Authentication authentication, ObjectPermission objectPermission, Object object) { boolean res = false; if (objectPermission.getPermissionRecipient() instanceof User){ User recipient = (User)objectPermission.getPermissionRecipient(); User user = (User)authentication.getPrincipal(); res = (recipient.getUsername() == user.getUsername() || (recipient.getUsername() != null && recipient.getUsername().equals(user.getUsername()))) && (recipient.getTenantId() == user.getTenantId() || (recipient.getTenantId() != null && recipient.getTenantId().equals(user.getTenantId()))); } else if (objectPermission.getPermissionRecipient() instanceof Role){ Role recipient = (Role)objectPermission.getPermissionRecipient(); final Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities(); for (GrantedAuthority authority : authorities){ String name = authority.getAuthority(); String tenantId = authority instanceof TenantQualified ? ((TenantQualified)authority).getTenantId() : null; if (name.equals(recipient.getRoleName()) && (tenantId == recipient.getTenantId() || (tenantId != null && tenantId.equals(recipient.getTenantId())))){ res = true; break; } } } return res; }  @Override boolean supports(ConfigAttribute attribute);  }### Answer:
@Test public void testSupports_user() throws Exception { assertTrue(voter.isPermitted(authentication, permission, object)); }
@Test public void testSupports_role() throws Exception { permission.setPermissionRecipient(role); assertTrue(voter.isPermitted(authentication, permission, object)); }
@Test public void testSupports_wrongUser() throws Exception { user.setUsername("Ulazlo"); assertFalse(voter.isPermitted(authentication, permission, object)); }
@Test public void testSupports_wrongRole() throws Exception { permission.setPermissionRecipient(role); role.setRoleName("afsdasf"); assertFalse(voter.isPermitted(authentication, permission, object)); }
@Test public void testSupports_wrongUserTenant() throws Exception { user.setTenantId("Ulazlo"); assertFalse(voter.isPermitted(authentication, permission, object)); }
@Test public void testSupports_wrongRoleTenant() throws Exception { permission.setPermissionRecipient(role); role.setTenantId("afsdasf"); assertFalse(voter.isPermitted(authentication, permission, object)); }