Search in sources :

Example 11 with TestStringSetGenerator

use of com.google.common.collect.testing.TestStringSetGenerator 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<>(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<>(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 boolean add(String element) {
                    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 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 12 with TestStringSetGenerator

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

the class ForwardingNavigableSetTest method suite.

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(ForwardingNavigableSetTest.class);
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            return new StandardImplForwardingNavigableSet<>(new SafeTreeSet<String>(Arrays.asList(elements)));
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            return Lists.newArrayList(Sets.newTreeSet(insertionOrder));
        }
    }).named("ForwardingNavigableSet[SafeTreeSet] with standard implementations").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.GENERAL_PURPOSE).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            SafeTreeSet<String> set = new SafeTreeSet<>(Ordering.natural().nullsFirst());
            Collections.addAll(set, elements);
            return new StandardImplForwardingNavigableSet<>(set);
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            return Lists.newArrayList(Sets.newTreeSet(insertionOrder));
        }
    }).named("ForwardingNavigableSet[SafeTreeSet[Ordering.natural.nullsFirst]]" + " with standard implementations").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.GENERAL_PURPOSE, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
    return suite;
}
Also used : SafeTreeSet(com.google.common.collect.testing.SafeTreeSet) TestStringSetGenerator(com.google.common.collect.testing.TestStringSetGenerator) SortedSet(java.util.SortedSet) Set(java.util.Set) NavigableSet(java.util.NavigableSet) SafeTreeSet(com.google.common.collect.testing.SafeTreeSet) TestSuite(junit.framework.TestSuite) List(java.util.List)

Example 13 with TestStringSetGenerator

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

the class ForwardingSetTest method suite.

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(ForwardingSetTest.class);
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            return new StandardImplForwardingSet<>(Sets.newLinkedHashSet(asList(elements)));
        }
    }).named("ForwardingSet[LinkedHashSet] with standard implementations").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.GENERAL_PURPOSE).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            return new StandardImplForwardingSet<>(MinimalSet.of(elements));
        }
    }).named("ForwardingSet[MinimalSet] with standard implementations").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
    return suite;
}
Also used : TestStringSetGenerator(com.google.common.collect.testing.TestStringSetGenerator) MinimalSet(com.google.common.collect.testing.MinimalSet) Set(java.util.Set) TestSuite(junit.framework.TestSuite)

Example 14 with TestStringSetGenerator

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

the class CompactLinkedHashSetTest method suite.

public static Test suite() {
    List<Feature<?>> allFeatures = Arrays.<Feature<?>>asList(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION, CollectionFeature.GENERAL_PURPOSE, CollectionFeature.REMOVE_OPERATIONS, CollectionFeature.SERIALIZABLE, CollectionFeature.KNOWN_ORDER, CollectionFeature.SUPPORTS_ADD, CollectionFeature.SUPPORTS_REMOVE);
    TestSuite suite = new TestSuite();
    suite.addTestSuite(CompactLinkedHashSetTest.class);
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            return CompactLinkedHashSet.create(Arrays.asList(elements));
        }
    }).named("CompactLinkedHashSet").withFeatures(allFeatures).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            CompactLinkedHashSet<String> set = CompactLinkedHashSet.create();
            set.convertToHashFloodingResistantImplementation();
            Collections.addAll(set, elements);
            return set;
        }
    }).named("CompactLinkedHashSet with flooding protection").withFeatures(allFeatures).createTestSuite());
    return suite;
}
Also used : TestStringSetGenerator(com.google.common.collect.testing.TestStringSetGenerator) Set(java.util.Set) TestSuite(junit.framework.TestSuite) CollectionFeature(com.google.common.collect.testing.features.CollectionFeature) Feature(com.google.common.collect.testing.features.Feature)

Example 15 with TestStringSetGenerator

use of com.google.common.collect.testing.TestStringSetGenerator 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.addTestSuite(FloodingTest.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(MultisetTestSuiteBuilder.using(new TestStringMultisetGenerator() {

        @Override
        protected Multiset<String> create(String[] elements) {
            return ImmutableMultiset.<String>builder().add(elements).buildJdkBacked();
        }
    }).named("ImmutableMultiset [JDK backed]").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<>();
            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<>();
            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)

Aggregations

TestStringSetGenerator (com.google.common.collect.testing.TestStringSetGenerator)24 Set (java.util.Set)24 TestSuite (junit.framework.TestSuite)24 List (java.util.List)13 GwtIncompatible (com.google.common.annotations.GwtIncompatible)11 SortedSet (java.util.SortedSet)10 TestStringMultisetGenerator (com.google.common.collect.testing.google.TestStringMultisetGenerator)8 SafeTreeSet (com.google.common.collect.testing.SafeTreeSet)6 Collection (java.util.Collection)6 HashSet (java.util.HashSet)6 NavigableSet (java.util.NavigableSet)5 TreeSet (java.util.TreeSet)5 ArrayList (java.util.ArrayList)4 Sets.newEnumSet (com.google.common.collect.Sets.newEnumSet)3 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)3 Sets.powerSet (com.google.common.collect.Sets.powerSet)3 ListTestSuiteBuilder (com.google.common.collect.testing.ListTestSuiteBuilder)3 SampleElements (com.google.common.collect.testing.SampleElements)3 SetTestSuiteBuilder (com.google.common.collect.testing.SetTestSuiteBuilder)3 TestStringCollectionGenerator (com.google.common.collect.testing.TestStringCollectionGenerator)3