AccessControlFailureMessageGenerator { public String errorMessageFrom( final JsonEnvelope jsonEnvelope, final AccessControlViolation accessControlViolation) { return format("Access Control failed for json envelope '%s' of type '%s'. Reason: %s", jsonEnvelope.metadata().id(), jsonEnvelope.metadata().name(), accessControlViolation.getReason()); }  String errorMessageFrom(
                    final JsonEnvelope jsonEnvelope,
                    final AccessControlViolation accessControlViolation);  }
@Test public void shouldGenerateAnErrorMessageWithEnvelopeIdAndEnvelopeNameAndFailureReasonAndNoUserId() throws Exception { final String reason = "reason"; final AccessControlViolation accessControlViolation = new AccessControlViolation(reason); final Metadata metadata = mock(Metadata.class); final JsonEnvelope jsonEnvelope = mock(JsonEnvelope.class); when(jsonEnvelope.metadata()).thenReturn(metadata); when(metadata.id()).thenReturn(fromString("9132d439-c797-4483-a961-5eb640c55fe7")); when(metadata.name()).thenReturn("sjp.query.cases-referred-to-court"); final String errorMessage = accessControlFailureMessageGenerator .errorMessageFrom(jsonEnvelope, accessControlViolation); assertThat(errorMessage, is("Access Control failed for json envelope '9132d439-c797-4483-a961-5eb640c55fe7' of type 'sjp.query.cases-referred-to-court'. Reason: reason")); verify(metadata, times(0)).userId(); }