Recycler { public final boolean recycle(T o, Handle handle) { DefaultHandle h = (DefaultHandle) handle; if (h.stack.parent != this) { return false; } if (o != h.value) { throw new IllegalArgumentException("o does not belong to handle"); } h.recycle(); return true; } protected  Recycler(); protected  Recycler(int maxCapacity); @SuppressWarnings("unchecked") final T get(); final boolean recycle(T o, Handle handle);  }
@Test(expected = IllegalStateException.class) public void testMultipleRecycle() { RecyclableObject object = RecyclableObject.newInstance(); object.recycle(); object.recycle(); }
@Test public void testRecycle() { RecyclableObject object = RecyclableObject.newInstance(); object.recycle(); RecyclableObject object2 = RecyclableObject.newInstance(); assertSame(object, object2); object2.recycle(); }