@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());
}
}
项目:guava-mock
文件:TestsForMapsInJavaUtil.java
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();
}
项目:guava-mock
文件:TestsForMapsInJavaUtil.java
public Test testsForUnmodifiableNavigableMap() {
return MapTestSuiteBuilder.using(
new TestStringSortedMapGenerator() {
@Override
protected NavigableMap<String,String>[] entries) {
return Collections.unmodifiableNavigableMap(populate(new TreeMap<>(),entries));
}
})
.named("unmodifiableNavigableMap/TreeMap,natural")
.withFeatures(
MapFeature.ALLOWS_NULL_VALUES,CollectionSize.ANY)
.suppressing(suppressForUnmodifiableNavigableMap())
.createTestSuite();
}
项目:guava-mock
文件:TestsForMapsInJavaUtil.java
public Test testsForconcurrentskiplistmapNatural() {
return NavigableMapTestSuiteBuilder.using(
new TestStringSortedMapGenerator() {
@Override
protected SortedMap<String,String>[] entries) {
return populate(new concurrentskiplistmap<String,entries);
}
})
.named("concurrentskiplistmap,CollectionSize.ANY)
.suppressing(suppressForconcurrentskiplistmap())
.createTestSuite();
}
项目:guava-mock
文件:TestsForMapsInJavaUtil.java
public Test testsForconcurrentskiplistmapWithComparator() {
return NavigableMapTestSuiteBuilder.using(
new TestStringSortedMapGenerator() {
@Override
protected SortedMap<String,String>[] entries) {
return populate(
new concurrentskiplistmap<String,String>(arbitraryNullFriendlyComparator()),with comparator")
.withFeatures(
MapFeature.GENERAL_PURPOSE,CollectionSize.ANY)
.suppressing(suppressForconcurrentskiplistmap())
.createTestSuite();
}
public Test testsForUnmodifiableNavigableMap() {
return MapTestSuiteBuilder.using(
new TestStringSortedMapGenerator() {
@Override
protected NavigableMap<String,CollectionSize.ANY)
.suppressing(suppressForUnmodifiableNavigableMap())
.createTestSuite();
}
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.RESTRICTS_KEYS,CollectionSize.ANY)
.suppressing(suppressForEnumMap())
.createTestSuite();
}
@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());
}
项目:guava-mock
文件:SetMultimapPutTester.java
@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);
}
}
项目:guava-mock
文件:MultimapAsMapGetTester.java
@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()),v2());
assertTrue(multimap().containsKey(k0()));
assertFalse(multimap().containsEntry(k0(),v0()));
assertTrue(multimap().containsEntry(k0(),v2()));
assertEquals(oldSize + 1,multimap().size());
}
项目:guava-mock
文件:MapMergeTester.java
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testMergePresentToNull() {
assertNull(
"Map.merge(present,value,getMap()
.merge(
k0(),v3(),(oldV,newV) -> {
assertEquals(v0(),oldV);
assertEquals(v3(),newV);
return null;
}));
expectMissing(e0());
}
项目:guava-mock
文件:MultimapRemoveEntryTester.java
@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));
}
}
public Test testsForUnmodifiableSortedMap() {
return MapTestSuiteBuilder.using(
new TestStringSortedMapGenerator() {
@Override
protected SortedMap<String,String>[] entries) {
SortedMap<String,String> map = populate(new TreeMap<String,entries);
return Collections.unmodifiableSortedMap(map);
}
})
.named("unmodifiableSortedMap/TreeMap,CollectionSize.ANY)
.suppressing(suppressForUnmodifiableSortedMap())
.createTestSuite();
}
项目:guava-mock
文件:MapMergeTester.java
@MapFeature.Require({SUPPORTS_PUT,ALLOWS_NULL_VALUES})
@CollectionSize.Require(absent = ZERO)
public void testMappedToNull() {
initMapWithNullValue();
assertEquals(
"Map.merge(keyMappedToNull,function) should return value",getMap()
.merge(
getKeyForNullValue(),newV) -> {
throw new AssertionFailedError(
"Should not call merge function if key was mapped to null");
}));
expectReplacement(entry(getKeyForNullValue(),v3()));
}
@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",getMap()
.compute(
getKeyForNullValue(),v)
-> {
assertEquals(getKeyForNullValue(),k);
assertNull(v);
return value;
}));
expectReplacement(entry(getKeyForNullValue(),value));
assertEquals(getNumElements(),getMap().size());
}
private static Set<Feature<?>> computeValuesCollectionFeatures(Set<Feature<?>> mapFeatures) {
Set<Feature<?>> valuesCollectionFeatures = computeCommonDerivedCollectionFeatures(mapFeatures);
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUE_QUERIES)) {
valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
}
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUES)) {
valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES);
}
return valuesCollectionFeatures;
}
@MapFeature.Require(absent = ALLOWS_NULL_KEY_QUERIES)
public void testGet_nullNotContainedAndUnsupported() {
try {
assertNull("get(null) should return null or throw",get(null));
} catch (NullPointerException tolerated) {
}
}
项目:guava-mock
文件:MultimapTestSuiteBuilder.java
static Set<Feature<?>> computeKeysFeatures(Set<Feature<?>> multimapFeatures) {
Set<Feature<?>> result = computeDerivedCollectionFeatures(multimapFeatures);
if (multimapFeatures.contains(MapFeature.ALLOWS_NULL_KEYS)) {
result.add(CollectionFeature.ALLOWS_NULL_VALUES);
}
if (multimapFeatures.contains(MapFeature.ALLOWS_NULL_KEY_QUERIES)) {
result.add(CollectionFeature.ALLOWS_NULL_QUERIES);
}
return result;
}
项目:guava-mock
文件:ConcurrentMapPutIfAbsentTester.java
@MapFeature.Require(absent = SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testPutIfAbsent_unsupportedPresentExistingValue() {
try {
assertEquals(
"putIfAbsent(present,existingValue) should return present or throw",v0(),putIfAbsent(e0()));
} catch (UnsupportedOperationException tolerated) {
}
expectUnchanged();
}
@MapFeature.Require(value = SUPPORTS_PUT,absent = ALLOWS_NULL_KEY_QUERIES)
public void testReplace_absentNullKeyUnsupported() {
try {
getMap().replace(null,v3());
} catch (NullPointerException tolerated) {
// permitted not to throw because it would be a no-op
}
expectUnchanged();
}
@MapFeature.Require(value = SUPPORTS_PUT,absent = ALLOWS_NULL_KEYS)
public void testPutIfAbsent_nullKeyUnsupported() {
try {
getMap().putIfAbsent(null,v3());
fail("putIfAbsent(null,value) should throw");
} catch (NullPointerException expected) {
}
expectUnchanged();
expectNullKeyMissingWhenNullKeysUnsupported(
"Should not contain null key after unsupported putIfAbsent(null,value)");
}
项目:guava-mock
文件:MultimapTestSuiteBuilder.java
@MapFeature.Require(absent = SUPPORTS_PUT)
public void testReplaceEntry_unsupportedAbsentKey() {
try {
getMap().replace(k3(),v4());
} catch (UnsupportedOperationException tolerated) {
// the operation would be a no-op,so exceptions are allowed but not required
}
expectUnchanged();
}
@MapFeature.Require(SUPPORTS_REMOVE)
public void testValuesClearClearsInverse() {
BiMap<V,K> inv = getMap().inverse();
getMap().values().clear();
assertTrue(getMap().isEmpty());
assertTrue(inv.isEmpty());
}
@MapFeature.Require(absent = SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemove_unsupportedPresent() {
try {
getMap().remove(k0(),v0());
fail("Expected UnsupportedOperationException");
} catch (UnsupportedOperationException expected) {}
expectUnchanged();
}
项目:guava-mock
文件:MapTestSuiteBuilder.java
private static Set<Feature<?>> computeValuesCollectionFeatures(Set<Feature<?>> mapFeatures) {
Set<Feature<?>> valuesCollectionFeatures = computeCommonDerivedCollectionFeatures(mapFeatures);
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUE_QUERIES)) {
valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
}
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUES)) {
valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES);
}
return valuesCollectionFeatures;
}
项目:guava-mock
文件:MapTestSuiteBuilder.java
public static Set<Feature<?>> computeCommonDerivedCollectionFeatures(
Set<Feature<?>> mapFeatures) {
mapFeatures = new HashSet<Feature<?>>(mapFeatures);
Set<Feature<?>> derivedFeatures = new HashSet<Feature<?>>();
mapFeatures.remove(CollectionFeature.SERIALIZABLE);
if (mapFeatures.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
derivedFeatures.add(CollectionFeature.SERIALIZABLE);
}
if (mapFeatures.contains(MapFeature.SUPPORTS_REMOVE)) {
derivedFeatures.add(CollectionFeature.SUPPORTS_REMOVE);
}
if (mapFeatures.contains(MapFeature.REJECTS_DUPLICATES_AT_CREATION)) {
derivedFeatures.add(CollectionFeature.REJECTS_DUPLICATES_AT_CREATION);
}
if (mapFeatures.contains(MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION)) {
derivedFeatures.add(CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION);
}
// add the intersection of CollectionFeature.values() and mapFeatures
for (CollectionFeature feature : CollectionFeature.values()) {
if (mapFeatures.contains(feature)) {
derivedFeatures.add(feature);
}
}
// add the intersection of CollectionSize.values() and mapFeatures
for (CollectionSize size : CollectionSize.values()) {
if (mapFeatures.contains(size)) {
derivedFeatures.add(size);
}
}
return derivedFeatures;
}
项目:guava-mock
文件:MultimapGetTester.java
@CollectionSize.Require(SEVERAL)
@MapFeature.Require(SUPPORTS_REMOVE)
public void testPropagatesRemovetoMultimap() {
resetContainer(
Helpers.mapEntry(k0(),v0()),Helpers.mapEntry(k0(),v3()),v2()));
Collection<V> result = multimap().get(k0());
assertTrue(result.remove(v0()));
assertFalse(multimap().containsEntry(k0(),v0()));
assertEquals(2,multimap().size());
}
项目:guava-mock
文件:MapRemoveEntryTester.java
@MapFeature.Require(value = SUPPORTS_REMOVE,absent = ALLOWS_NULL_KEY_QUERIES)
public void testRemove_nullKeyQueriesUnsupported() {
try {
assertFalse(getMap().remove(null,v3()));
} catch (NullPointerException tolerated) {
// since the operation would be a no-op,the exception is not required
}
expectUnchanged();
}
@SuppressWarnings("unchecked")
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(ZERO)
public void testForcePutOverwritesOldValueEntry() {
getMap().put(k0(),v0());
getMap().forcePut(k1(),v0());
// verify that the bimap is unchanged
expectAdded(Helpers.mapEntry(k1(),v0()));
}
@MapFeature.Require({SUPPORTS_PUT,ALLOWS_NULL_KEYS})
public void testMergeAbsentNullKey() {
assertEquals(
"Map.merge(null,getMap()
.merge(
null,newV) -> {
throw new AssertionFailedError(
"Should not call merge function if key was absent");
}));
expectAdded(entry(null,v3()));
}
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testPutPresentKeyPropagatesToAsMapEntrySet() {
List<K> keys = Helpers.copyToList(multimap().keySet());
for (K key : keys) {
resetContainer();
int size = getNumElements();
Iterator<Entry<K,Collection<V>>> asMapItr = multimap().asMap().entrySet().iterator();
Collection<V> collection = null;
while (asMapItr.hasNext()) {
Entry<K,Collection<V>> asMapEntry = asMapItr.next();
if (key.equals(asMapEntry.getKey())) {
collection = asMapEntry.getValue();
break;
}
}
assertNotNull(collection);
Collection<V> expectedCollection = Helpers.copyToList(collection);
multimap().put(key,v3());
expectedCollection.add(v3());
assertEqualIgnoringOrder(expectedCollection,collection);
assertEquals(size + 1,multimap().size());
}
}
@MapFeature.Require(absent = SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemove_unsupported() {
try {
getMap().remove(k0());
fail("remove(present) should throw UnsupportedOperationException");
} catch (UnsupportedOperationException expected) {
}
expectUnchanged();
assertEquals("remove(present) should not remove the element",get(k0()));
}
@CollectionSize.Require(absent = ZERO)
@MapFeature.Require(ALLOWS_NULL_KEYS)
public void testEqualsMultimapWithNullKey() {
Multimap<K,V> original = multimap();
initMultimapWithNullKey();
Multimap<K,V> withNull = multimap();
new EqualsTester()
.addEqualityGroup(original)
.addEqualityGroup(
withNull,getSubjectGenerator().create((Object[]) createArrayWithNullKey()))
.testEquals();
}
项目:guava-mock
文件:MapRemoveTester.java
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemove_present() {
int initialSize = getMap().size();
assertEquals("remove(present) should return the associated value",getMap().remove(k0()));
assertEquals(
"remove(present) should decrease a map's size by one.",initialSize - 1,getMap().size());
expectMissing(e0());
}
项目:guava-mock
文件:MultimapContainsEntryTester.java
/**
* copy of the {@link #testContainsEntryNulldisallowed} test. Needed because
* "optional" feature requirements are not supported.
*/
@MapFeature.Require(absent = ALLOWS_NULL_VALUE_QUERIES)
public void testContainsEntryNulldisallowedBecauseValueQueriesdisallowed() {
try {
multimap().containsEntry(k3(),null);
fail("Expected NullPointerException");
} catch (NullPointerException expected) {
// success
}
}
项目:guava-mock
文件:NavigableMapNavigationTester.java
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(SEVERAL)
public void testPollLast() {
assertEquals(c,navigableMap.pollLastEntry());
assertEquals(
entries.subList(0,entries.size() - 1),Helpers.copyToList(navigableMap.entrySet()));
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。