本文整理汇总了Java中com.google.common.collect.testing.features.CollectionSize类的典型用法代码示例。如果您正苦于以下问题:Java CollectionSize类的具体用法?Java CollectionSize怎么用?Java CollectionSize使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CollectionSize类属于com.google.common.collect.testing.features包,在下文中一共展示了CollectionSize类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testsForSingletonSet
import com.google.common.collect.testing.features.CollectionSize; //导入依赖的package包/类
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();
}
示例2: testsForCheckedList
import com.google.common.collect.testing.features.CollectionSize; //导入依赖的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();
}
示例3: testIterator_removeAffectsBackingCollection
import com.google.common.collect.testing.features.CollectionSize; //导入依赖的package包/类
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testIterator_removeAffectsBackingCollection() {
int originalSize = collection.size();
Iterator<E> iterator = collection.iterator();
Object element = iterator.next();
// If it's an Entry, it may become invalid once it's removed from the Map. Copy it.
if (element instanceof Entry) {
Entry<?, ?> entry = (Entry<?, ?>) element;
element = mapEntry(entry.getKey(), entry.getValue());
}
assertTrue(collection.contains(element)); // sanity check
iterator.remove();
assertFalse(collection.contains(element));
assertEquals(originalSize - 1, collection.size());
}
示例4: testsForSingletonList
import com.google.common.collect.testing.features.CollectionSize; //导入依赖的package包/类
public Test testsForSingletonList() {
return ListTestSuiteBuilder.using(
new TestStringListGenerator() {
@Override
public List<String> create(String[] elements) {
return Collections.singletonList(elements[0]);
}
})
.named("singletonList")
.withFeatures(
CollectionFeature.SERIALIZABLE,
CollectionFeature.ALLOWS_NULL_VALUES,
CollectionSize.ONE)
.suppressing(suppressForSingletonList())
.createTestSuite();
}
示例5: testsForTreeMapWithComparator
import com.google.common.collect.testing.features.CollectionSize; //导入依赖的package包/类
public Test testsForTreeMapWithComparator() {
return NavigableMapTestSuiteBuilder.using(
new TestStringSortedMapGenerator() {
@Override
protected SortedMap<String, String> create(Entry<String, String>[] entries) {
return populate(
new TreeMap<String, String>(arbitraryNullFriendlyComparator()), entries);
}
})
.named("TreeMap, with comparator")
.withFeatures(
MapFeature.GENERAL_PURPOSE,
MapFeature.ALLOWS_NULL_KEYS,
MapFeature.ALLOWS_NULL_VALUES,
MapFeature.ALLOWS_ANY_NULL_QUERIES,
MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
CollectionFeature.KNOWN_ORDER,
CollectionFeature.SERIALIZABLE,
CollectionSize.ANY)
.suppressing(suppressForTreeMapWithComparator())
.createTestSuite();
}
示例6: suite
import com.google.common.collect.testing.features.CollectionSize; //导入依赖的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();
}
示例7: testsForConcurrentSkipListMapWithComparator
import com.google.common.collect.testing.features.CollectionSize; //导入依赖的package包/类
public Test testsForConcurrentSkipListMapWithComparator() {
return NavigableMapTestSuiteBuilder.using(
new TestStringSortedMapGenerator() {
@Override
protected SortedMap<String, String> create(Entry<String, String>[] entries) {
return populate(
new ConcurrentSkipListMap<String, String>(arbitraryNullFriendlyComparator()),
entries);
}
})
.named("ConcurrentSkipListMap, with comparator")
.withFeatures(
MapFeature.GENERAL_PURPOSE,
CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
CollectionFeature.KNOWN_ORDER,
CollectionFeature.SERIALIZABLE,
CollectionSize.ANY)
.suppressing(suppressForConcurrentSkipListMap())
.createTestSuite();
}
示例8: testsForArrayDeque
import com.google.common.collect.testing.features.CollectionSize; //导入依赖的package包/类
public Test testsForArrayDeque() {
return QueueTestSuiteBuilder.using(
new TestStringQueueGenerator() {
@Override
public Queue<String> create(String[] elements) {
return new ArrayDeque<String>(MinimalCollection.of(elements));
}
})
.named("ArrayDeque")
.withFeatures(
CollectionFeature.GENERAL_PURPOSE,
CollectionFeature.KNOWN_ORDER,
CollectionSize.ANY)
.suppressing(suppressForArrayDeque())
.createTestSuite();
}
示例9: testsForFilter
import com.google.common.collect.testing.features.CollectionSize; //导入依赖的package包/类
@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();
}
示例10: testsForEnumSet
import com.google.common.collect.testing.features.CollectionSize; //导入依赖的package包/类
public Test testsForEnumSet() {
return SetTestSuiteBuilder.using(
new TestEnumSetGenerator() {
@Override
public Set<AnEnum> create(AnEnum[] elements) {
return (elements.length == 0)
? EnumSet.noneOf(AnEnum.class)
: EnumSet.copyOf(MinimalCollection.of(elements));
}
})
.named("EnumSet")
.withFeatures(
SetFeature.GENERAL_PURPOSE,
CollectionFeature.SERIALIZABLE,
CollectionFeature.KNOWN_ORDER,
CollectionFeature.RESTRICTS_ELEMENTS,
CollectionSize.ANY)
.suppressing(suppressForEnumSet())
.createTestSuite();
}
示例11: testCompute_presentToAbsent
import com.google.common.collect.testing.features.CollectionSize; //导入依赖的package包/类
@MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
@CollectionSize.Require(absent = ZERO)
public void testCompute_presentToAbsent() {
assertNull(
"Map.compute(present, functionReturningNull) should return null",
getMap()
.compute(
k0(),
(k, v)
-> {
assertEquals(k0(), k);
assertEquals(v0(), v);
return null;
}));
expectMissing(e0());
expectMissingKeys(k0());
assertEquals(getNumElements() - 1, getMap().size());
}
示例12: testsForLinkedList
import com.google.common.collect.testing.features.CollectionSize; //导入依赖的package包/类
public Test testsForLinkedList() {
return QueueTestSuiteBuilder.using(
new TestStringQueueGenerator() {
@Override
public Queue<String> create(String[] elements) {
return new LinkedList<String>(MinimalCollection.of(elements));
}
})
.named("LinkedList")
.withFeatures(
CollectionFeature.GENERAL_PURPOSE,
CollectionFeature.ALLOWS_NULL_VALUES,
CollectionFeature.KNOWN_ORDER,
CollectionSize.ANY)
.skipCollectionTests() // already covered in TestsForListsInJavaUtil
.suppressing(suppressForLinkedList())
.createTestSuite();
}
示例13: testComputeIfPresent_nullKeySupportedPresent
import com.google.common.collect.testing.features.CollectionSize; //导入依赖的package包/类
@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_KEYS})
@CollectionSize.Require(absent = ZERO)
public void testComputeIfPresent_nullKeySupportedPresent() {
initMapWithNullKey();
assertEquals(
"computeIfPresent(null, function) should return new value",
v3(),
getMap()
.computeIfPresent(
null,
(k, v) -> {
assertNull(k);
assertEquals(getValueForNullKey(), v);
return v3();
}));
Entry<K, V>[] expected = createArrayWithNullKey();
expected[getNullLocation()] = entry(null, v3());
expectContents(expected);
}
示例14: testSubList_subListRemoveAffectsOriginal
import com.google.common.collect.testing.features.CollectionSize; //导入依赖的package包/类
@ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testSubList_subListRemoveAffectsOriginal() {
List<E> subList = getList().subList(0, 1);
subList.remove(0);
List<E> expected = Arrays.asList(createSamplesArray()).subList(1, getNumElements());
expectContents(expected);
}
示例15: testInversePut
import com.google.common.collect.testing.features.CollectionSize; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(ZERO)
public void testInversePut() {
getMap().put(k0(), v0());
getMap().inverse().put(v1(), k1());
expectAdded(e0(), e1());
}