Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/io/zold/api/Copies.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public int compareTo(final Copy other) {
@Override
public boolean equals(final Object obj) {
return obj instanceof Copy
&& this.compareTo((Copy) obj) == 0;
&& this.wlt.equals(((Copy) obj).wlt);
}

@Override
Expand Down
51 changes: 49 additions & 2 deletions src/test/java/io/zold/api/CopiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,60 @@ void groupsRemotesScoresIntoSingleCopy() {
);
}

@Test
void keepsIdentityWhenCopyGetsRemote() {
final Copies.Copy copy = new Copies.Copy(
new Wallet.Fake(1L),
CopiesTest.remote("a")
);
MatcherAssert.assertThat(
"copy identity is stable when a remote is added",
copy.with(CopiesTest.remote("b")),
new IsEqual<>(copy)
);
}

@Test
void keepsHashCodeWhenCopyGetsRemote() {
final Copies.Copy copy = new Copies.Copy(
new Wallet.Fake(1L),
CopiesTest.remote("a")
);
MatcherAssert.assertThat(
"hash code matches equality after adding a remote",
copy.with(CopiesTest.remote("b")).hashCode(),
new IsEqual<>(copy.hashCode())
);
}

@Test
void distinguishesCopiesWithDifferentWalletsAndSameScore() {
MatcherAssert.assertThat(
"different wallets are not equal even with the same score",
new Copies.Copy(
new Wallet.Fake(1L),
CopiesTest.remote("a")
).equals(
new Copies.Copy(
new Wallet.Fake(2L),
CopiesTest.remote("b")
)
),
new IsEqual<>(false)
);
}

private static Iterable<Copies.Copy> copies() {
return new Copies(
1L,
new IterableOf<>(
new Remote.Fake(new RtScore(new IterableOf<>(new TextOf("a")))),
new Remote.Fake(new RtScore(new IterableOf<>(new TextOf("b"))))
CopiesTest.remote("a"),
CopiesTest.remote("b")
)
);
}

private static Remote remote(final String suffix) {
return new Remote.Fake(new RtScore(new IterableOf<>(new TextOf(suffix))));
}
}
Loading