JsonEnvelopeRepacker { public JsonEnvelope repack(final Envelope<JsonValue> envelope) { if(envelope == null) { return null; } if(JsonEnvelope.class.isAssignableFrom(envelope.getClass())) { return (JsonEnvelope) envelope; } return JsonEnvelope.envelopeFrom(envelope.metadata(), (JsonValue) envelope.payload()); }  JsonEnvelope repack(final Envelope<JsonValue> envelope);  }
@SuppressWarnings("unchecked") @Test public void shouldConvertJsonValueEnvelopeToJsonEnvelope() throws JsonProcessingException { final Envelope<JsonValue> envelope = mock(Envelope.class); final JsonEnvelopeRepacker jsonEnvelopeRepacker = new JsonEnvelopeRepacker(); final JsonEnvelope jsonEnvelope = jsonEnvelopeRepacker.repack(envelope); assertThat(jsonEnvelope, isA(JsonEnvelope.class)); }
@Test public void shouldHandleJsonEnvelope() throws JsonProcessingException { final Envelope<JsonValue> envelope = mock(JsonEnvelope.class); final JsonEnvelopeRepacker jsonEnvelopeRepacker = new JsonEnvelopeRepacker(); final JsonEnvelope jsonEnvelope = jsonEnvelopeRepacker.repack(envelope); assertThat(envelope, is(sameInstance(jsonEnvelope))); }