Created
November 26, 2023 14:16
-
-
Save rlindooren/56c71f726affae115787b6d4adc5ccc3 to your computer and use it in GitHub Desktop.
AssertJ field by field comparison for ProtoBuf messages ignoring dynamic fields (gRPC)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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