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 7bed5b7
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,33 @@ public void testComparingExpectedFieldsOnly() {

expectFailureWhenTesting()
.that(message)
.unpackingAnyUsing(getTypeRegistry(), getExtensionRegistry())
.comparingExpectedFieldsOnly()
.isNotEqualTo(narrowMessage);
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 7bed5b7

Please sign in to comment.