项目:guava-mock
文件:TestsForSetsInJavaUtil.java
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();
}
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,CollectionSize.ANY)
.suppressing(suppressForCheckedList())
.createTestSuite();
}
@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());
}
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,CollectionSize.ONE)
.suppressing(suppressForSingletonList())
.createTestSuite();
}
项目:guava-mock
文件:TestsForMapsInJavaUtil.java
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,CollectionSize.ANY)
.suppressing(suppressForTreeMapWithComparator())
.createTestSuite();
}
项目:guava-mock
文件:SynchronizedSetTest.java
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,CollectionSize.ANY,CollectionFeature.SERIALIZABLE)
.createTestSuite();
}
项目:guava-mock
文件:TestsForMapsInJavaUtil.java
public Test testsForconcurrentskiplistmapWithComparator() {
return NavigableMapTestSuiteBuilder.using(
new TestStringSortedMapGenerator() {
@Override
protected SortedMap<String,String>[] entries) {
return populate(
new concurrentskiplistmap<String,entries);
}
})
.named("concurrentskiplistmap,CollectionSize.ANY)
.suppressing(suppressForconcurrentskiplistmap())
.createTestSuite();
}
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,CollectionSize.ANY)
.suppressing(suppressForarraydeque())
.createTestSuite();
}
@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,CollectionSize.ANY)
.createTestSuite();
}
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,CollectionSize.ANY)
.suppressing(suppressForEnumSet())
.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());
}
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,CollectionSize.ANY)
.skipCollectionTests() // already covered in TestsForListsInJavaUtil
.suppressing(suppressForLinkedList())
.createTestSuite();
}
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>(),CollectionFeature.SERIALIZABLE)
.createTestSuite();
}
@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,v) -> {
assertNull(k);
assertEquals(getValueForNullKey(),v);
return v3();
}));
Entry<K,V>[] expected = createArrayWithNullKey();
expected[getNullLocation()] = entry(null,v3());
expectContents(expected);
}
@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);
}
@SuppressWarnings("unchecked")
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(ZERO)
public void testInversePut() {
getMap().put(k0(),v0());
getMap().inverse().put(v1(),k1());
expectAdded(e0(),e1());
}
项目:guava-mock
文件:MapClearTester.java
@MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION,SUPPORTS_REMOVE})
@CollectionSize.Require(SEVERAL)
public void testClearConcurrentWithEntrySetIteration() {
try {
Iterator<Entry<K,V>> iterator = getMap().entrySet().iterator();
getMap().clear();
iterator.next();
fail("Expected ConcurrentModificationException");
} catch (ConcurrentModificationException expected) {
// success
}
}
项目:guava-mock
文件:BiMapPutTester.java
@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()));
}
项目:guava-mock
文件:ListIndexOfTester.java
@CollectionFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION)
@CollectionSize.Require(absent = {ZERO,ONE})
public void testIndexOf_duplicate() {
E[] array = createSamplesArray();
array[getNumElements() / 2] = e0();
collection = getSubjectGenerator().create(array);
assertEquals(
"indexOf(duplicate) should return index of first occurrence",getList().indexOf(e0()));
}
@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_REMOVE)
@MultisetFeature.Require(ENTRIES_ARE_VIEWS)
public void testEntryReflectsClear() {
initThreecopies();
assertEquals(3,getMultiset().count(e0()));
Multiset.Entry<E> entry = Iterables.getonlyElement(getMultiset().entrySet());
assertEquals(3,entry.getCount());
getMultiset().clear();
assertEquals(0,entry.getCount());
}
@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_REMOVE)
@MultisetFeature.Require(ENTRIES_ARE_VIEWS)
public void testEntryReflectsEntrySetClear() {
initThreecopies();
assertEquals(3,entry.getCount());
getMultiset().entrySet().clear();
assertEquals(0,entry.getCount());
}
项目:guava-mock
文件:MultimapClearTester.java
@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);
}
}
项目:guava-mock
文件:MultisetEntrySetTester.java
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testEntrySet_removeAllAbsent() {
assertFalse(
"multiset.entrySet.remove(missingEntry) returned true",getMultiset()
.entrySet()
.removeAll(Collections.singleton(Multisets.immutableEntry(e0(),2))));
assertTrue(
"multiset didn't contain element after removing a missing entry",getMultiset().contains(e0()));
}
@ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testAddAllAtIndex_unsupportedSomePresent() {
try {
getList().addAll(0,MinimalCollection.of(e0(),e3()));
fail("addAll(n,allPresent) should throw");
} catch (UnsupportedOperationException expected) {
}
expectUnchanged();
expectMissing(e3());
}
@MapFeature.Require(value = SUPPORTS_PUT,absent = ALLOWS_NULL_VALUES)
@CollectionSize.Require(absent = ZERO)
public void testReplaceEntry_presentNullValueUnsupported() {
try {
getMap().replace(k0(),v0(),null);
fail("Expected NullPointerException");
} catch (NullPointerException expected) {}
expectUnchanged();
}
@CollectionFeature.Require(value = ALLOWS_NULL_VALUES,absent = REJECTS_DUPLICATES_AT_CREATION)
@CollectionSize.Require(absent = {ZERO,ONE})
public void testCreateWithDuplicates_nullDuplicatesNotRejected() {
E[] array = createArrayWithNullElement();
array[0] = null;
collection = getSubjectGenerator().create(array);
List<E> expectedWithDuplicateRemoved = Arrays.asList(array).subList(1,getNumElements());
expectContents(expectedWithDuplicateRemoved);
}
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(absent = NON_STANDARD_TOSTRING)
@MapFeature.Require(ALLOWS_NULL_VALUES)
public void testToStringWithNullValue() {
initMultimapWithNullValue();
testToStringMatchesAsMap();
}
@SuppressWarnings("unchecked")
@CollectionFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(SEVERAL)
public void testRetainAll_duplicatesRemoved() {
E[] array = createSamplesArray();
array[1] = e0();
collection = getSubjectGenerator().create(array);
assertTrue(
"containsDuplicates.retainAll(subset) should return true",collection.retainAll(MinimalCollection.of(e2())));
expectContents(e2());
}
@CollectionSize.Require(absent = ZERO)
@MapFeature.Require(ALLOWS_NULL_VALUES)
public void testEqualsMultimapWithNullValue() {
Multimap<K,V> original = multimap();
initMultimapWithNullValue();
Multimap<K,V> withNull = multimap();
new EqualsTester()
.addEqualityGroup(original)
.addEqualityGroup(
withNull,getSubjectGenerator().create((Object[]) createArrayWithNullValue()))
.testEquals();
}
项目:guava-mock
文件:MapReplaceEntryTester.java
@MapFeature.Require(absent = SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testReplaceEntry_unsupportedPresent() {
try {
getMap().replace(k0(),v3());
fail("Expected UnsupportedOperationException");
} catch (UnsupportedOperationException expected) {}
expectUnchanged();
}
@MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION,SUPPORTS_PUT})
@CollectionSize.Require(absent = ZERO)
public void testPutAllSomePresentConcurrentWithEntrySetIteration() {
try {
Iterator<Entry<K,V>> iterator = getMap().entrySet().iterator();
putAll(MinimalCollection.of(e3(),e0()));
iterator.next();
fail("Expected ConcurrentModificationException");
} catch (ConcurrentModificationException expected) {
// success
}
}
public Test testsForEmptyNavigableSet() {
return SetTestSuiteBuilder.using(
new TestStringSortedSetGenerator() {
@Override
public NavigableSet<String> create(String[] elements) {
return Collections.emptyNavigableSet();
}
})
.named("emptyNavigableSet")
.withFeatures(CollectionFeature.SERIALIZABLE,CollectionSize.ZERO)
.suppressing(suppressForEmptyNavigableSet())
.createTestSuite();
}
@CollectionSize.Require(SEVERAL)
public void testLower() {
resetWithHole();
assertEquals(null,sortedMultiset.headMultiset(a.getElement(),OPEN).lastEntry());
assertEquals(a,sortedMultiset.headMultiset(b.getElement(),sortedMultiset.headMultiset(c.getElement(),OPEN).lastEntry());
}
@MapFeature.Require(value = SUPPORTS_PUT,absent = ALLOWS_NULL_VALUE_QUERIES)
@CollectionSize.Require(absent = ZERO)
public void testReplaceEntry_wrongValueNullValueUnsupported() {
try {
assertFalse(getMap().replace(k0(),null));
} catch (NullPointerException tolerated) {
// the operation would be a no-op,so exceptions are allowed but not required
}
expectUnchanged();
}
项目:guava-mock
文件:MultisetNavigationTester.java
@CollectionSize.Require(SEVERAL)
public void testLower() {
resetWithHole();
assertEquals(null,OPEN).lastEntry());
}
@CollectionSize.Require(absent = ZERO)
@MapFeature.Require(SUPPORTS_REMOVE)
public void testRemoveAllPropagatesToGet() {
Collection<V> getResult = multimap().get(k0());
multimap().removeAll(k0());
assertEmpty(getResult);
expectMissing(e0());
}
@SuppressWarnings("unchecked")
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(SEVERAL)
public void testMultimapRemoveDeletesFirstOccurrence() {
resetContainer(mapEntry(k0(),v0()),mapEntry(k0(),v1()),v0()));
List<V> list = multimap().get(k0());
multimap().remove(k0(),v0());
assertContentsInorder(list,v1(),v0());
}
@CollectionSize.Require(SEVERAL)
@MapFeature.Require(SUPPORTS_REMOVE)
public void testKeysEntrySetRemove() {
resetContainer(
Helpers.mapEntry(k0(),Helpers.mapEntry(k0(),Helpers.mapEntry(k1(),v0()));
assertTrue(multimap().keys().entrySet().remove(Multisets.immutableEntry(k0(),2)));
assertEquals(1,multimap().size());
assertTrue(multimap().containsEntry(k1(),v0()));
}
项目:guava-mock
文件:TestsForSetsInJavaUtil.java
public Test testsForEmptySet() {
return SetTestSuiteBuilder.using(
new TestStringSetGenerator() {
@Override
public Set<String> create(String[] elements) {
return Collections.emptySet();
}
})
.named("emptySet")
.withFeatures(CollectionFeature.SERIALIZABLE,CollectionSize.ZERO)
.suppressing(suppressForEmptySet())
.createTestSuite();
}
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testEntrySet_removeAllAbsent() {
assertFalse(
"multiset.entrySet.remove(missingEntry) returned true",getMultiset().contains(e0()));
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。