@Test
public void shouldReturnEnvelopeWithSystemUserId() throws Exception {

    final UUID sysUserId = randomUUID();
    when(systemUserProvider.getContextSystemUserId()).thenReturn(Optional.of(sysUserId));
    final UUID id = randomUUID();
    final String name = "name456";
    final JsonEnvelope returnedEnvelope = systemUserUtil.asEnvelopeWithSystemUserId(
            envelopeFrom(metadataBuilder()
                            .withId(id)
                            .withName(name)
                            .withUserId("someIdToBeReplaced"),
                    createObjectBuilder().add("numName", BigDecimal.valueOf(123)))
    );
    assertThat(returnedEnvelope.metadata().id(), is(id));
    assertThat(returnedEnvelope.metadata().name(), is(name));
    assertThat(returnedEnvelope.metadata().userId(), contains(sysUserId.toString()));
    assertThat(returnedEnvelope.payloadAsJsonObject().getInt("numName"), is(123));
}