use of com.google.common.collect.testing.google.TestStringBiMapGenerator in project guava by google.
the class ImmutableBiMapTest method suite.
// TODO: Reduce duplication of ImmutableMapTest code
// suite
@GwtIncompatible
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(MapTests.class);
suite.addTestSuite(InverseMapTests.class);
suite.addTestSuite(CreationTests.class);
suite.addTestSuite(BiMapSpecificTests.class);
suite.addTestSuite(FloodingTest.class);
suite.addTest(BiMapTestSuiteBuilder.using(new ImmutableBiMapGenerator()).named("ImmutableBiMap").withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE, CollectionFeature.KNOWN_ORDER, MapFeature.REJECTS_DUPLICATES_AT_CREATION, MapFeature.ALLOWS_ANY_NULL_QUERIES).suppressing(BiMapInverseTester.getInverseSameAfterSerializingMethods()).createTestSuite());
suite.addTest(BiMapTestSuiteBuilder.using(new TestStringBiMapGenerator() {
@Override
protected BiMap<String, String> create(Entry<String, String>[] entries) {
return ImmutableBiMap.<String, String>builder().putAll(Arrays.asList(entries)).buildJdkBacked();
}
}).named("ImmutableBiMap [JDK backed]").withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE, CollectionFeature.KNOWN_ORDER, MapFeature.REJECTS_DUPLICATES_AT_CREATION, MapFeature.ALLOWS_ANY_NULL_QUERIES).suppressing(BiMapInverseTester.getInverseSameAfterSerializingMethods()).createTestSuite());
suite.addTest(BiMapTestSuiteBuilder.using(new ImmutableBiMapCopyOfGenerator()).named("ImmutableBiMap.copyOf[Map]").withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE, CollectionFeature.KNOWN_ORDER, MapFeature.ALLOWS_ANY_NULL_QUERIES).suppressing(BiMapInverseTester.getInverseSameAfterSerializingMethods()).createTestSuite());
suite.addTest(BiMapTestSuiteBuilder.using(new ImmutableBiMapCopyOfEntriesGenerator()).named("ImmutableBiMap.copyOf[Iterable<Entry>]").withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE, CollectionFeature.KNOWN_ORDER, MapFeature.REJECTS_DUPLICATES_AT_CREATION, MapFeature.ALLOWS_ANY_NULL_QUERIES).suppressing(BiMapInverseTester.getInverseSameAfterSerializingMethods()).createTestSuite());
suite.addTestSuite(ImmutableBiMapTest.class);
return suite;
}
use of com.google.common.collect.testing.google.TestStringBiMapGenerator in project guava by google.
the class MapsCollectionTest method suite.
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(NavigableMapTestSuiteBuilder.using(new TestStringSortedMapGenerator() {
@Override
protected SortedMap<String, String> create(Entry<String, String>[] entries) {
SafeTreeMap<String, String> map = new SafeTreeMap<>();
putEntries(map, entries);
return Maps.unmodifiableNavigableMap(map);
}
}).named("unmodifiableNavigableMap[SafeTreeMap]").withFeatures(CollectionSize.ANY, MapFeature.ALLOWS_NULL_VALUES, CollectionFeature.SERIALIZABLE).createTestSuite());
suite.addTest(BiMapTestSuiteBuilder.using(new TestStringBiMapGenerator() {
@Override
protected BiMap<String, String> create(Entry<String, String>[] entries) {
BiMap<String, String> bimap = HashBiMap.create(entries.length);
for (Entry<String, String> entry : entries) {
checkArgument(!bimap.containsKey(entry.getKey()));
bimap.put(entry.getKey(), entry.getValue());
}
return Maps.unmodifiableBiMap(bimap);
}
}).named("unmodifiableBiMap[HashBiMap]").withFeatures(CollectionSize.ANY, MapFeature.ALLOWS_NULL_VALUES, MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_ANY_NULL_QUERIES, MapFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.SERIALIZABLE).createTestSuite());
suite.addTest(MapTestSuiteBuilder.using(new TestMapGenerator<String, Integer>() {
@Override
public SampleElements<Entry<String, Integer>> samples() {
return new SampleElements<>(mapEntry("x", 1), mapEntry("xxx", 3), mapEntry("xx", 2), mapEntry("xxxx", 4), mapEntry("aaaaa", 5));
}
@Override
public Map<String, Integer> create(Object... elements) {
Set<String> set = Sets.newLinkedHashSet();
for (Object e : elements) {
Entry<?, ?> entry = (Entry<?, ?>) e;
checkNotNull(entry.getValue());
set.add((String) checkNotNull(entry.getKey()));
}
return Maps.asMap(set, new Function<String, Integer>() {
@Override
public Integer apply(String input) {
return input.length();
}
});
}
@SuppressWarnings("unchecked")
@Override
public Entry<String, Integer>[] createArray(int length) {
return new Entry[length];
}
@Override
public Iterable<Entry<String, Integer>> order(List<Entry<String, Integer>> insertionOrder) {
return insertionOrder;
}
@Override
public String[] createKeyArray(int length) {
return new String[length];
}
@Override
public Integer[] createValueArray(int length) {
return new Integer[length];
}
}).named("Maps.asMap[Set, Function]").withFeatures(CollectionSize.ANY, MapFeature.SUPPORTS_REMOVE, CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
suite.addTest(SortedMapTestSuiteBuilder.using(new TestMapGenerator<String, Integer>() {
@Override
public String[] createKeyArray(int length) {
return new String[length];
}
@Override
public Integer[] createValueArray(int length) {
return new Integer[length];
}
@Override
public SampleElements<Entry<String, Integer>> samples() {
return new SampleElements<>(mapEntry("a", 1), mapEntry("aa", 2), mapEntry("aba", 3), mapEntry("bbbb", 4), mapEntry("ccccc", 5));
}
@Override
public SortedMap<String, Integer> create(Object... elements) {
SortedSet<String> set = new NonNavigableSortedSet();
for (Object e : elements) {
Entry<?, ?> entry = (Entry<?, ?>) e;
checkNotNull(entry.getValue());
set.add((String) checkNotNull(entry.getKey()));
}
return Maps.asMap(set, new Function<String, Integer>() {
@Override
public Integer apply(String input) {
return input.length();
}
});
}
@SuppressWarnings("unchecked")
@Override
public Entry<String, Integer>[] createArray(int length) {
return new Entry[length];
}
@Override
public Iterable<Entry<String, Integer>> order(List<Entry<String, Integer>> insertionOrder) {
Collections.sort(insertionOrder, new Comparator<Entry<String, Integer>>() {
@Override
public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
return o1.getKey().compareTo(o2.getKey());
}
});
return insertionOrder;
}
}).named("Maps.asMap[SortedSet, Function]").withFeatures(CollectionSize.ANY, CollectionFeature.SUPPORTS_ITERATOR_REMOVE, MapFeature.SUPPORTS_REMOVE).createTestSuite());
suite.addTest(NavigableMapTestSuiteBuilder.using(new TestMapGenerator<String, Integer>() {
@Override
public String[] createKeyArray(int length) {
return new String[length];
}
@Override
public Integer[] createValueArray(int length) {
return new Integer[length];
}
@Override
public SampleElements<Entry<String, Integer>> samples() {
return new SampleElements<>(mapEntry("a", 1), mapEntry("aa", 2), mapEntry("aba", 3), mapEntry("bbbb", 4), mapEntry("ccccc", 5));
}
@Override
public NavigableMap<String, Integer> create(Object... elements) {
NavigableSet<String> set = Sets.newTreeSet(Ordering.natural());
for (Object e : elements) {
Entry<?, ?> entry = (Entry<?, ?>) e;
checkNotNull(entry.getValue());
set.add((String) checkNotNull(entry.getKey()));
}
return Maps.asMap(set, new Function<String, Integer>() {
@Override
public Integer apply(String input) {
return input.length();
}
});
}
@SuppressWarnings("unchecked")
@Override
public Entry<String, Integer>[] createArray(int length) {
return new Entry[length];
}
@Override
public Iterable<Entry<String, Integer>> order(List<Entry<String, Integer>> insertionOrder) {
Collections.sort(insertionOrder, new Comparator<Entry<String, Integer>>() {
@Override
public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
return o1.getKey().compareTo(o2.getKey());
}
});
return insertionOrder;
}
}).named("Maps.asMap[NavigableSet, Function]").withFeatures(CollectionSize.ANY, MapFeature.SUPPORTS_REMOVE, CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
suite.addTest(filterSuite());
suite.addTest(transformSuite());
return suite;
}
use of com.google.common.collect.testing.google.TestStringBiMapGenerator in project guava by google.
the class MapsCollectionTest method filterBiMapSuite.
static TestSuite filterBiMapSuite() {
TestSuite suite = new TestSuite("FilterBiMap");
suite.addTest(BiMapTestSuiteBuilder.using(new TestStringBiMapGenerator() {
@Override
protected BiMap<String, String> create(Entry<String, String>[] entries) {
BiMap<String, String> map = HashBiMap.create();
putEntries(map, entries);
map.putAll(ENTRIES_TO_FILTER);
return Maps.filterKeys(map, FILTER_KEYS);
}
}).named("Maps.filterKeys[BiMap, Predicate]").withFeatures(MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_NULL_VALUES, MapFeature.GENERAL_PURPOSE, CollectionSize.ANY).createTestSuite());
suite.addTest(BiMapTestSuiteBuilder.using(new TestStringBiMapGenerator() {
@Override
protected BiMap<String, String> create(Entry<String, String>[] entries) {
BiMap<String, String> map = HashBiMap.create();
putEntries(map, entries);
map.putAll(ENTRIES_TO_FILTER);
return Maps.filterValues(map, FILTER_VALUES);
}
}).named("Maps.filterValues[BiMap, Predicate]").withFeatures(MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_NULL_VALUES, MapFeature.ALLOWS_ANY_NULL_QUERIES, MapFeature.GENERAL_PURPOSE, CollectionSize.ANY).createTestSuite());
suite.addTest(BiMapTestSuiteBuilder.using(new TestStringBiMapGenerator() {
@Override
protected BiMap<String, String> create(Entry<String, String>[] entries) {
BiMap<String, String> map = HashBiMap.create();
putEntries(map, entries);
map.putAll(ENTRIES_TO_FILTER);
return Maps.filterEntries(map, FILTER_ENTRIES);
}
}).named("Maps.filterEntries[BiMap, Predicate]").withFeatures(MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_NULL_VALUES, MapFeature.ALLOWS_ANY_NULL_QUERIES, MapFeature.GENERAL_PURPOSE, CollectionSize.ANY).createTestSuite());
return suite;
}
use of com.google.common.collect.testing.google.TestStringBiMapGenerator in project guava by hceylan.
the class MapsCollectionTest method suite.
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(NavigableMapTestSuiteBuilder.using(new TestStringMapGenerator() {
@Override
protected Map<String, String> create(Entry<String, String>[] entries) {
SafeTreeMap<String, String> map = new SafeTreeMap<String, String>();
for (Entry<String, String> entry : entries) {
map.put(entry.getKey(), entry.getValue());
}
return Maps.unmodifiableNavigableMap(map);
}
}).named("unmodifiableNavigableMap[SafeTreeMap]").withFeatures(CollectionSize.ANY, MapFeature.ALLOWS_NULL_VALUES).createTestSuite());
suite.addTest(NavigableMapTestSuiteBuilder.using(new TestStringMapGenerator() {
@Override
protected Map<String, String> create(Entry<String, String>[] entries) {
SafeTreeMap<String, String> map = new SafeTreeMap<String, String>();
for (Entry<String, String> entry : entries) {
map.put(entry.getKey(), entry.getValue());
}
return SerializableTester.reserialize(Maps.unmodifiableNavigableMap(map));
}
}).named("unmodifiableNavigableMap[SafeTreeMap], reserialized").withFeatures(CollectionSize.ANY, MapFeature.ALLOWS_NULL_VALUES).createTestSuite());
suite.addTest(BiMapTestSuiteBuilder.using(new TestStringBiMapGenerator() {
@Override
protected BiMap<String, String> create(Entry<String, String>[] entries) {
BiMap<String, String> bimap = HashBiMap.create(entries.length);
for (Entry<String, String> entry : entries) {
checkArgument(!bimap.containsKey(entry.getKey()));
bimap.put(entry.getKey(), entry.getValue());
}
return Maps.unmodifiableBiMap(bimap);
}
}).named("unmodifiableBiMap[HashBiMap]").withFeatures(CollectionSize.ANY, MapFeature.ALLOWS_NULL_VALUES, MapFeature.ALLOWS_NULL_KEYS, MapFeature.REJECTS_DUPLICATES_AT_CREATION).createTestSuite());
suite.addTest(BiMapTestSuiteBuilder.using(new TestStringBiMapGenerator() {
@Override
protected BiMap<String, String> create(Entry<String, String>[] entries) {
BiMap<String, String> bimap = HashBiMap.create(entries.length);
for (Entry<String, String> entry : entries) {
checkArgument(!bimap.containsKey(entry.getKey()));
bimap.put(entry.getKey(), entry.getValue());
}
return SerializableTester.reserialize(Maps.unmodifiableBiMap(bimap));
}
}).named("unmodifiableBiMap[HashBiMap], reserialized").withFeatures(CollectionSize.ANY, MapFeature.ALLOWS_NULL_VALUES, MapFeature.ALLOWS_NULL_KEYS, MapFeature.REJECTS_DUPLICATES_AT_CREATION).createTestSuite());
return suite;
}
Aggregations