RemoveListDuplicatedElements { public void remove2(ListNode<Integer> head) { validateInput(head); ListNode<Integer> node = head; while (node != null) { removeNextNodesWithValue(node); node = node.getNext(); } }  void remove(ListNode<Integer> head); void remove2(ListNode<Integer> head);  }
@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullInstancesAsParameter2() { removeDuplicates.remove2(null); }
@Test public void shouldNotModifyListIfThereAreNotDuplicatedElements2() { ListNode<Integer> head = createList(new Integer[] { 0, 1, 2, 3, 4 }); removeDuplicates.remove2(head); assertListContainsElements(new Integer[] { 0, 1, 2, 3, 4 }, head); }
@Test public void shouldRemoveDuplicatedElements2() { ListNode<Integer> head = createList(new Integer[] { 0, 1, 0, 2, 2, 3, 4, 4 }); removeDuplicates.remove2(head); assertListContainsElements(new Integer[] { 0, 1, 2, 3, 4 }, head); }