@Override protected boolean matchesSafely(final Metadata metadata, final Description description) { if (idIsSetAndDoesNotMatchWith(metadata)) { description.appendText("Metadata with id = " + metadata.id()); return false; } if (nameIsSetAndDoesNotMatchWith(metadata)) { description.appendText("Metadata with name = " + metadata.name()); return false; } if (causationIdsDoNotMatchWith(metadata)) { description.appendText("Metadata with causationIds = " + metadata.causation()); return false; } if (userIdIsSetAndDoesNotMatchWith(metadata)) { description.appendText("Metadata with userId = " + metadata.userId().orElse(NOT_SET)); return false; } if (sessionIdIsSetAndDoesNotMatchWith(metadata)) { description.appendText("Metadata with sessionId = " + metadata.sessionId().orElse(NOT_SET)); return false; } if (streamIdIsSetAndDoesNotMatchWith(metadata)) { description.appendText( "Metadata with streamId = " + metadata.streamId().map(UUID::toString).orElse(NOT_SET)); return false; } if (versionIsSetAndDoesNotMatchWith(metadata)) { description.appendText( "Metadata with version = " + metadata.version().map(String::valueOf).orElse(NOT_SET)); return false; } if (clientCorrelationIdIsSetAndDoesNotMatchWith(metadata)) { description.appendText( "Metadata with clientCorrelationId = " + metadata.clientCorrelationId().map(String::valueOf).orElse(NOT_SET)); return false; } if (jsonMatcherIsSetAndDoesNotMatchWith(metadata)) { description.appendText("Metadata "); jsonMatcher.ifPresent( matcher -> matcher.describeMismatch(metadata.asJsonObject().toString(), description)); return false; } return true; }
private boolean clientCorrelationIdIsSetAndDoesNotMatchWith(final Metadata metadata) { return clientCorrelationId.isPresent() && !clientCorrelationId.equals(metadata.clientCorrelationId()); }