Search in sources :

Example 11 with TestStringMultisetGenerator

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

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) TestSuite(junit.framework.TestSuite) Collection(java.util.Collection) TestStringMultisetGenerator(com.google.common.collect.testing.google.TestStringMultisetGenerator)

Example 12 with TestStringMultisetGenerator

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

the class MultisetCollectionTest method suite.

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(MultisetTestSuiteBuilder.using(hashMultisetGenerator()).withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.SERIALIZABLE, CollectionFeature.GENERAL_PURPOSE).named("HashMultiset").createTestSuite());
    suite.addTest(MultisetTestSuiteBuilder.using(unmodifiableMultisetGenerator()).withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).named("UnmodifiableTreeMultiset").createTestSuite());
    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).named("TreeMultiset, Ordering.natural").createTestSuite());
    suite.addTest(SortedMultisetTestSuiteBuilder.using(new TestStringMultisetGenerator() {

        @Override
        protected Multiset<String> create(String[] elements) {
            Multiset<String> result = TreeMultiset.create(new NullsBeforeB());
            result.addAll(Arrays.asList(elements));
            return result;
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            return new NullsBeforeB().sortedCopy(insertionOrder);
        }
    }).withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.GENERAL_PURPOSE, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_VALUES).named("TreeMultiset, NullsBeforeB").createTestSuite());
    suite.addTest(MultisetTestSuiteBuilder.using(forSetGenerator()).withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.SERIALIZABLE, CollectionFeature.REMOVE_OPERATIONS).suppressing(getReadsDuplicateInitializingMethods()).suppressing(getSetCountDuplicateInitializingMethods()).suppressing(getIteratorDuplicateInitializingMethods()).named("ForSetMultiset").createTestSuite());
    suite.addTest(MultisetTestSuiteBuilder.using(concurrentMultisetGenerator()).withFeatures(CollectionSize.ANY, CollectionFeature.GENERAL_PURPOSE, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).named("ConcurrentHashMultiset").createTestSuite());
    suite.addTest(MultisetTestSuiteBuilder.using(enumMultisetGenerator()).withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.GENERAL_PURPOSE, CollectionFeature.ALLOWS_NULL_QUERIES).named("EnumMultiset").createTestSuite());
    suite.addTest(MultisetTestSuiteBuilder.using(intersectionGenerator()).withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.KNOWN_ORDER).named("IntersectionMultiset").createTestSuite());
    suite.addTest(SortedMultisetTestSuiteBuilder.using(unmodifiableSortedMultisetGenerator()).withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.ALLOWS_NULL_QUERIES).named("UnmodifiableSortedTreeMultiset").createTestSuite());
    return suite;
}
Also used : TestSuite(junit.framework.TestSuite) TestStringMultisetGenerator(com.google.common.collect.testing.google.TestStringMultisetGenerator) List(java.util.List) Arrays.asList(java.util.Arrays.asList)

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