Skip to content

Commit c957a44

Browse files
committed
test: remove tautological hashCode assertions and use idiomatic isEqualTo
- Remove self-comparing hashCode assertions (always true) - Use assertThat(options).isEqualTo(options2) instead of assertThat(options.equals(options2)).isTrue() for better error messages
1 parent 0965e96 commit c957a44

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

  • java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner

java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OptionsTest.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,10 @@ public void allOptionsAbsent() {
152152
assertThat(options.equals(null)).isFalse();
153153
assertThat(options.equals(this)).isFalse();
154154
assertNull(options.isolationLevel());
155-
// Verify hashCode contract: equal objects must have equal hashCodes, and hashCode is stable.
155+
// Verify hashCode contract: equal objects must have equal hashCodes.
156156
Options options2 = Options.fromReadOptions();
157-
assertThat(options.equals(options2)).isTrue();
157+
assertThat(options).isEqualTo(options2);
158158
assertThat(options.hashCode()).isEqualTo(options2.hashCode());
159-
assertThat(options.hashCode()).isEqualTo(options.hashCode());
160159
}
161160

162161
@Test
@@ -179,13 +178,12 @@ public void listOptionsTest() {
179178
assertThat(options.pageSize()).isEqualTo(pageSize);
180179
assertThat(options.pageToken()).isEqualTo(pageToken);
181180
assertThat(options.filter()).isEqualTo(filter);
182-
// Verify hashCode contract: equal objects must have equal hashCodes, and hashCode is stable.
181+
// Verify hashCode contract: equal objects must have equal hashCodes.
183182
Options options2 =
184183
Options.fromListOptions(
185184
Options.pageSize(pageSize), Options.pageToken(pageToken), Options.filter(filter));
186-
assertThat(options.equals(options2)).isTrue();
185+
assertThat(options).isEqualTo(options2);
187186
assertThat(options.hashCode()).isEqualTo(options2.hashCode());
188-
assertThat(options.hashCode()).isEqualTo(options.hashCode());
189187
}
190188

191189
@Test
@@ -706,11 +704,10 @@ public void updateOptionsTest() {
706704
assertEquals("tag: " + tag + " ", options.toString());
707705
assertTrue(options.hasTag());
708706
assertThat(options.tag()).isEqualTo(tag);
709-
// Verify hashCode contract: equal objects must have equal hashCodes, and hashCode is stable.
707+
// Verify hashCode contract: equal objects must have equal hashCodes.
710708
Options options2 = Options.fromUpdateOptions(Options.tag(tag));
711-
assertThat(options.equals(options2)).isTrue();
709+
assertThat(options).isEqualTo(options2);
712710
assertThat(options.hashCode()).isEqualTo(options2.hashCode());
713-
assertThat(options.hashCode()).isEqualTo(options.hashCode());
714711
}
715712

716713
@Test
@@ -742,11 +739,10 @@ public void transactionOptionsTest() {
742739
assertEquals("tag: " + tag + " ", options.toString());
743740
assertTrue(options.hasTag());
744741
assertThat(options.tag()).isEqualTo(tag);
745-
// Verify hashCode contract: equal objects must have equal hashCodes, and hashCode is stable.
742+
// Verify hashCode contract: equal objects must have equal hashCodes.
746743
Options options2 = Options.fromTransactionOptions(Options.tag(tag));
747-
assertThat(options.equals(options2)).isTrue();
744+
assertThat(options).isEqualTo(options2);
748745
assertThat(options.hashCode()).isEqualTo(options2.hashCode());
749-
assertThat(options.hashCode()).isEqualTo(options.hashCode());
750746
}
751747

752748
@Test

0 commit comments

Comments
 (0)