DistanceEntity { @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } DistanceEntity that = (DistanceEntity) o; return key.equals(that.key) && distance.equals(that.distance); } protected  DistanceEntity();   DistanceEntity(DistanceKey key, Long distance); @Override boolean equals(Object o); @Override int hashCode();  }
@Test void equals() { final long from = 10; final long to = 2000; final DistanceKey distanceKey = new DistanceKey(from, to); final long distance = 50001; DistanceEntity distanceEntity = new DistanceEntity(distanceKey, distance); assertThat(distanceEntity) .isEqualTo(distanceEntity) .isEqualTo(new DistanceEntity(new DistanceKey(from, to), distance)) .isNotEqualTo(null) .isNotEqualTo(distanceKey) .isNotEqualTo(new DistanceEntity(distanceKey, distance + 1)) .isNotEqualTo(new DistanceEntity(new DistanceKey(to, from), distance)); }