public static FieldScope fromSetFields(Message message) {
    return fromSetFields(
        message, AnyUtils.defaultTypeRegistry(), AnyUtils.defaultExtensionRegistry());
  }
@Test
  public void testFromSetFields() {
    Message scopeMessage =
        parse(
            "o_int: 1 r_string: \"x\" o_test_message: { o_int: 1 } "
                + "r_test_message: { r_string: \"x\" } r_test_message: { o_int: 1 } "
                + "o_sub_test_message: { o_test_message: { o_int: 1 } }");

    // 1 = compared, [2, 3] = ignored, 4 = compared and fails
    Message message =
        parse(
            "o_int: 1 r_string: \"1\" o_test_message: {o_int: 1 r_string: \"2\" } "
                + "r_test_message: { o_int: 1 r_string: \"1\" } "
                + "r_test_message: { o_int: 1 r_string: \"1\" } "
                + "o_sub_test_message: { o_int: 2 o_test_message: { o_int: 1 r_string: \"2\" } }");
    Message diffMessage =
        parse(
            "o_int: 4 r_string: \"4\" o_test_message: {o_int: 4 r_string: \"3\" } "
                + "r_test_message: { o_int: 4 r_string: \"4\" } "
                + "r_test_message: { o_int: 4 r_string: \"4\" }"
                + "o_sub_test_message: { r_string: \"3\" o_int: 3 "
                + "o_test_message: { o_int: 4 r_string: \"3\" } }");
    Message eqMessage =
        parse(
            "o_int: 1 r_string: \"1\" o_test_message: {o_int: 1 r_string: \"3\" } "
                + "r_test_message: { o_int: 1 r_string: \"1\" } "
                + "r_test_message: { o_int: 1 r_string: \"1\" }"
                + "o_sub_test_message: { o_int: 3 o_test_message: { o_int: 1 r_string: \"3\" } }");

    expectThat(diffMessage).isNotEqualTo(message);
    expectThat(eqMessage).isNotEqualTo(message);

    expectThat(diffMessage)
        .withPartialScope(FieldScopes.fromSetFields(scopeMessage))
        .isNotEqualTo(message);
    expectThat(eqMessage)
        .withPartialScope(FieldScopes.fromSetFields(scopeMessage))
        .isEqualTo(message);

    expectFailureWhenTesting().that(diffMessage).isEqualTo(message);
    expectIsEqualToFailed();
    expectThatFailure().hasMessageThat().contains("1 -> 4");
    expectThatFailure().hasMessageThat().contains("\"1\" -> \"4\"");
    expectThatFailure().hasMessageThat().contains("2 -> 3");
    expectThatFailure().hasMessageThat().contains("\"2\" -> \"3\"");

    expectFailureWhenTesting()
        .that(diffMessage)
        .withPartialScope(FieldScopes.fromSetFields(scopeMessage))
        .isEqualTo(message);
    expectIsEqualToFailed();
    expectThatFailure().hasMessageThat().contains("1 -> 4");
    expectThatFailure().hasMessageThat().contains("\"1\" -> \"4\"");
    expectThatFailure().hasMessageThat().doesNotContain("2 -> 3");
    expectThatFailure().hasMessageThat().doesNotContain("\"2\" -> \"3\"");

    expectFailureWhenTesting()
        .that(eqMessage)
        .withPartialScope(FieldScopes.fromSetFields(scopeMessage))
        .isNotEqualTo(message);
    expectIsNotEqualToFailed();
    expectThatFailure().hasMessageThat().contains("ignored: o_test_message.r_string");
    expectThatFailure().hasMessageThat().contains("ignored: o_sub_test_message.o_int");
    expectThatFailure()
        .hasMessageThat()
        .contains("ignored: o_sub_test_message.o_test_message.r_string");
  }