Skip to content

Instantly share code, notes, and snippets.

@rlindooren
Created November 26, 2023 14:16
Show Gist options
  • Save rlindooren/56c71f726affae115787b6d4adc5ccc3 to your computer and use it in GitHub Desktop.
Save rlindooren/56c71f726affae115787b6d4adc5ccc3 to your computer and use it in GitHub Desktop.
AssertJ field by field comparison for ProtoBuf messages ignoring dynamic fields (gRPC)
public <T> ListAssert<T> createAssertionIgnoringCreatedAndModifiedDateFields(List<T> protoMessages) {
return assertThat(protoMessages)
.usingRecursiveFieldByFieldElementComparatorIgnoringFields(
// Ignore fields that are "dynamical" during a test
"createdOn_",
"lastModifiedOn_",
// And also additionally ignore some ProtoBuf 'special fields'
// which otherwise cause the assertion to fail because they are included due to the field-by-field comparison
"memoizedHashCode",
"memoizedIsInitialized");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment