WhoamiResponse extends CommonCommandResponse<WhoamiResponse> implements WithEntity<WhoamiResponse> { @Override public WhoamiResponse setEntity(final JsonValue entity) { checkNotNull(entity, "entity"); return new WhoamiResponse(entity.asObject(), getDittoHeaders()); } private  WhoamiResponse(final JsonObject userInformation, final DittoHeaders dittoHeaders); static WhoamiResponse of(final UserInformation userInformation, final DittoHeaders dittoHeaders); static WhoamiResponse fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders); @Override WhoamiResponse setDittoHeaders(final DittoHeaders dittoHeaders); @Override WhoamiResponse setEntity(final JsonValue entity); @Override JsonValue getEntity(final JsonSchemaVersion schemaVersion); @Override boolean equals(@Nullable final Object o); @Override int hashCode(); @Override @Nonnull String toString(); @Override @Nonnull JsonSchemaVersion[] getSupportedSchemaVersions(); static final String TYPE; }
@Test public void setEntity() { final UserInformation otherUserInformation = DefaultUserInformation.fromAuthorizationContext( AuthorizationContext.newInstance(DittoAuthorizationContextType.UNSPECIFIED, AuthorizationSubject.newInstance(OTHER_SUBJECT))); final JsonValue expectedEntity = otherUserInformation.toJson(); final WhoamiResponse originalResponse = WhoamiResponse.of(USER_INFORMATION, DITTO_HEADERS); final WhoamiResponse responseWithNewEntity = originalResponse.setEntity(expectedEntity); final JsonValue newEntity = responseWithNewEntity.getEntity(JsonSchemaVersion.LATEST); assertThat(newEntity).isEqualTo(expectedEntity); }