Skip to content

Commit c92e507

Browse files
committed
Fix Copy equality/hashCode contract
1 parent 69ba847 commit c92e507

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

‎pom.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
3-
* SPDX-FileCopyrightText: Copyright (c) 2018-2026 Zerocracy
4-
* SPDX-License-Identifier: MIT
3+
* SPDX-FileCopyrightText: Copyright (c) 2018-2026 Zerocracy
4+
* SPDX-License-Identifier: MIT
55
-->
66
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
77
<modelVersion>4.0.0</modelVersion>

‎src/main/java/io/zold/api/Copies.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public int compareTo(final Copy other) {
116116
@Override
117117
public boolean equals(final Object obj) {
118118
return obj instanceof Copy
119-
&& this.compareTo((Copy) obj) == 0;
119+
&& this.wlt.equals(((Copy) obj).wlt);
120120
}
121121

122122
@Override

‎src/test/java/io/zold/api/CopiesTest.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@ void groupsRemotesScoresIntoSingleCopy() {
4141
);
4242
}
4343

44+
@Test
45+
void distinguishesCopiesWithDifferentWallets() {
46+
final Remote remote = new Remote.Fake(
47+
new RtScore(new IterableOf<>(new TextOf("a")))
48+
);
49+
MatcherAssert.assertThat(
50+
"wallet identity defines copy equality",
51+
new Copies.Copy(new Wallet.Fake(1L), remote).equals(
52+
new Copies.Copy(
53+
new Wallet.Fake(2L),
54+
remote
55+
)
56+
),
57+
new IsEqual<>(false)
58+
);
59+
}
60+
4461
private static Iterable<Copies.Copy> copies() {
4562
return new Copies(
4663
1L,

0 commit comments

Comments
 (0)