本文整理汇总了Java中com.google.common.collect.testing.features.MapFeature.Require方法的典型用法代码示例。如果您正苦于以下问题:Java MapFeature.Require方法的具体用法?Java MapFeature.Require怎么用?Java MapFeature.Require使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.testing.features.MapFeature
的用法示例。
在下文中一共展示了MapFeature.Require方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCompute_absentFunctionThrows
import com.google.common.collect.testing.features.MapFeature; //导入方法依赖的package包/类
@MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
public void testCompute_absentFunctionThrows() {
try {
getMap()
.compute(
k3(),
(k, v) -> {
assertEquals(k3(), k);
assertNull(v);
throw new ExpectedException();
});
fail("Expected ExpectedException");
} catch (ExpectedException expected) {
}
expectUnchanged();
}
示例2: testPutDuplicateValue
import com.google.common.collect.testing.features.MapFeature; //导入方法依赖的package包/类
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
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();
List<V> values = multimap().get(k);
List<V> expectedValues = copyToList(values);
assertTrue(multimap().put(k, v));
expectedValues.add(v);
assertGet(k, expectedValues);
assertEquals(v, values.get(values.size() - 1));
}
}
示例3: 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());
}
示例4: testPutPresentKeyPropagatesToGet
import com.google.common.collect.testing.features.MapFeature; //导入方法依赖的package包/类
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testPutPresentKeyPropagatesToGet() {
List<K> keys = Helpers.copyToList(multimap().keySet());
for (K key : keys) {
resetContainer();
int size = getNumElements();
Collection<V> collection = multimap().get(key);
Collection<V> expectedCollection = Helpers.copyToList(collection);
multimap().put(key, v3());
expectedCollection.add(v3());
assertEqualIgnoringOrder(expectedCollection, collection);
assertEquals(size + 1, multimap().size());
}
}
示例5: testClearPropagatesToGet
import com.google.common.collect.testing.features.MapFeature; //导入方法依赖的package包/类
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testClearPropagatesToGet() {
for (K key : sampleKeys()) {
resetContainer();
Collection<V> collection = multimap().get(key);
multimap().clear();
assertEmpty(collection);
}
}
示例6: testComputeIfAbsent_supportedPresent
import com.google.common.collect.testing.features.MapFeature; //导入方法依赖的package包/类
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testComputeIfAbsent_supportedPresent() {
assertEquals("computeIfAbsent(present, function) should return existing value",
v0(), getMap().computeIfAbsent(k0(), k -> { throw new AssertionFailedError(); }));
expectUnchanged();
}
示例7: testKeySetClearClearsInverse
import com.google.common.collect.testing.features.MapFeature; //导入方法依赖的package包/类
@MapFeature.Require(SUPPORTS_REMOVE)
public void testKeySetClearClearsInverse() {
BiMap<V, K> inv = getMap().inverse();
getMap().keySet().clear();
assertTrue(getMap().isEmpty());
assertTrue(inv.isEmpty());
}
示例8: testCreateWithNullKeyAndValueSupported
import com.google.common.collect.testing.features.MapFeature; //导入方法依赖的package包/类
@MapFeature.Require({ALLOWS_NULL_KEYS, ALLOWS_NULL_VALUES})
@CollectionSize.Require(absent = ZERO)
public void testCreateWithNullKeyAndValueSupported() {
Entry<K, V>[] entries = createSamplesArray();
entries[getNullLocation()] = entry(null, null);
resetMap(entries);
expectContents(entries);
}
示例9: testReplace_presentNullValueUnsupported
import com.google.common.collect.testing.features.MapFeature; //导入方法依赖的package包/类
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES)
@CollectionSize.Require(absent = ZERO)
public void testReplace_presentNullValueUnsupported() {
try {
getMap().replace(k0(), null);
fail("Expected NullPointerException");
} catch (NullPointerException expected) {
}
expectUnchanged();
}
示例10: testAsMapRemoveImplementsList
import com.google.common.collect.testing.features.MapFeature; //导入方法依赖的package包/类
@MapFeature.Require(SUPPORTS_REMOVE)
public void testAsMapRemoveImplementsList() {
List<K> keys = new ArrayList<K>(multimap().keySet());
for (K key : keys) {
resetCollection();
assertTrue(multimap().asMap().remove(key) instanceof List);
}
}
示例11: testPutAllRejectsNullValue
import com.google.common.collect.testing.features.MapFeature; //导入方法依赖的package包/类
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES)
public void testPutAllRejectsNullValue() {
Multimap<K, V> source = getSubjectGenerator().create(Helpers.mapEntry(k0(), null));
try {
multimap().putAll(source);
fail("Expected NullPointerException");
} catch (NullPointerException expected) {
}
expectUnchanged();
}
示例12: testAddNullValue
import com.google.common.collect.testing.features.MapFeature; //导入方法依赖的package包/类
@CollectionSize.Require(absent = ZERO)
@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES})
public void testAddNullValue() {
Collection<V> result = multimap().asMap().get(k0());
assertTrue(result.add(null));
assertTrue(multimap().containsEntry(k0(), null));
}
示例13: testSizeNullKeyAndValue
import com.google.common.collect.testing.features.MapFeature; //导入方法依赖的package包/类
@CollectionSize.Require(absent = ZERO)
@MapFeature.Require({ALLOWS_NULL_KEYS, ALLOWS_NULL_VALUES})
public void testSizeNullKeyAndValue() {
initMultimapWithNullKeyAndValue();
assertEquals(getNumElements(), multimap().size());
assertFalse(multimap().isEmpty());
}
示例14: testReplaceAll_unsupportedNoOpFunction
import com.google.common.collect.testing.features.MapFeature; //导入方法依赖的package包/类
@MapFeature.Require(absent = SUPPORTS_PUT)
public void testReplaceAll_unsupportedNoOpFunction() {
try {
getMap().replaceAll((K k, V v) -> v);
} catch (UnsupportedOperationException tolerated) {
}
expectUnchanged();
}
示例15: testRemoveNullValueForbidden
import com.google.common.collect.testing.features.MapFeature; //导入方法依赖的package包/类
@MapFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_VALUE_QUERIES)
public void testRemoveNullValueForbidden() {
try {
multimap().remove(k0(), null);
fail("Expected NullPointerException");
} catch (NullPointerException expected) {
// success
}
expectUnchanged();
}