本文整理汇总了Java中com.google.common.collect.testing.features.MapFeature类的典型用法代码示例。如果您正苦于以下问题:Java MapFeature类的具体用法?Java MapFeature怎么用?Java MapFeature使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MapFeature类属于com.google.common.collect.testing.features包,在下文中一共展示了MapFeature类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPutAllNullValueNullLast_unsupported
import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES)
public void testPutAllNullValueNullLast_unsupported() {
int size = getNumElements();
try {
multimap().putAll(k3(), Lists.newArrayList(v3(), null));
fail();
} catch (NullPointerException expected) {
}
Collection<V> values = multimap().get(k3());
if (values.size() == 0) {
expectUnchanged();
// Be extra thorough in case internal state was corrupted by the expected null.
assertEquals(Lists.newArrayList(), Lists.newArrayList(values));
assertEquals(size, multimap().size());
} else {
assertEquals(Lists.newArrayList(v3()), Lists.newArrayList(values));
assertEquals(size + 1, multimap().size());
}
}
示例2: testsForTreeMapNatural
import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
public Test testsForTreeMapNatural() {
return NavigableMapTestSuiteBuilder.using(
new TestStringSortedMapGenerator() {
@Override
protected SortedMap<String, String> create(Entry<String, String>[] entries) {
/*
* TODO(cpovirk): it would be nice to create an input Map and use
* the copy constructor here and in the other tests
*/
return populate(new TreeMap<String, String>(), entries);
}
})
.named("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(suppressForTreeMapNatural())
.createTestSuite();
}
示例3: testsForUnmodifiableNavigableMap
import com.google.common.collect.testing.features.MapFeature; //导入依赖的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();
}
示例4: testsForConcurrentSkipListMapNatural
import com.google.common.collect.testing.features.MapFeature; //导入依赖的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();
}
示例5: testsForConcurrentSkipListMapWithComparator
import com.google.common.collect.testing.features.MapFeature; //导入依赖的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();
}
示例6: testsForEnumMap
import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
public Test testsForEnumMap() {
return MapTestSuiteBuilder.using(
new TestEnumMapGenerator() {
@Override
protected Map<AnEnum, String> create(Entry<AnEnum, String>[] entries) {
return populate(new EnumMap<AnEnum, String>(AnEnum.class), entries);
}
})
.named("EnumMap")
.withFeatures(
MapFeature.GENERAL_PURPOSE,
MapFeature.ALLOWS_NULL_VALUES,
MapFeature.RESTRICTS_KEYS,
CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
CollectionFeature.KNOWN_ORDER,
CollectionFeature.SERIALIZABLE,
CollectionSize.ANY)
.suppressing(suppressForEnumMap())
.createTestSuite();
}
示例7: testCompute_presentToAbsent
import com.google.common.collect.testing.features.MapFeature; //导入依赖的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());
}
示例8: testPutDuplicateValue
import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
@MapFeature.Require(SUPPORTS_PUT)
public void testPutDuplicateValue() {
List<Entry<K, V>> entries = copyToList(multimap().entries());
for (Entry<K, V> entry : entries) {
resetContainer();
K k = entry.getKey();
V v = entry.getValue();
Set<V> values = multimap().get(k);
Set<V> expectedValues = copyToSet(values);
assertFalse(multimap().put(k, v));
assertEquals(expectedValues, values);
assertGet(k, expectedValues);
}
}
示例9: testPropagatesRemoveThenAddToMultimap
import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
@CollectionSize.Require(absent = ZERO)
@MapFeature.Require({SUPPORTS_REMOVE, SUPPORTS_PUT})
public void testPropagatesRemoveThenAddToMultimap() {
int oldSize = getNumElements();
Collection<V> result = multimap().asMap().get(k0());
assertTrue(result.remove(v0()));
assertFalse(multimap().containsKey(k0()));
assertFalse(multimap().containsEntry(k0(), v0()));
assertEmpty(result);
assertTrue(result.add(v1()));
assertTrue(result.add(v2()));
assertContentsAnyOrder(result, v1(), v2());
assertContentsAnyOrder(multimap().get(k0()), v1(), v2());
assertTrue(multimap().containsKey(k0()));
assertFalse(multimap().containsEntry(k0(), v0()));
assertTrue(multimap().containsEntry(k0(), v2()));
assertEquals(oldSize + 1, multimap().size());
}
示例10: testMergePresentToNull
import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testMergePresentToNull() {
assertNull(
"Map.merge(present, value, functionReturningNull) should return null",
getMap()
.merge(
k0(),
v3(),
(oldV, newV) -> {
assertEquals(v0(), oldV);
assertEquals(v3(), newV);
return null;
}));
expectMissing(e0());
}
示例11: testRemovePropagatesToGet
import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemovePropagatesToGet() {
List<Entry<K, V>> entries = Helpers.copyToList(multimap().entries());
for (Entry<K, V> entry : entries) {
resetContainer();
K key = entry.getKey();
V value = entry.getValue();
Collection<V> collection = multimap().get(key);
assertNotNull(collection);
Collection<V> expectedCollection = Helpers.copyToList(collection);
multimap().remove(key, value);
expectedCollection.remove(value);
assertEqualIgnoringOrder(expectedCollection, collection);
assertEquals(!expectedCollection.isEmpty(), multimap().containsKey(key));
}
}
示例12: testsForUnmodifiableSortedMap
import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
public Test testsForUnmodifiableSortedMap() {
return MapTestSuiteBuilder.using(
new TestStringSortedMapGenerator() {
@Override
protected SortedMap<String, String> create(Entry<String, String>[] entries) {
SortedMap<String, String> map = populate(new TreeMap<String, String>(), entries);
return Collections.unmodifiableSortedMap(map);
}
})
.named("unmodifiableSortedMap/TreeMap, natural")
.withFeatures(
MapFeature.ALLOWS_NULL_VALUES,
CollectionFeature.KNOWN_ORDER,
CollectionFeature.SERIALIZABLE,
CollectionSize.ANY)
.suppressing(suppressForUnmodifiableSortedMap())
.createTestSuite();
}
示例13: testMappedToNull
import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES})
@CollectionSize.Require(absent = ZERO)
public void testMappedToNull() {
initMapWithNullValue();
assertEquals(
"Map.merge(keyMappedToNull, value, function) should return value",
v3(),
getMap()
.merge(
getKeyForNullValue(),
v3(),
(oldV, newV) -> {
throw new AssertionFailedError(
"Should not call merge function if key was mapped to null");
}));
expectReplacement(entry(getKeyForNullValue(), v3()));
}
示例14: testCompute_presentNullToPresentNonnull
import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
@MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE, ALLOWS_NULL_VALUES})
@CollectionSize.Require(absent = ZERO)
public void testCompute_presentNullToPresentNonnull() {
initMapWithNullValue();
V value = getValueForNullKey();
assertEquals(
"Map.compute(presentMappedToNull, functionReturningValue) should return new value",
value,
getMap()
.compute(
getKeyForNullValue(),
(k, v)
-> {
assertEquals(getKeyForNullValue(), k);
assertNull(v);
return value;
}));
expectReplacement(entry(getKeyForNullValue(), value));
assertEquals(getNumElements(), getMap().size());
}
示例15: putDistinctKeysDistinctValues
import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(ZERO)
public void putDistinctKeysDistinctValues() {
getMap().put(k0(), v0());
getMap().put(k1(), v1());
expectAdded(e0(), e1());
}