Search in sources :

Example 1 with TestStringMapGenerator

use of com.google.common.collect.testing.TestStringMapGenerator in project guava by google.

the class CompactHashMapTest method suite.

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(MapTestSuiteBuilder.using(new TestStringMapGenerator() {

        @Override
        protected Map<String, String> create(Entry<String, String>[] entries) {
            Map<String, String> map = CompactHashMap.create();
            for (Entry<String, String> entry : entries) {
                map.put(entry.getKey(), entry.getValue());
            }
            return map;
        }
    }).named("CompactHashMap").withFeatures(CollectionSize.ANY, MapFeature.GENERAL_PURPOSE, MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_NULL_VALUES, CollectionFeature.SERIALIZABLE, CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
    suite.addTest(MapTestSuiteBuilder.using(new TestStringMapGenerator() {

        @Override
        protected Map<String, String> create(Entry<String, String>[] entries) {
            CompactHashMap<String, String> map = CompactHashMap.create();
            map.convertToHashFloodingResistantImplementation();
            for (Entry<String, String> entry : entries) {
                map.put(entry.getKey(), entry.getValue());
            }
            return map;
        }
    }).named("CompactHashMap with flooding resistance").withFeatures(CollectionSize.ANY, MapFeature.GENERAL_PURPOSE, MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_NULL_VALUES, CollectionFeature.SERIALIZABLE, CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
    suite.addTestSuite(CompactHashMapTest.class);
    return suite;
}
Also used : Entry(java.util.Map.Entry) TestSuite(junit.framework.TestSuite) TestStringMapGenerator(com.google.common.collect.testing.TestStringMapGenerator) Map(java.util.Map)

Example 2 with TestStringMapGenerator

use of com.google.common.collect.testing.TestStringMapGenerator in project guava by google.

the class ImmutableMapTest method suite.

// suite
@GwtIncompatible
public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(ImmutableMapTest.class);
    suite.addTestSuite(FloodingTest.class);
    suite.addTest(MapTestSuiteBuilder.using(new ImmutableMapGenerator()).withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS, CollectionFeature.KNOWN_ORDER, MapFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES).named("ImmutableMap").createTestSuite());
    suite.addTest(MapTestSuiteBuilder.using(new TestStringMapGenerator() {

        @Override
        protected Map<String, String> create(Entry<String, String>[] entries) {
            ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
            builder.putAll(Arrays.asList(entries));
            return builder.buildJdkBacked();
        }
    }).withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS, CollectionFeature.KNOWN_ORDER, MapFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES).named("ImmutableMap [JDK backed]").createTestSuite());
    suite.addTest(MapTestSuiteBuilder.using(new ImmutableMapCopyOfGenerator()).withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS, CollectionFeature.KNOWN_ORDER, CollectionFeature.ALLOWS_NULL_QUERIES).named("ImmutableMap.copyOf[Map]").createTestSuite());
    suite.addTest(MapTestSuiteBuilder.using(new ImmutableMapCopyOfEntriesGenerator()).withFeatures(CollectionSize.ANY, MapFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS, CollectionFeature.KNOWN_ORDER, CollectionFeature.ALLOWS_NULL_QUERIES).named("ImmutableMap.copyOf[Iterable<Entry>]").createTestSuite());
    suite.addTest(MapTestSuiteBuilder.using(new ImmutableMapCopyOfEnumMapGenerator()).withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS, CollectionFeature.KNOWN_ORDER, CollectionFeature.ALLOWS_NULL_QUERIES).named("ImmutableMap.copyOf[EnumMap]").createTestSuite());
    suite.addTest(MapTestSuiteBuilder.using(new ImmutableMapValuesAsSingletonSetGenerator()).withFeatures(CollectionSize.ANY, MapFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.KNOWN_ORDER, CollectionFeature.ALLOWS_NULL_QUERIES).named("ImmutableMap.asMultimap.asMap").createTestSuite());
    suite.addTest(CollectionTestSuiteBuilder.using(new ImmutableMapUnhashableValuesGenerator()).withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.ALLOWS_NULL_QUERIES).named("ImmutableMap.values, unhashable").createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new ImmutableMapKeyListGenerator()).named("ImmutableMap.keySet.asList").withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE, CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new ImmutableMapEntryListGenerator()).named("ImmutableMap.entrySet.asList").withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE, CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new ImmutableMapValueListGenerator()).named("ImmutableMap.values.asList").withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    return suite;
}
Also used : ImmutableMapValueListGenerator(com.google.common.collect.testing.google.MapGenerators.ImmutableMapValueListGenerator) CollectionTestSuiteBuilder(com.google.common.collect.testing.CollectionTestSuiteBuilder) Builder(com.google.common.collect.ImmutableMap.Builder) ListTestSuiteBuilder(com.google.common.collect.testing.ListTestSuiteBuilder) MapTestSuiteBuilder(com.google.common.collect.testing.MapTestSuiteBuilder) ImmutableMapKeyListGenerator(com.google.common.collect.testing.google.MapGenerators.ImmutableMapKeyListGenerator) ImmutableMapUnhashableValuesGenerator(com.google.common.collect.testing.google.MapGenerators.ImmutableMapUnhashableValuesGenerator) Entry(java.util.Map.Entry) Helpers.mapEntry(com.google.common.collect.testing.Helpers.mapEntry) TestSuite(junit.framework.TestSuite) ImmutableMapGenerator(com.google.common.collect.testing.google.MapGenerators.ImmutableMapGenerator) TestStringMapGenerator(com.google.common.collect.testing.TestStringMapGenerator) ImmutableMapCopyOfEntriesGenerator(com.google.common.collect.testing.google.MapGenerators.ImmutableMapCopyOfEntriesGenerator) ImmutableMapValuesAsSingletonSetGenerator(com.google.common.collect.testing.google.MapGenerators.ImmutableMapValuesAsSingletonSetGenerator) ImmutableMapCopyOfEnumMapGenerator(com.google.common.collect.testing.google.MapGenerators.ImmutableMapCopyOfEnumMapGenerator) Map(java.util.Map) EnumMap(java.util.EnumMap) LinkedHashMap(java.util.LinkedHashMap) AbstractMap(java.util.AbstractMap) ImmutableMapEntryListGenerator(com.google.common.collect.testing.google.MapGenerators.ImmutableMapEntryListGenerator) ImmutableMapCopyOfGenerator(com.google.common.collect.testing.google.MapGenerators.ImmutableMapCopyOfGenerator) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 3 with TestStringMapGenerator

use of com.google.common.collect.testing.TestStringMapGenerator in project guava by google.

the class MapsCollectionTest method transformMapSuite.

static TestSuite transformMapSuite() {
    TestSuite suite = new TestSuite("TransformMap");
    suite.addTest(MapTestSuiteBuilder.using(new TestStringMapGenerator() {

        @Override
        protected Map<String, String> create(Entry<String, String>[] entries) {
            Map<String, String> map = Maps.newLinkedHashMap();
            for (Entry<String, String> entry : entries) {
                map.put(entry.getKey(), encode(entry.getValue()));
            }
            return Maps.transformValues(map, DECODE_FUNCTION);
        }
    }).named("Maps.transformValues[Map, Function]").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_ANY_NULL_QUERIES, MapFeature.SUPPORTS_REMOVE, CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
    suite.addTest(MapTestSuiteBuilder.using(new TestStringMapGenerator() {

        @Override
        protected Map<String, String> create(Entry<String, String>[] entries) {
            Map<String, String> map = Maps.newLinkedHashMap();
            for (Entry<String, String> entry : entries) {
                map.put(entry.getKey(), encode(entry.getValue()));
            }
            return Maps.transformEntries(map, DECODE_ENTRY_TRANSFORMER);
        }
    }).named("Maps.transformEntries[Map, EntryTransformer]").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_ANY_NULL_QUERIES, MapFeature.SUPPORTS_REMOVE, CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
    return suite;
}
Also used : Helpers.mapEntry(com.google.common.collect.testing.Helpers.mapEntry) Entry(java.util.Map.Entry) TestSuite(junit.framework.TestSuite) TestStringMapGenerator(com.google.common.collect.testing.TestStringMapGenerator) Map(java.util.Map) NavigableMap(java.util.NavigableMap) SafeTreeMap(com.google.common.collect.testing.SafeTreeMap) SortedMap(java.util.SortedMap)

Example 4 with TestStringMapGenerator

use of com.google.common.collect.testing.TestStringMapGenerator in project guava by google.

the class MapsCollectionTest method filterMapSuite.

static TestSuite filterMapSuite() {
    TestSuite suite = new TestSuite("FilterMap");
    suite.addTest(MapTestSuiteBuilder.using(new TestStringMapGenerator() {

        @Override
        protected Map<String, String> create(Entry<String, String>[] entries) {
            Map<String, String> map = Maps.newHashMap();
            putEntries(map, entries);
            map.putAll(ENTRIES_TO_FILTER);
            return Maps.filterKeys(map, FILTER_KEYS);
        }
    }).named("Maps.filterKeys[Map, Predicate]").withFeatures(MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_NULL_VALUES, MapFeature.ALLOWS_ANY_NULL_QUERIES, MapFeature.GENERAL_PURPOSE, CollectionSize.ANY).createTestSuite());
    suite.addTest(MapTestSuiteBuilder.using(new TestStringMapGenerator() {

        @Override
        protected Map<String, String> create(Entry<String, String>[] entries) {
            Map<String, String> map = Maps.newHashMap();
            putEntries(map, entries);
            map.putAll(ENTRIES_TO_FILTER);
            return Maps.filterValues(map, FILTER_VALUES);
        }
    }).named("Maps.filterValues[Map, Predicate]").withFeatures(MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_NULL_VALUES, MapFeature.ALLOWS_ANY_NULL_QUERIES, MapFeature.GENERAL_PURPOSE, CollectionSize.ANY).createTestSuite());
    suite.addTest(MapTestSuiteBuilder.using(new TestStringMapGenerator() {

        @Override
        protected Map<String, String> create(Entry<String, String>[] entries) {
            Map<String, String> map = Maps.newHashMap();
            putEntries(map, entries);
            map.putAll(ENTRIES_TO_FILTER);
            return Maps.filterEntries(map, FILTER_ENTRIES);
        }
    }).named("Maps.filterEntries[Map, Predicate]").withFeatures(MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_NULL_VALUES, MapFeature.ALLOWS_ANY_NULL_QUERIES, MapFeature.GENERAL_PURPOSE, CollectionSize.ANY).createTestSuite());
    suite.addTest(MapTestSuiteBuilder.using(new TestStringMapGenerator() {

        @Override
        protected Map<String, String> create(Entry<String, String>[] entries) {
            Map<String, String> map = Maps.newHashMap();
            putEntries(map, entries);
            map.putAll(ENTRIES_TO_FILTER);
            map = Maps.filterEntries(map, FILTER_ENTRIES_1);
            return Maps.filterEntries(map, FILTER_ENTRIES_2);
        }
    }).named("Maps.filterEntries[Maps.filterEntries[Map, Predicate], Predicate]").withFeatures(MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_NULL_VALUES, MapFeature.ALLOWS_ANY_NULL_QUERIES, MapFeature.GENERAL_PURPOSE, CollectionSize.ANY).createTestSuite());
    return suite;
}
Also used : Helpers.mapEntry(com.google.common.collect.testing.Helpers.mapEntry) Entry(java.util.Map.Entry) TestSuite(junit.framework.TestSuite) TestStringMapGenerator(com.google.common.collect.testing.TestStringMapGenerator) Map(java.util.Map) NavigableMap(java.util.NavigableMap) SafeTreeMap(com.google.common.collect.testing.SafeTreeMap) SortedMap(java.util.SortedMap)

Example 5 with TestStringMapGenerator

use of com.google.common.collect.testing.TestStringMapGenerator in project guava by hceylan.

the class ForwardingMapTest method suite.

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(ForwardingMapTest.class);
    suite.addTest(MapTestSuiteBuilder.using(new TestStringMapGenerator() {

        @Override
        protected Map<String, String> create(Entry<String, String>[] entries) {
            Map<String, String> map = Maps.newLinkedHashMap();
            for (Entry<String, String> entry : entries) {
                map.put(entry.getKey(), entry.getValue());
            }
            return new StandardImplForwardingMap<String, String>(map);
        }
    }).named("ForwardingMap[LinkedHashMap] with standard implementations").withFeatures(CollectionSize.ANY, MapFeature.ALLOWS_NULL_VALUES, MapFeature.ALLOWS_NULL_KEYS, MapFeature.GENERAL_PURPOSE).createTestSuite());
    suite.addTest(MapTestSuiteBuilder.using(new TestStringMapGenerator() {

        @Override
        protected Map<String, String> create(Entry<String, String>[] entries) {
            ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
            for (Entry<String, String> entry : entries) {
                builder.put(entry.getKey(), entry.getValue());
            }
            return new StandardImplForwardingMap<String, String>(builder.build());
        }
    }).named("ForwardingMap[ImmutableMap] with standard implementations").withFeatures(CollectionSize.ANY, MapFeature.REJECTS_DUPLICATES_AT_CREATION, MapFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    return suite;
}
Also used : Entry(java.util.Map.Entry) TestSuite(junit.framework.TestSuite) MapTestSuiteBuilder(com.google.common.collect.testing.MapTestSuiteBuilder) TestStringMapGenerator(com.google.common.collect.testing.TestStringMapGenerator) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

TestStringMapGenerator (com.google.common.collect.testing.TestStringMapGenerator)11 Map (java.util.Map)11 Entry (java.util.Map.Entry)11 TestSuite (junit.framework.TestSuite)11 SafeTreeMap (com.google.common.collect.testing.SafeTreeMap)5 SortedMap (java.util.SortedMap)5 MapTestSuiteBuilder (com.google.common.collect.testing.MapTestSuiteBuilder)4 Helpers.mapEntry (com.google.common.collect.testing.Helpers.mapEntry)3 NavigableMap (java.util.NavigableMap)3 GwtIncompatible (com.google.common.annotations.GwtIncompatible)1 Builder (com.google.common.collect.ImmutableMap.Builder)1 Maps.immutableEntry (com.google.common.collect.Maps.immutableEntry)1 CollectionTestSuiteBuilder (com.google.common.collect.testing.CollectionTestSuiteBuilder)1 ListTestSuiteBuilder (com.google.common.collect.testing.ListTestSuiteBuilder)1 ImmutableMapCopyOfEntriesGenerator (com.google.common.collect.testing.google.MapGenerators.ImmutableMapCopyOfEntriesGenerator)1 ImmutableMapCopyOfEnumMapGenerator (com.google.common.collect.testing.google.MapGenerators.ImmutableMapCopyOfEnumMapGenerator)1 ImmutableMapCopyOfGenerator (com.google.common.collect.testing.google.MapGenerators.ImmutableMapCopyOfGenerator)1 ImmutableMapEntryListGenerator (com.google.common.collect.testing.google.MapGenerators.ImmutableMapEntryListGenerator)1 ImmutableMapGenerator (com.google.common.collect.testing.google.MapGenerators.ImmutableMapGenerator)1 ImmutableMapKeyListGenerator (com.google.common.collect.testing.google.MapGenerators.ImmutableMapKeyListGenerator)1