DispatcherDelegate implements Requester, Sender { @Override public void send(final Envelope<?> envelope) { final JsonEnvelope jsonEnvelope = convertAndRepackEnvelope().apply(envelope); requestResponseEnvelopeValidator.validateRequest(jsonEnvelope); dispatch().apply(jsonEnvelope); } DispatcherDelegate(final Dispatcher dispatcher,
                              final SystemUserUtil systemUserUtil,
                              final RequestResponseEnvelopeValidator requestResponseEnvelopeValidator,
                              final EnvelopePayloadTypeConverter envelopePayloadTypeConverter,
                              final JsonEnvelopeRepacker jsonEnvelopeRepacker); @Override JsonEnvelope request(final Envelope<?> envelope); @Override Envelope<T> request(final Envelope<?> envelope, final Class<T> clazz); @Override JsonEnvelope requestAsAdmin(final JsonEnvelope envelope); @Override Envelope<T> requestAsAdmin(final Envelope<?> envelope, final Class<T> clazz); @Override void send(final Envelope<?> envelope); @Override void sendAsAdmin(final JsonEnvelope envelope); @Override void sendAsAdmin(final Envelope<?> envelope);  }
@Test public void shouldValidateEnvelopeWithSendMethod() throws Exception { final JsonEnvelope envelope = mock(JsonEnvelope.class); when(envelopePayloadTypeConverter.convert(any(Envelope.class), eq(JsonValue.class))) .thenReturn(envelope); when(jsonEnvelopeRepacker.repack(envelope)).thenReturn(envelope); dispatcherDelegate.send(envelope); verify(requestResponseEnvelopeValidator).validateRequest(envelope); }