ShutteringStoreSender implements EnvelopeSender { public void send(final JsonEnvelope command, final String destinationName) { final UUID envelopeId = command.metadata().id(); final String commandJson = jsonObjectEnvelopeConverter.asJsonString(command); final StoredCommand storedCommand = new StoredCommand( envelopeId, commandJson, destinationName, clock.now()); storedCommandRepository.save(storedCommand); }  void send(final JsonEnvelope command, final String destinationName);  }
@Test public void shouldConvertToShutteredCommandAndSave() throws Exception { final String destinationName = "destinationName"; final String envelopeJson = "envelope json"; final ZonedDateTime now = new UtcClock().now(); final UUID envelopeId = randomUUID(); final JsonEnvelope command = mock(JsonEnvelope.class); final Metadata metadata = mock(Metadata.class); when(command.metadata()).thenReturn(metadata); when(metadata.id()).thenReturn(envelopeId); when(jsonObjectEnvelopeConverter.asJsonString(command)).thenReturn(envelopeJson); when(clock.now()).thenReturn(now); shutteringStoreSender.send(command, destinationName); verify(storedCommandRepository).save(shutteredCommandCaptor.capture()); final StoredCommand storedCommand = shutteredCommandCaptor.getValue(); assertThat(storedCommand.getEnvelopeId(), is(envelopeId)); assertThat(storedCommand.getCommandJsonEnvelope(), is(envelopeJson)); assertThat(storedCommand.getDestination(), is(destinationName)); assertThat(storedCommand.getDateReceived(), is(now)); }