protected boolean matchesSafely()

in pojo/src/main/java/com/spotify/hamcrest/pojo/IsPojo.java [128:151]


  protected boolean matchesSafely(A item, Description mismatchDescription) {
    if (!cls().isInstance(item)) {
      mismatchDescription.appendText("not an instance of " + cls().getName());
      return false;
    }

    final Map<String, Consumer<Description>> mismatches = new LinkedHashMap<>();

    methodHandlers()
        .forEach(
            (methodName, handler) ->
                matchMethod(item, handler)
                    .ifPresent(
                        descriptionConsumer -> mismatches.put(methodName, descriptionConsumer)));

    if (!mismatches.isEmpty()) {
      mismatchDescription.appendText(cls().getSimpleName()).appendText(" ");
      DescriptionUtils.describeNestedMismatches(
          methodHandlers().keySet(), mismatchDescription, mismatches, IsPojo::describeMethod);
      return false;
    }

    return true;
  }