Search in sources :

Example 1 with TestStringMultisetGenerator

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;
}
Also used : Set(java.util.Set) TestStringSetGenerator(com.google.common.collect.testing.TestStringSetGenerator) Entry(com.google.common.collect.Multiset.Entry) TestSuite(junit.framework.TestSuite) Collection(java.util.Collection) TestStringMultisetGenerator(com.google.common.collect.testing.google.TestStringMultisetGenerator)

Example 2 with TestStringMultisetGenerator

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;
}
Also used : TestSuite(junit.framework.TestSuite) TestStringMultisetGenerator(com.google.common.collect.testing.google.TestStringMultisetGenerator) List(java.util.List)

Example 3 with TestStringMultisetGenerator

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;
}
Also used : TestStringSetGenerator(com.google.common.collect.testing.TestStringSetGenerator) SortedSet(java.util.SortedSet) Set(java.util.Set) TestSuite(junit.framework.TestSuite) TestStringMultisetGenerator(com.google.common.collect.testing.google.TestStringMultisetGenerator) List(java.util.List) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 4 with TestStringMultisetGenerator

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;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ListTestSuiteBuilder(com.google.common.collect.testing.ListTestSuiteBuilder) SetTestSuiteBuilder(com.google.common.collect.testing.SetTestSuiteBuilder) MultisetTestSuiteBuilder(com.google.common.collect.testing.google.MultisetTestSuiteBuilder) TestStringListGenerator(com.google.common.collect.testing.TestStringListGenerator) TestStringSetGenerator(com.google.common.collect.testing.TestStringSetGenerator) TestSuite(junit.framework.TestSuite) TestStringMultisetGenerator(com.google.common.collect.testing.google.TestStringMultisetGenerator) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 5 with TestStringMultisetGenerator

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;
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) TestStringSetGenerator(com.google.common.collect.testing.TestStringSetGenerator) Helpers.mapEntry(com.google.common.collect.testing.Helpers.mapEntry) Entry(java.util.Map.Entry) TestSuite(junit.framework.TestSuite) TestStringListMultimapGenerator(com.google.common.collect.testing.google.TestStringListMultimapGenerator) TestStringMultisetGenerator(com.google.common.collect.testing.google.TestStringMultisetGenerator)

Aggregations

TestStringMultisetGenerator (com.google.common.collect.testing.google.TestStringMultisetGenerator)12 TestSuite (junit.framework.TestSuite)12 Set (java.util.Set)9 TestStringSetGenerator (com.google.common.collect.testing.TestStringSetGenerator)8 List (java.util.List)7 GwtIncompatible (com.google.common.annotations.GwtIncompatible)4 Arrays.asList (java.util.Arrays.asList)4 ListTestSuiteBuilder (com.google.common.collect.testing.ListTestSuiteBuilder)3 TestStringListGenerator (com.google.common.collect.testing.TestStringListGenerator)3 Collection (java.util.Collection)3 SetTestSuiteBuilder (com.google.common.collect.testing.SetTestSuiteBuilder)2 MultisetTestSuiteBuilder (com.google.common.collect.testing.google.MultisetTestSuiteBuilder)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Entry (java.util.Map.Entry)2 SortedSet (java.util.SortedSet)2 TreeSet (java.util.TreeSet)2 Entry (com.google.common.collect.Multiset.Entry)1 CollectionTestSuiteBuilder (com.google.common.collect.testing.CollectionTestSuiteBuilder)1 Helpers.mapEntry (com.google.common.collect.testing.Helpers.mapEntry)1