-
Notifications
You must be signed in to change notification settings - Fork 1.1k
test(spanner): replace fixed hashCode value assertions with contract-compliance tests in OptionsTest #12901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
test(spanner): replace fixed hashCode value assertions with contract-compliance tests in OptionsTest #12901
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -152,7 +152,11 @@ public void allOptionsAbsent() { | |||||||||||||||||||||||||||
| assertThat(options.equals(null)).isFalse(); | ||||||||||||||||||||||||||||
| assertThat(options.equals(this)).isFalse(); | ||||||||||||||||||||||||||||
| assertNull(options.isolationLevel()); | ||||||||||||||||||||||||||||
| assertThat(options.hashCode()).isEqualTo(31); | ||||||||||||||||||||||||||||
| // Verify hashCode contract: equal objects must have equal hashCodes, and hashCode is stable. | ||||||||||||||||||||||||||||
| Options options2 = Options.fromReadOptions(); | ||||||||||||||||||||||||||||
| assertThat(options.equals(options2)).isTrue(); | ||||||||||||||||||||||||||||
| assertThat(options.hashCode()).isEqualTo(options2.hashCode()); | ||||||||||||||||||||||||||||
| assertThat(options.hashCode()).isEqualTo(options.hashCode()); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||
|
|
@@ -175,7 +179,13 @@ public void listOptionsTest() { | |||||||||||||||||||||||||||
| assertThat(options.pageSize()).isEqualTo(pageSize); | ||||||||||||||||||||||||||||
| assertThat(options.pageToken()).isEqualTo(pageToken); | ||||||||||||||||||||||||||||
| assertThat(options.filter()).isEqualTo(filter); | ||||||||||||||||||||||||||||
| assertThat(options.hashCode()).isEqualTo(108027089); | ||||||||||||||||||||||||||||
| // Verify hashCode contract: equal objects must have equal hashCodes, and hashCode is stable. | ||||||||||||||||||||||||||||
| Options options2 = | ||||||||||||||||||||||||||||
| Options.fromListOptions( | ||||||||||||||||||||||||||||
| Options.pageSize(pageSize), Options.pageToken(pageToken), Options.filter(filter)); | ||||||||||||||||||||||||||||
| assertThat(options.equals(options2)).isTrue(); | ||||||||||||||||||||||||||||
| assertThat(options.hashCode()).isEqualTo(options2.hashCode()); | ||||||||||||||||||||||||||||
| assertThat(options.hashCode()).isEqualTo(options.hashCode()); | ||||||||||||||||||||||||||||
|
Comment on lines
+182
to
+188
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The assertion assertThat(options.hashCode()).isEqualTo(options.hashCode()) is a tautology and provides little value in a unit test for a value-like object. Additionally, using assertThat(options).isEqualTo(options2) is more idiomatic and provides better failure messages than assertThat(options.equals(options2)).isTrue().
Suggested change
|
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||
|
|
@@ -696,7 +706,11 @@ public void updateOptionsTest() { | |||||||||||||||||||||||||||
| assertEquals("tag: " + tag + " ", options.toString()); | ||||||||||||||||||||||||||||
| assertTrue(options.hasTag()); | ||||||||||||||||||||||||||||
| assertThat(options.tag()).isEqualTo(tag); | ||||||||||||||||||||||||||||
| assertThat(options.hashCode()).isEqualTo(-2118248262); | ||||||||||||||||||||||||||||
| // Verify hashCode contract: equal objects must have equal hashCodes, and hashCode is stable. | ||||||||||||||||||||||||||||
| Options options2 = Options.fromUpdateOptions(Options.tag(tag)); | ||||||||||||||||||||||||||||
| assertThat(options.equals(options2)).isTrue(); | ||||||||||||||||||||||||||||
| assertThat(options.hashCode()).isEqualTo(options2.hashCode()); | ||||||||||||||||||||||||||||
| assertThat(options.hashCode()).isEqualTo(options.hashCode()); | ||||||||||||||||||||||||||||
|
Comment on lines
+709
to
+713
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The assertion assertThat(options.hashCode()).isEqualTo(options.hashCode()) is a tautology and provides little value in a unit test for a value-like object. Additionally, using assertThat(options).isEqualTo(options2) is more idiomatic and provides better failure messages than assertThat(options.equals(options2)).isTrue().
Suggested change
|
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||
|
|
@@ -728,7 +742,11 @@ public void transactionOptionsTest() { | |||||||||||||||||||||||||||
| assertEquals("tag: " + tag + " ", options.toString()); | ||||||||||||||||||||||||||||
| assertTrue(options.hasTag()); | ||||||||||||||||||||||||||||
| assertThat(options.tag()).isEqualTo(tag); | ||||||||||||||||||||||||||||
| assertThat(options.hashCode()).isEqualTo(-2118248262); | ||||||||||||||||||||||||||||
| // Verify hashCode contract: equal objects must have equal hashCodes, and hashCode is stable. | ||||||||||||||||||||||||||||
| Options options2 = Options.fromTransactionOptions(Options.tag(tag)); | ||||||||||||||||||||||||||||
| assertThat(options.equals(options2)).isTrue(); | ||||||||||||||||||||||||||||
| assertThat(options.hashCode()).isEqualTo(options2.hashCode()); | ||||||||||||||||||||||||||||
| assertThat(options.hashCode()).isEqualTo(options.hashCode()); | ||||||||||||||||||||||||||||
|
Comment on lines
+745
to
+749
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The assertion assertThat(options.hashCode()).isEqualTo(options.hashCode()) is a tautology and provides little value in a unit test for a value-like object. Additionally, using assertThat(options).isEqualTo(options2) is more idiomatic and provides better failure messages than assertThat(options.equals(options2)).isTrue().
Suggested change
|
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertion assertThat(options.hashCode()).isEqualTo(options.hashCode()) is a tautology and provides little value in a unit test for a value-like object. Additionally, using assertThat(options).isEqualTo(options2) is more idiomatic and provides better failure messages than assertThat(options.equals(options2)).isTrue().