I've started using your library for my projects and its really awesome!
I have encountered though an issue I can't seem to work around it.
I have the following class:
class MyCollection<T> {
protected final Map<T, Node<T>> map;
protected Optional<Node<T>> head;
protected Optional<Node<T>> last;
.....
.....
.....
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (!head.isPresent() ? 0 : head.get().value.hashCode());
result = prime * result + (!last.isPresent() ? 0 : last.get().value.hashCode());
result = prime * result + ((map == null) ? 0 : map.keySet().hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
MyCollection<T> other = (MyCollection) obj;
if (head.isPresent()) {
if (!other.head.isPresent())
return false;
if (!head.get().value.equals(other.head.get().value))
return false;
} else if (other.head.isPresent())
return false;
if (last.isPresent()) {
if (!other.last.isPresent())
return false;
if (!last.get().value.equals(other.last.get().value))
return false;
} else if (other.last.isPresent())
return false;
if (!map.keySet().equals(other.map.keySet()))
return false;
return true;
}
.....
.....
.....
.....
private static class Node<T> {
T value;
Optional<Node<T>> prev = Optional.empty();
Optional<Node<T>> next = Optional.empty();
public Node(T t) {
value = t;
}
//Node doesn't implement hashcode() and equals() since it has to be unique
}
}
When I tried testing "MyCollection" using "EqualsVerifier.forClass(MyCollection.class).usingGetClass().verify()" I got the following exception:
java.lang.AssertionError: java.lang.ClassCastException: java.lang.Object cannot be cast to com.example.MyCollection$Node