PersonalAccountPermissionsChecker implements AccountPermissionsChecker { @Override public void checkPermissions(String id, AccountOperation operation) throws ForbiddenException { if (!EnvironmentContext.getCurrent().getSubject().getUserId().equals(id)) { throw new ForbiddenException("User is not authorized to use specified account"); } }  @Override void checkPermissions(String id, AccountOperation operation); @Override String getAccountType();  }
@Test public void shouldNotThrowExceptionWhenUserIdFromSubjectEqualsToSpecifiedAccountId() throws Exception { permissionsChecker.checkPermissions(userId, null); }
@Test( expectedExceptions = ForbiddenException.class, expectedExceptionsMessageRegExp = "User is not authorized to use specified account") public void shouldThrowForbiddenExceptionWhenUserIdFromSubjectDoesNotEqualToSpecifiedAccountId() throws Exception { permissionsChecker.checkPermissions("anotherUserId", null); }