Java Code Examples for com.google.common.collect.testing.features.CollectionFeature

The following are top voted examples for showing how to use com.google.common.collect.testing.features.CollectionFeature. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: guava-mock   File: TestsForListsInJavaUtil.java   Source Code and License 6 votes vote down vote up
public Test testsForArraysAsList() {
  return ListTestSuiteBuilder.using(
          new TestStringListGenerator() {
            @Override
            public List<String> create(String[] elements) {
              return Arrays.asList(elements.clone());
            }
          })
      .named("Arrays.asList")
      .withFeatures(
          ListFeature.SUPPORTS_SET,
          CollectionFeature.SERIALIZABLE,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionSize.ANY)
      .suppressing(suppressForArraysAsList())
      .createTestSuite();
}
 
Example 2
Project: googles-monorepo-demo   File: SetHashCodeTester.java   Source Code and License 6 votes vote down vote up
@CollectionSize.Require(absent = CollectionSize.ZERO)
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
public void testHashCode_containingNull() {
  Collection<E> elements = getSampleElements(getNumElements() - 1);
  int expectedHashCode = 0;
  for (E element : elements) {
    expectedHashCode += ((element == null) ? 0 : element.hashCode());
  }

  elements.add(null);
  collection = getSubjectGenerator().create(elements.toArray());
  assertEquals(
      "A Set's hashCode() should be the sum of those of its elements (with "
          + "a null element counting as having a hash of zero).",
      expectedHashCode,
      getSet().hashCode());
}
 
Example 3
Project: guava-mock   File: MultisetNavigationTester.java   Source Code and License 6 votes vote down vote up
@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_ADD)
public void testConflictingBounds() {
  testEmptyRangeSubMultiset(
      sortedMultiset.subMultiset(a.getElement(), CLOSED, a.getElement(), OPEN));
  testEmptyRangeSubMultiset(
      sortedMultiset.subMultiset(a.getElement(), OPEN, a.getElement(), OPEN));
  testEmptyRangeSubMultiset(
      sortedMultiset.subMultiset(a.getElement(), OPEN, a.getElement(), CLOSED));
  testEmptyRangeSubMultiset(
      sortedMultiset.subMultiset(b.getElement(), CLOSED, a.getElement(), CLOSED));
  testEmptyRangeSubMultiset(
      sortedMultiset.subMultiset(b.getElement(), CLOSED, a.getElement(), OPEN));
  testEmptyRangeSubMultiset(
      sortedMultiset.subMultiset(b.getElement(), OPEN, a.getElement(), OPEN));
}
 
Example 4
Project: guava-mock   File: TestsForSetsInJavaUtil.java   Source Code and License 6 votes vote down vote up
public Test testsForConcurrentSkipListSetWithComparator() {
  return SetTestSuiteBuilder.using(
          new TestStringSortedSetGenerator() {
            @Override
            public SortedSet<String> create(String[] elements) {
              SortedSet<String> set =
                  new ConcurrentSkipListSet<String>(arbitraryNullFriendlyComparator());
              Collections.addAll(set, elements);
              return set;
            }
          })
      .named("ConcurrentSkipListSet, with comparator")
      .withFeatures(
          SetFeature.GENERAL_PURPOSE,
          CollectionFeature.SERIALIZABLE,
          CollectionFeature.KNOWN_ORDER,
          CollectionSize.ANY)
      .suppressing(suppressForConcurrentSkipListSetWithComparator())
      .createTestSuite();
}
 
Example 5
Project: guava-mock   File: TestsForMapsInJavaUtil.java   Source Code and License 6 votes vote down vote up
public Test testsForCheckedNavigableMap() {
  return SortedMapTestSuiteBuilder.using(
      new TestStringSortedMapGenerator() {
        @Override
        protected NavigableMap<String, String> create(Entry<String, String>[] entries) {
          NavigableMap<String, String> map = populate(new TreeMap<String, String>(), entries);
          return Collections.checkedNavigableMap(map, String.class, String.class);
        }
      })
      .named("checkedNavigableMap/TreeMap, natural")
      .withFeatures(
          MapFeature.GENERAL_PURPOSE,
          MapFeature.ALLOWS_NULL_VALUES,
          MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
          MapFeature.RESTRICTS_KEYS,
          MapFeature.RESTRICTS_VALUES,
          CollectionFeature.KNOWN_ORDER,
          CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
          CollectionFeature.SERIALIZABLE,
          CollectionSize.ANY)
      .suppressing(suppressForCheckedNavigableMap())
      .createTestSuite();
}
 
Example 6
Project: guava-mock   File: BiMapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
private static Set<Feature<?>> computeInverseFeatures(Set<Feature<?>> mapFeatures) {
  Set<Feature<?>> inverseFeatures = new HashSet<Feature<?>>(mapFeatures);

  boolean nullKeys = inverseFeatures.remove(MapFeature.ALLOWS_NULL_KEYS);
  boolean nullValues = inverseFeatures.remove(MapFeature.ALLOWS_NULL_VALUES);

  if (nullKeys) {
    inverseFeatures.add(MapFeature.ALLOWS_NULL_VALUES);
  }
  if (nullValues) {
    inverseFeatures.add(MapFeature.ALLOWS_NULL_KEYS);
  }

  inverseFeatures.add(NoRecurse.INVERSE);
  inverseFeatures.remove(CollectionFeature.KNOWN_ORDER);
  inverseFeatures.add(MapFeature.REJECTS_DUPLICATES_AT_CREATION);

  return inverseFeatures;
}
 
Example 7
Project: googles-monorepo-demo   File: SynchronizedSetTest.java   Source Code and License 6 votes vote down vote up
public static Test suite() {
  return SetTestSuiteBuilder.using(
          new TestStringSetGenerator() {
            @Override
            protected Set<String> create(String[] elements) {
              TestSet<String> inner = new TestSet<String>(new HashSet<String>(), null);
              Set<String> outer = Synchronized.set(inner, null);
              inner.mutex = outer;
              Collections.addAll(outer, elements);
              return outer;
            }
          })
      .named("Synchronized.set")
      .withFeatures(
          CollectionFeature.GENERAL_PURPOSE,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionSize.ANY,
          CollectionFeature.SERIALIZABLE)
      .createTestSuite();
}
 
Example 8
Project: googles-monorepo-demo   File: MultisetEntrySetTester.java   Source Code and License 6 votes vote down vote up
@CollectionSize.Require(ONE)
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
public void testEntrySet_iteratorRemovePropagates() {
  Iterator<Multiset.Entry<E>> iterator = getMultiset().entrySet().iterator();
  assertTrue(
      "non-empty multiset.entrySet() iterator.hasNext() returned false", iterator.hasNext());
  assertEquals(
      "multiset.entrySet() iterator.next() returned incorrect entry",
      Multisets.immutableEntry(e0(), 1),
      iterator.next());
  assertFalse(
      "size 1 multiset.entrySet() iterator.hasNext() returned true after next()",
      iterator.hasNext());
  iterator.remove();
  assertTrue(
      "multiset isn't empty after multiset.entrySet() iterator.remove()",
      getMultiset().isEmpty());
}
 
Example 9
Project: guava-mock   File: TestsForMapsInJavaUtil.java   Source Code and License 6 votes vote down vote up
public Test testsForUnmodifiableMap() {
  return MapTestSuiteBuilder.using(
      new TestStringMapGenerator() {
        @Override
        protected Map<String, String> create(Entry<String, String>[] entries) {
          return Collections.unmodifiableMap(toHashMap(entries));
        }
      })
      .named("unmodifiableMap/HashMap")
      .withFeatures(
          MapFeature.ALLOWS_NULL_KEYS,
          MapFeature.ALLOWS_NULL_VALUES,
          MapFeature.ALLOWS_ANY_NULL_QUERIES,
          CollectionFeature.SERIALIZABLE,
          CollectionSize.ANY)
      .suppressing(suppressForUnmodifiableMap())
      .createTestSuite();
}
 
Example 10
Project: guava-mock   File: TestsForMapsInJavaUtil.java   Source Code and License 6 votes vote down vote up
public Test testsForUnmodifiableNavigableMap() {
  return MapTestSuiteBuilder.using(
      new TestStringSortedMapGenerator() {
        @Override
        protected NavigableMap<String, String> create(Entry<String, String>[] entries) {
          return Collections.unmodifiableNavigableMap(populate(new TreeMap<>(), entries));
        }
      })
      .named("unmodifiableNavigableMap/TreeMap, natural")
      .withFeatures(
          MapFeature.ALLOWS_NULL_VALUES,
          CollectionFeature.KNOWN_ORDER,
          CollectionFeature.SERIALIZABLE,
          CollectionSize.ANY)
      .suppressing(suppressForUnmodifiableNavigableMap())
      .createTestSuite();
}
 
Example 11
Project: guava-mock   File: TestsForMapsInJavaUtil.java   Source Code and License 6 votes vote down vote up
public Test testsForConcurrentSkipListMapNatural() {
  return NavigableMapTestSuiteBuilder.using(
          new TestStringSortedMapGenerator() {
            @Override
            protected SortedMap<String, String> create(Entry<String, String>[] entries) {
              return populate(new ConcurrentSkipListMap<String, String>(), entries);
            }
          })
      .named("ConcurrentSkipListMap, natural")
      .withFeatures(
          MapFeature.GENERAL_PURPOSE,
          CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
          CollectionFeature.KNOWN_ORDER,
          CollectionFeature.SERIALIZABLE,
          CollectionSize.ANY)
      .suppressing(suppressForConcurrentSkipListMap())
      .createTestSuite();
}
 
Example 12
Project: googles-monorepo-demo   File: MinimalCollectionTest.java   Source Code and License 6 votes vote down vote up
public static Test suite() {
  return CollectionTestSuiteBuilder
      .using(new TestStringCollectionGenerator() {
          @Override public Collection<String> create(String[] elements) {
            // TODO: MinimalCollection should perhaps throw
            for (Object element : elements) {
              if (element == null) {
                throw new NullPointerException();
              }
            }
            return MinimalCollection.of(elements);
          }
        })
      .named("MinimalCollection")
      .withFeatures(
          CollectionFeature.NONE,
          CollectionSize.ANY)
      .createTestSuite();
}
 
Example 13
Project: guava-mock   File: SetHashCodeTester.java   Source Code and License 6 votes vote down vote up
@CollectionSize.Require(absent = CollectionSize.ZERO)
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
public void testHashCode_containingNull() {
  Collection<E> elements = getSampleElements(getNumElements() - 1);
  int expectedHashCode = 0;
  for (E element : elements) {
    expectedHashCode += ((element == null) ? 0 : element.hashCode());
  }

  elements.add(null);
  collection = getSubjectGenerator().create(elements.toArray());
  assertEquals(
      "A Set's hashCode() should be the sum of those of its elements (with "
          + "a null element counting as having a hash of zero).",
      expectedHashCode,
      getSet().hashCode());
}
 
Example 14
Project: googles-monorepo-demo   File: TestsForMapsInJavaUtil.java   Source Code and License 6 votes vote down vote up
/**
 * Tests regular NavigableMap behavior of synchronizedNavigableMap(treeMap);
 * does not test the fact that it's synchronized.
 */
public Test testsForSynchronizedNavigableMap() {
  return NavigableMapTestSuiteBuilder.using(
          new TestStringSortedMapGenerator() {
            @Override
            protected SortedMap<String, String> create(Entry<String, String>[] entries) {
              NavigableMap<String, String> delegate = populate(new TreeMap<>(), entries);
              return Collections.synchronizedNavigableMap(delegate);
            }
          })
      .named("synchronizedNavigableMap/TreeMap, natural")
      .withFeatures(
          MapFeature.GENERAL_PURPOSE,
          MapFeature.ALLOWS_NULL_VALUES,
          MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
          CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
          CollectionFeature.KNOWN_ORDER,
          CollectionFeature.SERIALIZABLE,
          CollectionSize.ANY)
      .suppressing(suppressForSynchronizedNavigableMap())
      .createTestSuite();
}
 
Example 15
Project: googles-monorepo-demo   File: TestsForListsInJavaUtil.java   Source Code and License 6 votes vote down vote up
public Test testsForCheckedList() {
  return ListTestSuiteBuilder.using(
          new TestStringListGenerator() {
            @Override
            public List<String> create(String[] elements) {
              List<String> innerList = new ArrayList<String>();
              Collections.addAll(innerList, elements);
              return Collections.checkedList(innerList, String.class);
            }
          })
      .named("checkedList/ArrayList")
      .withFeatures(
          ListFeature.GENERAL_PURPOSE,
          CollectionFeature.SERIALIZABLE,
          CollectionFeature.RESTRICTS_ELEMENTS,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionSize.ANY)
      .suppressing(suppressForCheckedList())
      .createTestSuite();
}
 
Example 16
Project: googles-monorepo-demo   File: TestsForSetsInJavaUtil.java   Source Code and License 6 votes vote down vote up
public Test testsForCheckedSet() {
  return SetTestSuiteBuilder.using(
          new TestStringSetGenerator() {
            @Override
            public Set<String> create(String[] elements) {
              Set<String> innerSet = new HashSet<String>();
              Collections.addAll(innerSet, elements);
              return Collections.checkedSet(innerSet, String.class);
            }
          })
      .named("checkedSet/HashSet")
      .withFeatures(
          SetFeature.GENERAL_PURPOSE,
          CollectionFeature.SERIALIZABLE,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionFeature.RESTRICTS_ELEMENTS,
          CollectionSize.ANY)
      .suppressing(suppressForCheckedSet())
      .createTestSuite();
}
 
Example 17
Project: googles-monorepo-demo   File: SetsTest.java   Source Code and License 6 votes vote down vote up
@GwtIncompatible // suite
private static Test testsForFilter() {
  return SetTestSuiteBuilder.using(new TestStringSetGenerator() {
        @Override public Set<String> create(String[] elements) {
          Set<String> unfiltered = Sets.newLinkedHashSet();
          unfiltered.add("yyy");
          Collections.addAll(unfiltered, elements);
          unfiltered.add("zzz");
          return Sets.filter(unfiltered, Collections2Test.NOT_YYY_ZZZ);
        }
      })
      .named("Sets.filter")
      .withFeatures(
          CollectionFeature.SUPPORTS_ADD,
          CollectionFeature.SUPPORTS_REMOVE,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionFeature.KNOWN_ORDER,
          CollectionSize.ANY)
      .createTestSuite();
}
 
Example 18
Project: googles-monorepo-demo   File: MultisetEntrySetTester.java   Source Code and License 6 votes vote down vote up
@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
@MultisetFeature.Require(ENTRIES_ARE_VIEWS)
public void testEntryReflectsIteratorRemove() {
  initThreeCopies();
  assertEquals(3, getMultiset().count(e0()));
  Multiset.Entry<E> entry = Iterables.getOnlyElement(getMultiset().entrySet());
  assertEquals(3, entry.getCount());
  Iterator<E> itr = getMultiset().iterator();
  itr.next();
  itr.remove();
  assertEquals(2, entry.getCount());
  itr.next();
  itr.remove();
  itr.next();
  itr.remove();
  assertEquals(0, entry.getCount());
}
 
Example 19
Project: googles-monorepo-demo   File: Collections2Test.java   Source Code and License 6 votes vote down vote up
@GwtIncompatible // suite
private static Test testsForFilter() {
  return CollectionTestSuiteBuilder.using(
      new TestStringCollectionGenerator() {
        @Override public Collection<String> create(String[] elements) {
          List<String> unfiltered = newArrayList();
          unfiltered.add("yyy");
          Collections.addAll(unfiltered, elements);
          unfiltered.add("zzz");
          return Collections2.filter(unfiltered, NOT_YYY_ZZZ);
        }
      })
      .named("Collections2.filter")
      .withFeatures(
          CollectionFeature.SUPPORTS_ADD,
          CollectionFeature.SUPPORTS_REMOVE,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionFeature.KNOWN_ORDER,
          CollectionSize.ANY)
      .createTestSuite();
}
 
Example 20
Project: guava-mock   File: TestsForSetsInJavaUtil.java   Source Code and License 6 votes vote down vote up
public Test testsForSingletonSet() {
  return SetTestSuiteBuilder.using(
          new TestStringSetGenerator() {
            @Override
            public Set<String> create(String[] elements) {
              return Collections.singleton(elements[0]);
            }
          })
      .named("singleton")
      .withFeatures(
          CollectionFeature.SERIALIZABLE,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionSize.ONE)
      .suppressing(suppressForSingletonSet())
      .createTestSuite();
}
 
Example 21
Project: googles-monorepo-demo   File: TestsForListsInJavaUtil.java   Source Code and License 6 votes vote down vote up
public Test testsForLinkedList() {
  return ListTestSuiteBuilder.using(
          new TestStringListGenerator() {
            @Override
            public List<String> create(String[] elements) {
              return new LinkedList<String>(MinimalCollection.of(elements));
            }
          })
      .named("LinkedList")
      .withFeatures(
          ListFeature.GENERAL_PURPOSE,
          CollectionFeature.SERIALIZABLE,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
          CollectionSize.ANY)
      .suppressing(suppressForLinkedList())
      .createTestSuite();
}
 
Example 22
Project: guava-mock   File: Collections2Test.java   Source Code and License 6 votes vote down vote up
@GwtIncompatible // suite
private static Test testsForFilter() {
  return CollectionTestSuiteBuilder.using(
      new TestStringCollectionGenerator() {
        @Override public Collection<String> create(String[] elements) {
          List<String> unfiltered = newArrayList();
          unfiltered.add("yyy");
          Collections.addAll(unfiltered, elements);
          unfiltered.add("zzz");
          return Collections2.filter(unfiltered, NOT_YYY_ZZZ);
        }
      })
      .named("Collections2.filter")
      .withFeatures(
          CollectionFeature.SUPPORTS_ADD,
          CollectionFeature.SUPPORTS_REMOVE,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionFeature.KNOWN_ORDER,
          CollectionSize.ANY)
      .createTestSuite();
}
 
Example 23
Project: googles-monorepo-demo   File: MultisetEntrySetTester.java   Source Code and License 5 votes vote down vote up
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testEntrySet_removeAllPresent() {
  assertTrue(
      "multiset.entrySet.removeAll(presentEntry) returned false",
      getMultiset()
          .entrySet()
          .removeAll(Collections.singleton(Multisets.immutableEntry(e0(), 1))));
  assertFalse("multiset contains element after removing its entry", getMultiset().contains(e0()));
}
 
Example 24
Project: guava-mock   File: CollectionClearTester.java   Source Code and License 5 votes vote down vote up
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testClear() {
  collection.clear();
  assertTrue("After clear(), a collection should be empty.", collection.isEmpty());
  assertEquals(0, collection.size());
  assertFalse(collection.iterator().hasNext());
}
 
Example 25
Project: guava-mock   File: MultisetIteratorTester.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@CollectionFeature.Require(absent = {SUPPORTS_ITERATOR_REMOVE, KNOWN_ORDER})
public void testIteratorUnknownOrder() {
  new IteratorTester<E>(
      4,
      UNMODIFIABLE,
      Arrays.asList(e0(), e1(), e1(), e2()),
      IteratorTester.KnownOrder.UNKNOWN_ORDER) {
    @Override
    protected Iterator<E> newTargetIterator() {
      return getSubjectGenerator().create(e0(), e1(), e1(), e2()).iterator();
    }
  }.test();
}
 
Example 26
Project: googles-monorepo-demo   File: MultisetForEachEntryTester.java   Source Code and License 5 votes vote down vote up
@CollectionFeature.Require(KNOWN_ORDER)
public void testForEachEntryOrdered() {
  List<Entry<E>> expected = new ArrayList<>(getMultiset().entrySet());
  List<Entry<E>> actual = new ArrayList<>();
  getMultiset()
      .forEachEntry((element, count) -> actual.add(Multisets.immutableEntry(element, count)));
  assertEquals(expected, actual);
}
 
Example 27
Project: guava-mock   File: CollectionRemoveAllTester.java   Source Code and License 5 votes vote down vote up
@CollectionFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_VALUES})
@CollectionSize.Require(absent = ZERO)
public void testRemoveAll_containsNullYes() {
  initCollectionWithNullElement();
  assertTrue(
      "removeAll(containsNull) should return true",
      collection.removeAll(Collections.singleton(null)));
  // TODO: make this work with MinimalCollection
}
 
Example 28
Project: googles-monorepo-demo   File: MultisetIteratorTester.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@CollectionFeature.Require(absent = {SUPPORTS_ITERATOR_REMOVE, KNOWN_ORDER})
public void testIteratorUnknownOrder() {
  new IteratorTester<E>(
      4,
      UNMODIFIABLE,
      Arrays.asList(e0(), e1(), e1(), e2()),
      IteratorTester.KnownOrder.UNKNOWN_ORDER) {
    @Override
    protected Iterator<E> newTargetIterator() {
      return getSubjectGenerator().create(e0(), e1(), e1(), e2()).iterator();
    }
  }.test();
}
 
Example 29
Project: googles-monorepo-demo   File: CollectionAddTester.java   Source Code and License 5 votes vote down vote up
@CollectionFeature.Require({SUPPORTS_ADD, FAILS_FAST_ON_CONCURRENT_MODIFICATION})
@CollectionSize.Require(absent = ZERO)
public void testAddConcurrentWithIteration() {
  try {
    Iterator<E> iterator = collection.iterator();
    assertTrue(collection.add(e3()));
    iterator.next();
    fail("Expected ConcurrentModificationException");
  } catch (ConcurrentModificationException expected) {
    // success
  }
}
 
Example 30
Project: googles-monorepo-demo   File: CollectionToStringTester.java   Source Code and License 5 votes vote down vote up
@CollectionSize.Require(ONE)
@CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
public void testToString_size1() {
  assertEquals(
      "size1Collection.toString should return [{element}]",
      "[" + e0() + "]",
      collection.toString());
}
 
Example 31
Project: guava-mock   File: ListRemoveAllTester.java   Source Code and License 5 votes vote down vote up
@CollectionFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testRemoveAll_duplicate() {
  ArrayWithDuplicate<E> arrayAndDuplicate = createArrayWithDuplicateElement();
  collection = getSubjectGenerator().create(arrayAndDuplicate.elements);
  E duplicate = arrayAndDuplicate.duplicate;

  assertTrue(
      "removeAll(intersectingCollection) should return true",
      getList().removeAll(MinimalCollection.of(duplicate)));
  assertFalse(
      "after removeAll(e), a collection should not contain e even "
          + "if it initially contained e more than once.",
      getList().contains(duplicate));
}
 
Example 32
Project: guava-mock   File: MultisetRemoveTester.java   Source Code and License 5 votes vote down vote up
@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testRemoveAllIgnoresCount() {
  initThreeCopies();
  assertTrue(getMultiset().removeAll(Collections.singleton(e0())));
  assertEmpty(getMultiset());
}
 
Example 33
Project: guava-mock   File: SetAddTester.java   Source Code and License 5 votes vote down vote up
@CollectionFeature.Require(value = {SUPPORTS_ADD, ALLOWS_NULL_VALUES})
@CollectionSize.Require(absent = ZERO)
public void testAdd_supportedNullPresent() {
  E[] array = createArrayWithNullElement();
  collection = getSubjectGenerator().create(array);
  assertFalse("add(nullPresent) should return false", getSet().add(null));
  expectContents(array);
}
 
Example 34
Project: googles-monorepo-demo   File: AbstractMultisetSetCountTester.java   Source Code and License 5 votes vote down vote up
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
public void testSetCount_existingNoNopNull_nullSupported() {
  initCollectionWithNullElement();
  try {
    assertSetCount(null, 1);
  } catch (UnsupportedOperationException tolerated) {
  }
}
 
Example 35
Project: guava-mock   File: CollectionSpliteratorTester.java   Source Code and License 5 votes vote down vote up
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testSpliteratorNotImmutable_CollectionAllowsRemove() {
  // If remove is supported, verify that IMMUTABLE is not reported.
  synchronized (collection) { // for Collections.synchronized
    assertFalse(collection.spliterator().hasCharacteristics(Spliterator.IMMUTABLE));
  }
}
 
Example 36
Project: googles-monorepo-demo   File: SetCreationTester.java   Source Code and License 5 votes vote down vote up
@CollectionFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testCreateWithDuplicates_nonNullDuplicatesNotRejected() {
  E[] array = createSamplesArray();
  array[1] = e0();
  collection = getSubjectGenerator().create(array);

  List<E> expectedWithDuplicateRemoved = Arrays.asList(array).subList(1, getNumElements());
  expectContents(expectedWithDuplicateRemoved);
}
 
Example 37
Project: guava-mock   File: MultisetElementSetTester.java   Source Code and License 5 votes vote down vote up
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testElementSetRemovePropagatesToMultiset() {
  Set<E> elementSet = getMultiset().elementSet();
  assertTrue(elementSet.remove(e0()));
  assertFalse(getMultiset().contains(e0()));
}
 
Example 38
Project: googles-monorepo-demo   File: MultimapKeySetTester.java   Source Code and License 5 votes vote down vote up
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
public void testKeySetIteratorRemove() {
  int key0Count = multimap().get(k0()).size();
  Iterator<K> keyItr = multimap().keySet().iterator();
  while (keyItr.hasNext()) {
    if (keyItr.next().equals(k0())) {
      keyItr.remove();
    }
  }
  assertEquals(getNumElements() - key0Count, multimap().size());
  assertGet(k0());
}
 
Example 39
Project: guava-mock   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testClearTailClosed() {
  List<Entry<E>> expected =
      copyToList(sortedMultiset.headMultiset(b.getElement(), OPEN).entrySet());
  sortedMultiset.tailMultiset(b.getElement(), CLOSED).clear();
  assertEquals(expected, copyToList(sortedMultiset.entrySet()));
}
 
Example 40
Project: googles-monorepo-demo   File: SetCreationTester.java   Source Code and License 5 votes vote down vote up
@CollectionFeature.Require(value = ALLOWS_NULL_VALUES, absent = REJECTS_DUPLICATES_AT_CREATION)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testCreateWithDuplicates_nullDuplicatesNotRejected() {
  E[] array = createArrayWithNullElement();
  array[0] = null;
  collection = getSubjectGenerator().create(array);

  List<E> expectedWithDuplicateRemoved = Arrays.asList(array).subList(1, getNumElements());
  expectContents(expectedWithDuplicateRemoved);
}