PendingReferenceRegistry { Set<PendingListReference> removeAndGetPendingListReferencesWith(Object object) { assert object != null; final Set<PendingListReference> refs = pendingLists == null ? null : pendingLists.remove(object); if (refs == null) { return Collections.emptySet(); } final Iterator<PendingListReference> it = refs.iterator(); while (it.hasNext()) { final PendingListReference ref = it.next(); assert pendingListItems.get(ref.descriptor) != null; pendingListItems.compute(ref.descriptor, (k, v) -> v - 1); if (pendingListItems.get(ref.descriptor) == 0) { pendingListItems.remove(ref.descriptor); } else { it.remove(); } } return refs; }    }
@Test public void removeAndGetPendingListReferencesReturnsEmptyCollectionWhenNoPendingListsExistForItem() { final Set<PendingReferenceRegistry.PendingListReference> result = registry.removeAndGetPendingListReferencesWith(new OWLClassA()); assertNotNull(result); assertTrue(result.isEmpty()); }