本文整理汇总了Java中com.google.common.collect.testing.features.CollectionFeature类的典型用法代码示例。如果您正苦于以下问题:Java CollectionFeature类的具体用法?Java CollectionFeature怎么用?Java CollectionFeature使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CollectionFeature类属于com.google.common.collect.testing.features包,在下文中一共展示了CollectionFeature类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testsForArraysAsList
import com.google.common.collect.testing.features.CollectionFeature; //导入依赖的package包/类
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();
}
示例2: testHashCode_containingNull
import com.google.common.collect.testing.features.CollectionFeature; //导入依赖的package包/类
@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());
}
示例3: testConflictingBounds
import com.google.common.collect.testing.features.CollectionFeature; //导入依赖的package包/类
@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));
}
示例4: testsForConcurrentSkipListSetWithComparator
import com.google.common.collect.testing.features.CollectionFeature; //导入依赖的package包/类
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();
}
示例5: testsForCheckedNavigableMap
import com.google.common.collect.testing.features.CollectionFeature; //导入依赖的package包/类
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();
}
示例6: computeInverseFeatures
import com.google.common.collect.testing.features.CollectionFeature; //导入依赖的package包/类
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;
}
示例7: suite
import com.google.common.collect.testing.features.CollectionFeature; //导入依赖的package包/类
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();
}
示例8: testEntrySet_iteratorRemovePropagates
import com.google.common.collect.testing.features.CollectionFeature; //导入依赖的package包/类
@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());
}
示例9: testsForUnmodifiableMap
import com.google.common.collect.testing.features.CollectionFeature; //导入依赖的package包/类
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();
}
示例10: testsForUnmodifiableNavigableMap
import com.google.common.collect.testing.features.CollectionFeature; //导入依赖的package包/类
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();
}
示例11: testsForConcurrentSkipListMapNatural
import com.google.common.collect.testing.features.CollectionFeature; //导入依赖的package包/类
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();
}
示例12: suite
import com.google.common.collect.testing.features.CollectionFeature; //导入依赖的package包/类
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();
}
示例13: testsForSynchronizedNavigableMap
import com.google.common.collect.testing.features.CollectionFeature; //导入依赖的package包/类
/**
* 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();
}
示例14: testsForCheckedList
import com.google.common.collect.testing.features.CollectionFeature; //导入依赖的package包/类
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();
}
示例15: testsForCheckedSet
import com.google.common.collect.testing.features.CollectionFeature; //导入依赖的package包/类
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();
}