@CollectionFeature.Require(ALLOWS_NULL_VALUES) @CollectionSize.Require(absent = ZERO) public void testContains_nullContained() { initCollectionWithNullElement(); assertTrue("contains(null) should return true", collection.contains(null)); }
@CollectionFeature.Require(ALLOWS_NULL_VALUES) @CollectionSize.Require(absent = ZERO) public void testContains_nonNullWhenNullContained() { initCollectionWithNullElement(); assertFalse("contains(notPresent) should return false", collection.contains(e3())); }
@CollectionFeature.Require(absent = ALLOWS_NULL_VALUES) public void testFind_nullNotContainedAndUnsupported() { try { assertEquals(getMethodName() + "(nullNotPresent) should return -1 or throw", -1, find(null)); } catch (NullPointerException tolerated) { } }
@CollectionSize.Require(SEVERAL) @CollectionFeature.Require(SUPPORTS_REMOVE) @MultisetFeature.Require(ENTRIES_ARE_VIEWS) public void testEntryReflectsElementSetClear() { initThreeCopies(); assertEquals(3, getMultiset().count(e0())); Multiset.Entry<E> entry = Iterables.getOnlyElement(getMultiset().entrySet()); assertEquals(3, entry.getCount()); getMultiset().elementSet().clear(); assertEquals(0, entry.getCount()); }
@CollectionSize.Require(SEVERAL) @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE) @MultisetFeature.Require(ENTRIES_ARE_VIEWS) public void testEntryReflectsEntrySetIteratorRemove() { initThreeCopies(); assertEquals(3, getMultiset().count(e0())); Iterator<Multiset.Entry<E>> entryItr = getMultiset().entrySet().iterator(); Multiset.Entry<E> entry = entryItr.next(); entryItr.remove(); assertEquals(0, entry.getCount()); }
@CollectionSize.Require(SEVERAL) @CollectionFeature.Require(SUPPORTS_REMOVE) @MultisetFeature.Require(ENTRIES_ARE_VIEWS) public void testEntryReflectsEntrySetClear() { initThreeCopies(); assertEquals(3, getMultiset().count(e0())); Multiset.Entry<E> entry = Iterables.getOnlyElement(getMultiset().entrySet()); assertEquals(3, entry.getCount()); getMultiset().entrySet().clear(); assertEquals(0, entry.getCount()); }
@CollectionSize.Require(absent = ZERO) @CollectionFeature.Require(SUPPORTS_REMOVE) public void testElementSetReflectsRemove() { Set<E> elementSet = getMultiset().elementSet(); assertTrue(elementSet.contains(e0())); getMultiset().removeAll(Collections.singleton(e0())); assertFalse(elementSet.contains(e0())); }
@CollectionFeature.Require(ALLOWS_NULL_VALUES) public void testSetCount_noOpNull_nullSupported() { try { assertSetCount(null, 0); } catch (UnsupportedOperationException tolerated) { } }
@CollectionFeature.Require( value = {SUPPORTS_ADD, ALLOWS_NULL_VALUES}, absent = RESTRICTS_ELEMENTS ) public void testSetCount_addNull_nullSupported() { assertSetCount(null, 1); }
@CollectionSize.Require(SEVERAL) @CollectionFeature.Require(absent = SUPPORTS_REMOVE) public void testSetCount_threeToOne_unsupported() { initThreeCopies(); assertSetCountDecreasingFailure(e0(), 1); }
@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 } }
@CollectionSize.Require(absent = ZERO) @CollectionFeature.Require(absent = SUPPORTS_ADD) public void testSetCount_oneToThree_unsupported() { assertSetCountIncreasingFailure(e3(), 3); }
@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 } }
@CollectionSize.Require(absent = ZERO) @CollectionFeature.Require(absent = {SUPPORTS_ADD, SUPPORTS_REMOVE}) public void testSetCount_oneToOne_unsupported() { try { assertOneToOne(); } catch (UnsupportedOperationException tolerated) { } }
@CollectionFeature.Require(absent = {SUPPORTS_ADD, SUPPORTS_REMOVE}) public void testSetCount_zeroToZero_unsupported() { try { assertZeroToZero(); } catch (UnsupportedOperationException tolerated) { } }
@CollectionFeature.Require(SERIALIZABLE) public void testReserializeMap() { Map<K, V> deserialized = SerializableTester.reserialize(getMap()); new EqualsTester().addEqualityGroup(getMap(), deserialized).testEquals(); } }
@CollectionFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_QUERIES}) public void testRemoveAll_containsNullNoButAllowed() { MinimalCollection<?> containsNull = MinimalCollection.of((Object) null); assertFalse("removeAll(containsNull) should return false", collection.removeAll(containsNull)); expectUnchanged(); }
@CollectionFeature.Require(SUPPORTS_REMOVE) @CollectionSize.Require(absent = ZERO) public void testRemoveAll_nullCollectionReferenceNonEmptySubject() { try { collection.removeAll(null); fail("removeAll(null) should throw NullPointerException"); } catch (NullPointerException expected) { } }
@CollectionFeature.Require(KNOWN_ORDER) public void testToArray_rightSizedArray_ordered() { E[] array = getSubjectGenerator().createArray(getNumElements()); assertSame( "toArray(sameSizeE[]) should return the given array", array, collection.toArray(array)); expectArrayContentsInOrder(getOrderedElements(), array); }
@CollectionFeature.Require(SUPPORTS_REMOVE) @CollectionSize.Require(SEVERAL) public void testPollLast() { assertEquals(c, navigableSet.pollLast()); assertEquals(values.subList(0, values.size() - 1), Helpers.copyToList(navigableSet)); }