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 18, 2024
1 parent a3a94ee commit 0dd8a4c
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,27 @@ 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).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 0dd8a4c

Please sign in to comment.