DeleteListNode { public void delete(ListNode node) { validateInputData(node); if (node.getNext() == null) { return; } ListNode next = node.getNext(); node.setData(next.getData()); node.setNext(next.getNext()); }  void delete(ListNode node);  }
@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullNodes() { deleteNode.delete(null); }
@Test public void shouldNotModifyNodeIfListContainsJustThatNode() { ListNode<Integer> head = new ListNode<Integer>(1); deleteNode.delete(head); assertEquals(head, head); }
@Test public void shouldRemoveListNode() { ListNode<Integer> head = new ListNode<Integer>(0); ListNode<Integer> n1 = new ListNode<Integer>(1); ListNode<Integer> n2 = new ListNode<Integer>(2); head.setNext(n1); n1.setNext(n2); deleteNode.delete(n1); assertListContainsElements(new Integer[] { 0, 2 }, head); }
@Test public void shouldRemoveHead() { ListNode<Integer> head = new ListNode<Integer>(0); ListNode<Integer> n1 = new ListNode<Integer>(1); ListNode<Integer> n2 = new ListNode<Integer>(2); head.setNext(n1); n1.setNext(n2); deleteNode.delete(head); assertListContainsElements(new Integer[] { 1, 2 }, n1); }