Skip to content

Commit

Permalink
Test that comparingExpectedFieldsOnly is effective on nested Any
Browse files Browse the repository at this point in the history
…values.

PiperOrigin-RevId: 680553503
  • Loading branch information
java-team-github-bot authored and Google Java Core Libraries committed Oct 21, 2024
1 parent a3a94ee commit c021bf9
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'");
Expand Down

0 comments on commit c021bf9

Please sign in to comment.