use of com.google.common.collect.testing.google.TestStringMultisetGenerator in project guava by google.
the class ForwardingMultisetTest method suite.
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(ForwardingMultisetTest.class);
suite.addTest(MultisetTestSuiteBuilder.using(new TestStringMultisetGenerator() {
@Override
protected Multiset<String> create(String[] elements) {
return new StandardImplForwardingMultiset<String>(LinkedHashMultiset.create(Arrays.asList(elements)));
}
}).named("ForwardingMultiset[LinkedHashMultiset] with standard " + "implementations").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.GENERAL_PURPOSE).createTestSuite());
suite.addTest(MultisetTestSuiteBuilder.using(new TestStringMultisetGenerator() {
@Override
protected Multiset<String> create(String[] elements) {
return new StandardImplForwardingMultiset<String>(ImmutableMultiset.copyOf(elements));
}
}).named("ForwardingMultiset[ImmutableMultiset] with standard " + "implementations").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
/**
* Returns a Multiset that throws an exception on any attempt to use a
* method not specifically authorized by the elementSet() or hashCode()
* docs.
*/
@Override
protected Set<String> create(String[] elements) {
final Multiset<String> inner = LinkedHashMultiset.create(Arrays.asList(elements));
return new ForwardingMultiset<String>() {
@Override
protected Multiset<String> delegate() {
return inner;
}
@Override
public Set<String> elementSet() {
return new StandardElementSet();
}
@Override
public int add(String element, int occurrences) {
throw new UnsupportedOperationException();
}
@Override
public Set<Entry<String>> entrySet() {
final Set<Entry<String>> backingSet = super.entrySet();
return new ForwardingSet<Entry<String>>() {
@Override
protected Set<Entry<String>> delegate() {
return backingSet;
}
@Override
public boolean add(Entry<String> element) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(Collection<? extends Entry<String>> collection) {
throw new UnsupportedOperationException();
}
@Override
public void clear() {
throw new UnsupportedOperationException();
}
@Override
public boolean contains(Object object) {
throw new UnsupportedOperationException();
}
@Override
public boolean containsAll(Collection<?> collection) {
throw new UnsupportedOperationException();
}
@Override
public boolean isEmpty() {
throw new UnsupportedOperationException();
}
@Override
public boolean remove(Object object) {
throw new UnsupportedOperationException();
}
@Override
public boolean removeAll(Collection<?> collection) {
throw new UnsupportedOperationException();
}
@Override
public boolean retainAll(Collection<?> collection) {
throw new UnsupportedOperationException();
}
};
}
@Override
public boolean equals(Object object) {
throw new UnsupportedOperationException();
}
@Override
public boolean remove(Object element) {
throw new UnsupportedOperationException();
}
@Override
public boolean setCount(String element, int oldCount, int newCount) {
throw new UnsupportedOperationException();
}
@Override
public int setCount(String element, int count) {
throw new UnsupportedOperationException();
}
@Override
public boolean add(String element) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(Collection<? extends String> collection) {
throw new UnsupportedOperationException();
}
@Override
public Iterator<String> iterator() {
throw new UnsupportedOperationException();
}
@Override
public boolean removeAll(Collection<?> collection) {
throw new UnsupportedOperationException();
}
@Override
public boolean retainAll(Collection<?> collection) {
throw new UnsupportedOperationException();
}
@Override
public int size() {
throw new UnsupportedOperationException();
}
}.elementSet();
}
}).named("standardElementSet tripwire").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.REMOVE_OPERATIONS).createTestSuite());
return suite;
}
use of com.google.common.collect.testing.google.TestStringMultisetGenerator in project guava by google.
the class ForwardingSortedMultisetTest method suite.
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(ForwardingSortedMultisetTest.class);
suite.addTest(SortedMultisetTestSuiteBuilder.using(new TestStringMultisetGenerator() {
@Override
protected Multiset<String> create(String[] elements) {
return new StandardImplForwardingSortedMultiset<String>(TreeMultiset.create(Arrays.asList(elements)));
}
@Override
public List<String> order(List<String> insertionOrder) {
return Ordering.natural().sortedCopy(insertionOrder);
}
}).named("ForwardingSortedMultiset with standard impls").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.GENERAL_PURPOSE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
return suite;
}
use of com.google.common.collect.testing.google.TestStringMultisetGenerator in project guava by google.
the class TreeMultisetTest method suite.
// suite
@GwtIncompatible
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(SortedMultisetTestSuiteBuilder.using(new TestStringMultisetGenerator() {
@Override
protected Multiset<String> create(String[] elements) {
return TreeMultiset.create(Arrays.asList(elements));
}
@Override
public List<String> order(List<String> insertionOrder) {
return Ordering.natural().sortedCopy(insertionOrder);
}
}).withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.GENERAL_PURPOSE, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES, MultisetFeature.ENTRIES_ARE_VIEWS).named("TreeMultiset, Ordering.natural").createTestSuite());
suite.addTest(SortedMultisetTestSuiteBuilder.using(new TestStringMultisetGenerator() {
@Override
protected Multiset<String> create(String[] elements) {
Multiset<String> result = TreeMultiset.create(NullsBeforeB.INSTANCE);
Collections.addAll(result, elements);
return result;
}
@Override
public List<String> order(List<String> insertionOrder) {
sort(insertionOrder, NullsBeforeB.INSTANCE);
return insertionOrder;
}
}).withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.GENERAL_PURPOSE, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_VALUES, MultisetFeature.ENTRIES_ARE_VIEWS).named("TreeMultiset, NullsBeforeB").createTestSuite());
suite.addTest(NavigableSetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
return TreeMultiset.create(Arrays.asList(elements)).elementSet();
}
@Override
public List<String> order(List<String> insertionOrder) {
return Lists.newArrayList(Sets.newTreeSet(insertionOrder));
}
}).named("TreeMultiset[Ordering.natural].elementSet").withFeatures(CollectionSize.ANY, CollectionFeature.REMOVE_OPERATIONS, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTestSuite(TreeMultisetTest.class);
return suite;
}
use of com.google.common.collect.testing.google.TestStringMultisetGenerator in project guava by google.
the class ImmutableMultisetTest method suite.
// suite // TODO(cpovirk): add to collect/gwt/suites
@GwtIncompatible
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(ImmutableMultisetTest.class);
suite.addTest(MultisetTestSuiteBuilder.using(new TestStringMultisetGenerator() {
@Override
protected Multiset<String> create(String[] elements) {
return ImmutableMultiset.copyOf(elements);
}
}).named("ImmutableMultiset").withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
return ImmutableMultiset.copyOf(elements).elementSet();
}
}).named("ImmutableMultiset, element set").withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
@Override
protected List<String> create(String[] elements) {
return ImmutableMultiset.copyOf(elements).asList();
}
@Override
public List<String> order(List<String> insertionOrder) {
List<String> order = new ArrayList<String>();
for (String s : insertionOrder) {
int index = order.indexOf(s);
if (index == -1) {
order.add(s);
} else {
order.add(index, s);
}
}
return order;
}
}).named("ImmutableMultiset.asList").withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
@Override
protected List<String> create(String[] elements) {
Set<String> set = new HashSet<String>();
ImmutableMultiset.Builder<String> builder = ImmutableMultiset.builder();
for (String s : elements) {
checkArgument(set.add(s));
builder.addCopies(s, 2);
}
ImmutableSet<String> elementSet = (ImmutableSet<String>) builder.build().elementSet();
return elementSet.asList();
}
}).named("ImmutableMultiset.elementSet.asList").withFeatures(CollectionSize.ANY, CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
return suite;
}
use of com.google.common.collect.testing.google.TestStringMultisetGenerator in project guava by google.
the class MultimapsCollectionTest method suite.
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(transformSuite());
suite.addTest(filterSuite());
suite.addTest(ListMultimapTestSuiteBuilder.using(new TestStringListMultimapGenerator() {
@Override
protected ListMultimap<String, String> create(Entry<String, String>[] entries) {
ListMultimap<String, String> multimap = Multimaps.synchronizedListMultimap(ArrayListMultimap.<String, String>create());
for (Entry<String, String> entry : entries) {
multimap.put(entry.getKey(), entry.getValue());
}
return multimap;
}
}).named("synchronized ArrayListMultimap").withFeatures(MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_NULL_VALUES, MapFeature.ALLOWS_ANY_NULL_QUERIES, MapFeature.GENERAL_PURPOSE, MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION, CollectionFeature.SUPPORTS_ITERATOR_REMOVE, CollectionSize.ANY).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
PopulatableMapAsMultimap<Integer, String> multimap = PopulatableMapAsMultimap.create();
populateMultimapForGet(multimap, elements);
return multimap.build().get(3);
}
}).named("Multimaps.forMap.get").withFeatures(FOR_MAP_FEATURES_ONE).createTestSuite());
suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override
protected Set<String> create(String[] elements) {
PopulatableMapAsMultimap<String, Integer> multimap = PopulatableMapAsMultimap.create();
populateMultimapForKeySet(multimap, elements);
return multimap.build().keySet();
}
}).named("Multimaps.forMap.keySet").withFeatures(FOR_MAP_FEATURES_ANY).createTestSuite());
// TODO: use collection testers on Multimaps.forMap.values
suite.addTest(MultisetTestSuiteBuilder.using(new TestStringMultisetGenerator() {
@Override
protected Multiset<String> create(String[] elements) {
PopulatableMapAsMultimap<String, Integer> multimap = PopulatableMapAsMultimap.create();
populateMultimapForKeys(multimap, elements);
return multimap.build().keys();
}
}).named("Multimaps.forMap.keys").withFeatures(FOR_MAP_FEATURES_ANY).suppressing(getCountDuplicateInitializingMethods()).suppressing(getSetCountDuplicateInitializingMethods()).suppressing(getIteratorDuplicateInitializingMethods()).suppressing(getRemoveDuplicateInitializingMethods()).createTestSuite());
return suite;
}
Aggregations