diff --git a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTest.java b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTest.java index c9eb636b4..53628dfe1 100644 --- a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTest.java +++ b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTest.java @@ -555,6 +555,30 @@ public void testComparingExpectedFieldsOnly() { expectThatFailure().hasMessageThat().contains("ignored: r_string"); } + @Test + public void testComparingExpectedFieldsOnly_anyMessage() { + String typeUrl = + isProto3() + ? "type.googleapis.com/com.google.common.truth.extensions.proto.SubTestMessage3" + : "type.googleapis.com/com.google.common.truth.extensions.proto.SubTestMessage2"; + + Message message = parse("o_any_message: { [" + typeUrl + "]: {r_string: \"foo\"} }"); + Message diffMessage = + parse("o_any_message: { [" + typeUrl + "]: {o_int: 3 r_string: \"foo\"} }"); + + expectThat(diffMessage) + .unpackingAnyUsing(getTypeRegistry(), getExtensionRegistry()) + .comparingExpectedFieldsOnly() + .isEqualTo(message); + + expectFailureWhenTesting().that(message).comparingExpectedFieldsOnly().isEqualTo(diffMessage); + if (isProto3()) { + expectThatFailure().hasMessageThat().contains("modified: o_any_message.value.o_int: 3 -> 0"); + } else { + expectThatFailure().hasMessageThat().contains("deleted: o_any_message.value.o_int: 3"); + } + } + @Test public void testIgnoringExtraRepeatedFieldElements_respectingOrder() { Message message = parse("r_string: 'foo' r_string: 'bar'");