private void assertSetCount(E element, int count) { setCountCheckReturnValue(element, count); assertEquals( "multiset.count() should return the value passed to setCount()", count, getMultiset().count(element)); int size = 0; for (Multiset.Entry<E> entry : getMultiset().entrySet()) { size += entry.getCount(); } assertEquals( "multiset.size() should be the sum of the counts of all entries", size, getMultiset().size()); }
@CollectionSize.Require(absent = ZERO) @CollectionFeature.Require(absent = {SUPPORTS_ADD, SUPPORTS_REMOVE}) public void testSetCount_oneToOne_unsupported() { try { assertOneToOne(); } catch (UnsupportedOperationException tolerated) { } }
private void assertThreeToThree() { initThreeCopies(); assertSetCount(e0(), 3); }
private void assertSetCountIncreasingFailure(E element, int count) { try { setCountNoCheckReturnValue(element, count); fail("a call to multiset.setCount() to increase an element's count should throw"); } catch (UnsupportedOperationException expected) { } }
private void assertOneToOne() { assertSetCount(e0(), 1); }
@CollectionSize.Require(SEVERAL) @CollectionFeature.Require(absent = SUPPORTS_REMOVE) public void testSetCount_threeToOne_unsupported() { initThreeCopies(); assertSetCountDecreasingFailure(e0(), 1); }
@CollectionFeature.Require(absent = SUPPORTS_REMOVE) public void testSetCount_negative_removeUnsupported() { try { setCountNoCheckReturnValue(e3(), -1); fail( "calling setCount() with a negative count should throw " + "IllegalArgumentException or UnsupportedOperationException"); } catch (IllegalArgumentException | UnsupportedOperationException expected) { } }
@CollectionFeature.Require({SUPPORTS_ADD, FAILS_FAST_ON_CONCURRENT_MODIFICATION}) public void testSetCountZeroToOneConcurrentWithEntrySetIteration() { try { Iterator<Entry<E>> iterator = getMultiset().entrySet().iterator(); assertSetCount(e3(), 1); iterator.next(); fail("Expected ConcurrentModificationException"); } catch (ConcurrentModificationException expected) { // success } }
@CollectionFeature.Require({SUPPORTS_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION}) @CollectionSize.Require(absent = ZERO) public void testSetCountOneToZeroConcurrentWithEntrySetIteration() { try { Iterator<Entry<E>> iterator = getMultiset().entrySet().iterator(); assertSetCount(e0(), 0); iterator.next(); fail("Expected ConcurrentModificationException"); } catch (ConcurrentModificationException expected) { // success } }
@CollectionFeature.Require({SUPPORTS_ADD, FAILS_FAST_ON_CONCURRENT_MODIFICATION}) public void testSetCountZeroToOneConcurrentWithEntrySetIteration() { try { Iterator<Entry<E>> iterator = getMultiset().entrySet().iterator(); assertSetCount(samples.e3, 1); iterator.next(); fail("Expected ConcurrentModificationException"); } catch (ConcurrentModificationException expected) { // success } }
@CollectionFeature.Require(absent = SUPPORTS_ADD) public void testSetCount_zeroToThree_unsupported() { assertSetCountIncreasingFailure(e3(), 3); }
@CollectionFeature.Require({SUPPORTS_ADD, FAILS_FAST_ON_CONCURRENT_MODIFICATION}) public void testSetCountZeroToOneConcurrentWithIteration() { try { Iterator<E> iterator = collection.iterator(); assertSetCount(e3(), 1); iterator.next(); fail("Expected ConcurrentModificationException"); } catch (ConcurrentModificationException expected) { // success } }
@CollectionFeature.Require({SUPPORTS_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION}) @CollectionSize.Require(absent = ZERO) public void testSetCountOneToZeroConcurrentWithIteration() { try { Iterator<E> iterator = collection.iterator(); assertSetCount(e0(), 0); iterator.next(); fail("Expected ConcurrentModificationException"); } catch (ConcurrentModificationException expected) { // success } }
@CollectionSize.Require(absent = ZERO) @CollectionFeature.Require(ALLOWS_NULL_VALUES) public void testSetCount_existingNoNopNull_nullSupported() { initCollectionWithNullElement(); try { assertSetCount(null, 1); } catch (UnsupportedOperationException tolerated) { } }
@CollectionFeature.Require(absent = {SUPPORTS_ADD, SUPPORTS_REMOVE}) public void testSetCount_zeroToZero_unsupported() { try { assertZeroToZero(); } catch (UnsupportedOperationException tolerated) { } }
@CollectionSize.Require(SEVERAL) @CollectionFeature.Require(SUPPORTS_ADD) public void testSetCount_threeToThree_addSupported() { assertThreeToThree(); }
@CollectionSize.Require(SEVERAL) @CollectionFeature.Require(absent = SUPPORTS_REMOVE) public void testSetCount_threeToZero_unsupported() { initThreeCopies(); assertSetCountDecreasingFailure(samples.e0, 0); }
@CollectionFeature.Require({SUPPORTS_ADD, FAILS_FAST_ON_CONCURRENT_MODIFICATION}) public void testSetCountZeroToOneConcurrentWithIteration() { try { Iterator<E> iterator = collection.iterator(); assertSetCount(samples.e3, 1); iterator.next(); fail("Expected ConcurrentModificationException"); } catch (ConcurrentModificationException expected) { // success } }
@CollectionFeature.Require( value = {SUPPORTS_ADD, ALLOWS_NULL_VALUES}, absent = RESTRICTS_ELEMENTS ) public void testSetCount_addNull_nullSupported() { assertSetCount(null, 1); }
private void assertZeroToZero() { assertSetCount(e3(), 0); }