EnvelopeInspector { public Metadata getMetadataFor(final JsonEnvelope jsonEnvelope) { final Metadata metadata = jsonEnvelope.metadata(); if (metadata != null) { return metadata; } throw new EnvelopeValidationException("Metadata not set in the envelope."); }  String getActionNameFor(final JsonEnvelope jsonEnvelope); Metadata getMetadataFor(final JsonEnvelope jsonEnvelope);  }
@Test public void shouldGetTheMetadataOfAnEnvelope() throws Exception { final JsonEnvelope jsonEnvelope = mock(JsonEnvelope.class); final Metadata metadata = mock(Metadata.class); when(jsonEnvelope.metadata()).thenReturn(metadata); assertThat(envelopeInspector.getMetadataFor(jsonEnvelope), is(metadata)); }
@Test public void shouldThrowValidationExceptionIfTheJsonEnvelopeContainsNoMetadata() throws Exception { final JsonEnvelope jsonEnvelope = mock(JsonEnvelope.class); when(jsonEnvelope.metadata()).thenReturn(null); try { envelopeInspector.getMetadataFor(jsonEnvelope); fail(); } catch (final EnvelopeValidationException expected) { assertThat(expected.getMessage(), is("Metadata not set in the envelope.")); } }