O2Principal implements Principal { protected <T extends AbstractEntity> T sameOrOne(final T left, final T right) { if (left == null) { return right; } if (right == null) { return left; } if (!left.equals(right)) { throw new AccessDeniedException(); } return left; } O2Principal();  O2Principal(final Client client);  O2Principal(final OAuthToken token); private  O2Principal(final Client client, final OAuthToken token); OAuthToken getOAuthToken(); @Override String getName(); @Override boolean implies(final Subject subject); String getScheme(); Client getContext(); O2Principal merge(final Principal newPrincipal); @Override boolean equals(final Object o); @Override int hashCode();  }
@Test public void testSameOrOne() { O2Principal p = new O2Principal(); Client left = new Client(); left.setId(IdUtil.next()); Client right = new Client(); right.setId(left.getId()); assertEquals(left, p.sameOrOne(left, null)); assertEquals(right, p.sameOrOne(null, right)); assertEquals(left, p.sameOrOne(left, right)); }
@Test(expected = AccessDeniedException.class) public void testSameOrOneFail() { O2Principal p = new O2Principal(); Client left = new Client(); left.setId(IdUtil.next()); Client right = new Client(); right.setId(IdUtil.next()); p.sameOrOne(left, right); }