### Question:
Link { @Override public boolean equals(Object other) { if (other == null) { return false; } if (other == this) { return true; } if (!(other instanceof Link)) { return false; } Link otherLink = (Link) other; return otherLink.getType().equals(type) && ( (otherLink.getSource() == source && otherLink.getTarget() == target) || (otherLink.getSource() == target && otherLink.getTarget() == source)); } Link(Edge edge, int source, int target); int getSource(); int getTarget(); String getType(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void equalsReturnsFalseWhenOtherIsNull() { Link underTest = new Link(edgeMock, 2, 1); assertThat(underTest.equals(null), is(false)); }
@Test public void equalsReturnsTrueWhenOtherHasTheSameMemoryReference() { Link underTest = new Link(edgeMock, 2, 1); assertThat(underTest.equals(underTest), is(true)); }
@Test public void equalsReturnsFalseWhenOtherIsNotALink() { Link underTest = new Link(edgeMock, 2, 1); assertThat(underTest.equals(new Object()), is(false)); }
@Test public void equalsReturnsFalseWhenOtherLinkDoesNotMatchType() { Link underTest = new Link(edgeMock, 2, 1); Link compareTo = new Link(compareEdgeMockDifferentType, 2, 1); assertThat(underTest.equals(compareTo), is(false)); }
@Test public void equalsReturnsFalseWhenOtherLinkHasDifferentSourceTargetCombination() { Link underTest = new Link(edgeMock, 2, 1); Link compareTo = new Link(edgeMock, 3, 1); assertThat(underTest.equals(compareTo), is(false)); }
@Test public void equalsReturnsTrueWhenOtherLinkHasTheSameTypeAndSourceTargetCombination() { Link underTest = new Link(edgeMock, 2, 1); Link compareTo = new Link(edgeMock, 1, 2); Link compareTo2 = new Link(edgeMock, 2, 1); assertThat(underTest.equals(compareTo), is(true)); assertThat(underTest.equals(compareTo2), is(true)); assertThat(compareTo.equals(compareTo2), is(true)); }