@CollectionSize.Require(SEVERAL) @CollectionFeature.Require(SUPPORTS_REMOVE) public void testRemove_some_occurrences_present() { initThreeCopies(); assertEquals( "multiset.remove(present, 2) didn't return the old count", 3, getMultiset().remove(e0(), 2)); assertTrue( "multiset contains present after multiset.remove(present, 2)", getMultiset().contains(e0())); assertEquals(1, getMultiset().count(e0())); }
@CollectionSize.Require(SEVERAL) @CollectionFeature.Require(SUPPORTS_REMOVE) public void testRetainAllIgnoresCount() { initThreeCopies(); List<E> contents = Helpers.copyToList(getMultiset()); assertFalse(getMultiset().retainAll(Collections.singleton(e0()))); expectContents(contents); }
@CollectionFeature.Require(SUPPORTS_REMOVE) public void testRemoveZeroNoOp() { int originalCount = getMultiset().count(e0()); assertEquals("old count", originalCount, getMultiset().remove(e0(), 0)); expectUnchanged(); }
@CollectionFeature.Require(SUPPORTS_REMOVE) public void testRemoveNegative() { try { getMultiset().remove(e0(), -1); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } expectUnchanged(); }
@CollectionSize.Require(absent = ZERO) @CollectionFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_VALUES}) public void testRemove_nullPresent() { initCollectionWithNullElement(); assertEquals(1, getMultiset().remove(null, 2)); assertFalse( "multiset contains present after multiset.remove(present, 2)", getMultiset().contains(null)); assertEquals(0, getMultiset().count(null)); }
@CollectionFeature.Require(SUPPORTS_REMOVE) public void testRemove_occurrences_wrongType() { assertEquals( "multiset.remove(wrongType, 1) didn't return 0", 0, getMultiset().remove(WrongType.VALUE, 1)); }
@CollectionFeature.Require(SUPPORTS_REMOVE) public void testRemove_occurrences_negative() { try { getMultiset().remove(e0(), -1); fail("multiset.remove(E, -1) didn't throw an exception"); } catch (IllegalArgumentException required) { } }
@CollectionFeature.Require(absent = SUPPORTS_REMOVE) public void testRemove_occurrences_unsupported_absent() { // notice: we don't care whether it succeeds, or fails with UOE try { assertEquals( "multiset.remove(absent, 2) didn't return 0 or throw an exception", 0, getMultiset().remove(e3(), 2)); } catch (UnsupportedOperationException ok) { } }
@CollectionSize.Require(absent = ZERO) @CollectionFeature.Require(SUPPORTS_REMOVE) public void testRemove_occurrences_present() { assertEquals( "multiset.remove(present, 2) didn't return the old count", 1, getMultiset().remove(e0(), 2)); assertFalse( "multiset contains present after multiset.remove(present, 2)", getMultiset().contains(e0())); assertEquals(0, getMultiset().count(e0())); }
@CollectionFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_QUERIES) public void testRemove_nullForbidden() { try { getMultiset().remove(null, 2); fail("Expected NullPointerException"); } catch (NullPointerException expected) { } }
@CollectionFeature.Require(SUPPORTS_REMOVE) public void testRemoveNegative() { try { getMultiset().remove(samples.e0, -1); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) {} expectUnchanged(); }
@CollectionFeature.Require(SUPPORTS_REMOVE) public void testRemoveZeroNoOp() { int originalCount = getMultiset().count(samples.e0); assertEquals("old count", originalCount, getMultiset().remove(samples.e0, 0)); expectUnchanged(); }
@CollectionSize.Require(absent = ZERO) @CollectionFeature.Require(SUPPORTS_REMOVE) public void testRemove_occurrences_present() { assertEquals("multiset.remove(present, 2) didn't return the old count", 1, getMultiset().remove(samples.e0, 2)); assertFalse("multiset contains present after multiset.remove(present, 2)", getMultiset().contains(samples.e0)); assertEquals(0, getMultiset().count(samples.e0)); }
@CollectionSize.Require(SEVERAL) @CollectionFeature.Require(SUPPORTS_REMOVE) public void testRemoveAllIgnoresCount() { initThreeCopies(); assertTrue(getMultiset().removeAll(Collections.singleton(samples.e0))); ASSERT.that(getMultiset()).isEmpty(); }
@CollectionFeature.Require(SUPPORTS_REMOVE) public void testRemove_occurrences_0() { int oldCount = getMultiset().count(e0()); assertEquals( "multiset.remove(E, 0) didn't return the old count", oldCount, getMultiset().remove(e0(), 0)); }
@CollectionSize.Require(absent = ZERO) @CollectionFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_VALUES}) public void testRemove_nullPresent() { initCollectionWithNullElement(); assertEquals(1, getMultiset().remove(null, 2)); assertFalse( "multiset contains present after multiset.remove(present, 2)", getMultiset().contains(null)); assertEquals(0, getMultiset().count(null)); }
@CollectionFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_QUERIES}) public void testRemove_nullAbsent() { assertEquals(0, getMultiset().remove(null, 2)); }
@CollectionFeature.Require(absent = SUPPORTS_REMOVE) public void testRemoveUnsupported() { try { getMultiset().remove(e0(), 2); fail("Expected UnsupportedOperationException"); } catch (UnsupportedOperationException expected) { } }
@CollectionFeature.Require(SUPPORTS_REMOVE) public void testRemove_occurrences_absent() { int distinct = getMultiset().elementSet().size(); assertEquals("multiset.remove(absent, 0) didn't return 0", 0, getMultiset().remove(e3(), 2)); assertEquals(distinct, getMultiset().elementSet().size()); }
@CollectionSize.Require(absent = ZERO) @CollectionFeature.Require(SUPPORTS_REMOVE) public void testRemove_occurrences_present() { assertEquals( "multiset.remove(present, 2) didn't return the old count", 1, getMultiset().remove(e0(), 2)); assertFalse( "multiset contains present after multiset.remove(present, 2)", getMultiset().contains(e0())); assertEquals(0, getMultiset().count(e0())); }