### Question:
NotPermissionOwnerPermissionArgumentVoter extends BasicObjectPermissionArgumentVoter { @Override protected boolean isPermitted(Authentication authentication, ObjectPermission objectPermission, Object object) { User user = (User)authentication.getPrincipal(); boolean res = true; if (objectPermission.getPermissionRecipient() instanceof User){ User recipient = (User)objectPermission.getPermissionRecipient(); res = !((recipient.getUsername() == user.getUsername() || recipient.getUsername().equals(user.getUsername())) && (recipient.getTenantId() == user.getTenantId() || recipient.getTenantId().equals(user.getTenantId()))); } return res; }  @Override boolean supports(ConfigAttribute attribute);  }### Answer:
@Test public void testSupports_sameUser() throws Exception { List<GrantedAuthority> authorityList = new ArrayList<GrantedAuthority>(1); authorityList.add(new SimpleGrantedAuthority("SSS")); authentication = new UsernamePasswordAuthenticationToken(user, user, authorityList); assertFalse(voter.isPermitted(authentication, permission, object)); }
@Test public void testSupports_sameName() throws Exception { user.setTenantId("lala"); List<GrantedAuthority> authorityList = new ArrayList<GrantedAuthority>(1); authorityList.add(new SimpleGrantedAuthority("SSS")); authentication = new UsernamePasswordAuthenticationToken(user, user, authorityList); assertTrue(voter.isPermitted(authentication, permission, object)); }
@Test public void testSupports_sameTenant() throws Exception { user.setUsername("lala"); List<GrantedAuthority> authorityList = new ArrayList<GrantedAuthority>(1); authorityList.add(new SimpleGrantedAuthority("SSS")); authentication = new UsernamePasswordAuthenticationToken(user, user, authorityList); assertTrue(voter.isPermitted(authentication, permission, object)); }
@Test public void testSupports_justName() throws Exception { user.setTenantId(null); List<GrantedAuthority> authorityList = new ArrayList<GrantedAuthority>(1); authorityList.add(new SimpleGrantedAuthority("SSS")); authentication = new UsernamePasswordAuthenticationToken(user, user, authorityList); assertTrue(voter.isPermitted(authentication, permission, object)); }