PayloadExtractor { public JSONObject extractPayloadFrom(final String envelopeJson) { final JSONObject jsonObject = new JSONObject(envelopeJson); jsonObject.remove(METADATA); return jsonObject; }  JSONObject extractPayloadFrom(final String envelopeJson);  }
@Test public void shouldRemoveTheMetadataFromAnEnvelopeJsonStringAndConvertToJsonObject() throws Exception { final UUID streamId = randomUUID(); final String commandName = "time-travel-initiated"; final JsonEnvelope jsonEnvelope = envelopeFrom(metadataBuilder() .withId(randomUUID()) .withStreamId(streamId) .withName(commandName), createObjectBuilder() .add("destination", "Jurassic Era")); final String envelopeJson = jsonEnvelope.toDebugStringPrettyPrint(); final JSONObject jsonObject = payloadExtractor.extractPayloadFrom(envelopeJson); final String json = jsonObject.toString(); with(json) .assertThat("$.destination", is("Jurassic Era")) .assertNotDefined(METADATA) ; }