ImmutableAuthorizationContext implements AuthorizationContext { @Override public AuthorizationContext addHead(final List<AuthorizationSubject> authorizationSubjects) { checkNotNull(authorizationSubjects, "authorizationSubjects"); final List<AuthorizationSubject> newAuthorizationSubjects = new ArrayList<>(this.authorizationSubjects.size() + authorizationSubjects.size()); newAuthorizationSubjects.addAll(authorizationSubjects); newAuthorizationSubjects.addAll(this.authorizationSubjects); return new ImmutableAuthorizationContext(type, newAuthorizationSubjects); } private  ImmutableAuthorizationContext(final AuthorizationContextType type,
            final List<AuthorizationSubject> authorizationSubjects); static ImmutableAuthorizationContext of(final AuthorizationContextType type,
            final List<AuthorizationSubject> authorizationSubjects); static ImmutableAuthorizationContext of(final AuthorizationContextType type,
            final AuthorizationSubject authorizationSubject,
            final AuthorizationSubject... furtherAuthorizationSubjects); static ImmutableAuthorizationContext fromJson(final JsonObject jsonObject); @Override AuthorizationContextType getType(); @Override List<AuthorizationSubject> getAuthorizationSubjects(); @Override List<String> getAuthorizationSubjectIds(); @Override Optional<AuthorizationSubject> getFirstAuthorizationSubject(); @Override int getSize(); @Override boolean isEmpty(); @Override AuthorizationContext addHead(final List<AuthorizationSubject> authorizationSubjects); @Override AuthorizationContext addTail(final List<AuthorizationSubject> authorizationSubjects); @Override boolean isAuthorized(final Collection<AuthorizationSubject> granted,
            final Collection<AuthorizationSubject> revoked); @Override JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate); @Override Iterator<AuthorizationSubject> iterator(); @Override Stream<AuthorizationSubject> stream(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }
@Test public void addHead() { final ImmutableAuthorizationContext initialContext = ImmutableAuthorizationContext.of(KNOWN_TYPE, SUBJECTS_1); final AuthorizationContext newContext = initialContext.addHead(SUBJECTS_2); final List<AuthorizationSubject> expectedAuthSubjects = Lists.newArrayList(SUBJECTS_2); expectedAuthSubjects.addAll(SUBJECTS_1); final ImmutableAuthorizationContext expectedContext = ImmutableAuthorizationContext.of(KNOWN_TYPE, expectedAuthSubjects); assertThat(newContext).isEqualTo(expectedContext); }