DefaultUserInformation implements UserInformation { public static DefaultUserInformation fromAuthorizationContext(final AuthorizationContext context) { checkNotNull(context, "context"); @Nullable final String defaultSubject = context.getFirstAuthorizationSubject().map(AuthorizationSubject::getId).orElse(null); final List<String> subjects = context.getAuthorizationSubjects() .stream() .map(AuthorizationSubject::getId) .collect(Collectors.toList()); return new DefaultUserInformation(defaultSubject, subjects); } private  DefaultUserInformation(@Nullable final String defaultSubject,
            final List<String> subjects); static DefaultUserInformation fromAuthorizationContext(final AuthorizationContext context); static DefaultUserInformation fromJson(final JsonObject jsonObject); @Override Optional<String> getDefaultSubject(); @Override List<String> getSubjects(); @Override JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> predicate); @Override boolean equals(@Nullable final Object o); @Override int hashCode(); @Override String toString();  }
@Test public void fromAuthorizationContext() { final String defaultSubjectId = "google:i-am-user"; final AuthorizationSubject defaultSubject = AuthorizationSubject.newInstance(defaultSubjectId); final String otherSubjectId = "eclipse:i-am-not-google"; final AuthorizationSubject otherSubject = AuthorizationSubject.newInstance(otherSubjectId); final AuthorizationContext authorizationContext = AuthorizationContext.newInstance( DittoAuthorizationContextType.UNSPECIFIED, defaultSubject, otherSubject); final DefaultUserInformation userInformation = DefaultUserInformation.fromAuthorizationContext(authorizationContext); assertThat(userInformation.getDefaultSubject()).contains(defaultSubjectId); assertThat(userInformation.getSubjects()).containsExactly(defaultSubjectId, otherSubjectId); }
@Test public void fromAuthorizationContextThrowsOnNull() { assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> DefaultUserInformation.fromAuthorizationContext(null)); }