Fixed tests and fixed failed tests

This commit is contained in:
Teriuihi 2022-08-22 22:24:36 +02:00
parent 01456bfc9f
commit 8825f4b3cc
2 changed files with 12 additions and 8 deletions

View File

@ -25,13 +25,13 @@ public class Lock implements Comparable {
@Override
public final boolean equals(@Nullable Object o) {
if (this == o) {
Lock other = (Lock) o;
if (this == other) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (other == null || getClass() != other.getClass()) {
return false;
}
Lock other = (Lock) o;
return data.equals(other.data) && serverHash == other.serverHash;
}
@ -43,6 +43,10 @@ public class Lock implements Comparable {
@Override
public int compareTo(@NotNull Object o) {
return ((Lock) o).data.compareTo(data);
Lock lock = (Lock) o;
int data = lock.data.compareTo(this.data);
if (data != 0)
return data;
return Integer.compare(lock.getServerHash(), getServerHash());
}
}

View File

@ -6,16 +6,16 @@ class LockTest {
@org.junit.jupiter.api.Test
void testEquals() {
assertEquals(new Lock(123, "test"), new Lock(123, "test"));
assertNotEquals(new Lock(123, "test1"), new Lock(123, "test2"));
assertEquals(new Lock(123, "test"), new Lock(-123, "test"));
assertTrue(new Lock(123, "test").equals(new Lock(123, "test")));
assertFalse(new Lock(123, "test1").equals(new Lock(123, "test2")));
assertFalse(new Lock(123, "test").equals(new Lock(-123, "test")));
}
@org.junit.jupiter.api.Test
void testHashCode() {
assertEquals(new Lock(123, "test").hashCode(), new Lock(123, "test").hashCode());
assertNotEquals(new Lock(123, "test1").hashCode(), new Lock(123, "test2").hashCode());
assertEquals(new Lock(123, "test").hashCode(), new Lock(-123, "test").hashCode());
assertNotEquals(new Lock(123, "test").hashCode(), new Lock(-123, "test").hashCode());
}
@org.junit.jupiter.api.Test