DoublyLinkedList implements Iterable<T> { public ListNode2<T> enqueue(T value) { ListNode2<T> node = new ListNode2<T>(value); if (size++ == 0) { head = node; } else { node.next = tail; tail.prev = node; } tail = node; return node; }  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 testEnqueue() { DoublyLinkedList<Integer> list = new DoublyLinkedList<Integer>(); list.enqueue(1); assertFalse(list.isEmpty()); assertEquals(1, list.size()); assertArrayEquals(new Integer[]{1}, list.toArray()); list.enqueue(2); assertFalse(list.isEmpty()); assertEquals(2, list.size()); assertArrayEquals(new Integer[]{2, 1}, list.toArray()); list.enqueue(3); assertFalse(list.isEmpty()); assertEquals(3, list.size()); assertArrayEquals(new Integer[]{3, 2, 1}, list.toArray()); assertEquals(new Integer(3), list.first()); assertEquals(new Integer(1), list.last()); }