DoublyLinkedList implements Iterable<T> { public void remove(ListNode2<T> node) { if (node == tail) { tail = node.next; } else { node.prev.next = node.next; } if (node == head) { head = node.prev; } else { node.next.prev = node.prev; } size--; }  ListNode2<T> add(T value); ListNode2<T> enqueue(T value); void add(ListNode2<T> node); ListNode2<T> addAfter(ListNode2<T> node, T value); void addAfter(ListNode2<T> node, ListNode2<T> newNode); void remove(ListNode2<T> node); int size(); @Override Iterator<T> iterator(); T first(); T last(); ListNode2<T> head(); ListNode2<T> tail(); boolean isEmpty(); @SuppressWarnings("unchecked") T[] toArray();  }
@Test public void testRemove() { DoublyLinkedList<Integer> list = new DoublyLinkedList<Integer>(); ListNode2<Integer> node1 = list.add(1); list.remove(node1); node1 = list.add(1); ListNode2<Integer> node2 = list.add(2); list.remove(node1); assertEquals(1, list.size()); assertEquals(new Integer(2), list.first()); assertEquals(node2, list.head()); assertArrayEquals(new Integer[]{2}, list.toArray()); list.remove(node2); assertIsEmpty(list); node1 = list.add(1); node2 = list.add(2); list.remove(node2); assertEquals(1, list.size()); assertEquals(new Integer(1), list.first()); assertEquals(node1, list.head()); assertArrayEquals(new Integer[]{1}, list.toArray()); node2 = list.add(2); list.add(3); assertEquals(3, list.size()); assertArrayEquals(new Integer[]{1, 2, 3}, list.toArray()); list.remove(node2); assertEquals(2, list.size()); assertEquals(node1, list.tail()); assertEquals(new Integer(3), list.last()); assertArrayEquals(new Integer[]{1, 3}, list.toArray()); }