Pool { public synchronized T allocate() { if (free == null) { return null; } final T result = free; free = free.getNext(); return result; }  synchronized T allocate(); T free(T element); boolean isEmpty(); int size();  }
@Test public void testAllocate() { assertEquals(5, pool.size()); ListNode<Integer> previous = null; for (int i = 0; i < 5; i++) { assertFalse(pool.isEmpty()); ListNode<Integer> node = pool.allocate(); assertNotSame(node, previous); assertNotNull(node); previous = node; } assertTrue(pool.isEmpty()); assertNull(pool.allocate()); }