CloseableReferenceCount { public boolean unreference() { int newVal = status.decrementAndGet(); Preconditions.checkState(newVal != 0xffffffff, "called unreference when the reference count was already at 0."); return newVal == STATUS_CLOSED_MASK; } CloseableReferenceCount(); void reference(); boolean unreference(); void unreferenceCheckClosed(); boolean isOpen(); int setClosed(); int getReferenceCount();  }
@Test public void testUnreference() throws ClosedChannelException { CloseableReferenceCount clr = new CloseableReferenceCount(); clr.reference(); clr.reference(); assertFalse("New reference count should not equal STATUS_CLOSED_MASK", clr.unreference()); assertEquals("Incorrect reference count", 1, clr.getReferenceCount()); }