|
Java example source code file (TestsForSetsInJavaUtil.java)
The TestsForSetsInJavaUtil.java Java example source code/* * Copyright (C) 2009 The Guava Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.collect.testing; import com.google.common.annotations.GwtIncompatible; import com.google.common.collect.testing.features.CollectionFeature; import com.google.common.collect.testing.features.CollectionSize; import com.google.common.collect.testing.features.SetFeature; import junit.framework.Test; import junit.framework.TestSuite; import java.io.Serializable; import java.lang.reflect.Method; import java.util.AbstractSet; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.EnumSet; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.CopyOnWriteArraySet; /** * Generates a test suite covering the {@link Set} implementations in the * {@link java.util} package. Can be subclassed to specify tests that should * be suppressed. * * @author Kevin Bourrillion */ @GwtIncompatible public class TestsForSetsInJavaUtil { public static Test suite() { return new TestsForSetsInJavaUtil().allTests(); } public Test allTests() { TestSuite suite = new TestSuite("java.util Sets"); suite.addTest(testsForEmptySet()); suite.addTest(testsForSingletonSet()); suite.addTest(testsForHashSet()); suite.addTest(testsForLinkedHashSet()); suite.addTest(testsForEnumSet()); suite.addTest(testsForTreeSetNatural()); suite.addTest(testsForTreeSetWithComparator()); suite.addTest(testsForCopyOnWriteArraySet()); suite.addTest(testsForUnmodifiableSet()); suite.addTest(testsForCheckedSet()); suite.addTest(testsForAbstractSet()); suite.addTest(testsForBadlyCollidingHashSet()); suite.addTest(testsForConcurrentSkipListSetNatural()); suite.addTest(testsForConcurrentSkipListSetWithComparator()); return suite; } protected Collection<Method> suppressForEmptySet() { return Collections.emptySet(); } protected Collection<Method> suppressForSingletonSet() { return Collections.emptySet(); } protected Collection<Method> suppressForHashSet() { return Collections.emptySet(); } protected Collection<Method> suppressForLinkedHashSet() { return Collections.emptySet(); } protected Collection<Method> suppressForEnumSet() { return Collections.emptySet(); } protected Collection<Method> suppressForTreeSetNatural() { return Collections.emptySet(); } protected Collection<Method> suppressForTreeSetWithComparator() { return Collections.emptySet(); } protected Collection<Method> suppressForCopyOnWriteArraySet() { return Collections.emptySet(); } protected Collection<Method> suppressForUnmodifiableSet() { return Collections.emptySet(); } protected Collection<Method> suppressForCheckedSet() { return Collections.emptySet(); } protected Collection<Method> suppressForAbstractSet() { return Collections.emptySet(); } protected Collection<Method> suppressForConcurrentSkipListSetNatural() { return Collections.emptySet(); } protected Collection<Method> suppressForConcurrentSkipListSetWithComparator() { return Collections.emptySet(); } public Test testsForEmptySet() { return SetTestSuiteBuilder.using( new TestStringSetGenerator() { @Override public Set<String> create(String[] elements) { return Collections.emptySet(); } }) .named("emptySet") .withFeatures(CollectionFeature.SERIALIZABLE, CollectionSize.ZERO) .suppressing(suppressForEmptySet()) .createTestSuite(); } public Test testsForSingletonSet() { return SetTestSuiteBuilder.using( new TestStringSetGenerator() { @Override public Set<String> create(String[] elements) { return Collections.singleton(elements[0]); } }) .named("singleton") .withFeatures( CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_VALUES, CollectionSize.ONE) .suppressing(suppressForSingletonSet()) .createTestSuite(); } public Test testsForHashSet() { return SetTestSuiteBuilder.using( new TestStringSetGenerator() { @Override public Set<String> create(String[] elements) { return new HashSet<String>(MinimalCollection.of(elements)); } }) .named("HashSet") .withFeatures( SetFeature.GENERAL_PURPOSE, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION, CollectionSize.ANY) .suppressing(suppressForHashSet()) .createTestSuite(); } public Test testsForLinkedHashSet() { return SetTestSuiteBuilder.using( new TestStringSetGenerator() { @Override public Set<String> create(String[] elements) { return new LinkedHashSet<String>(MinimalCollection.of(elements)); } }) .named("LinkedHashSet") .withFeatures( SetFeature.GENERAL_PURPOSE, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.KNOWN_ORDER, CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION, CollectionSize.ANY) .suppressing(suppressForLinkedHashSet()) .createTestSuite(); } public Test testsForEnumSet() { return SetTestSuiteBuilder.using( new TestEnumSetGenerator() { @Override public Set<AnEnum> create(AnEnum[] elements) { return (elements.length == 0) ? EnumSet.noneOf(AnEnum.class) : EnumSet.copyOf(MinimalCollection.of(elements)); } }) .named("EnumSet") .withFeatures( SetFeature.GENERAL_PURPOSE, CollectionFeature.SERIALIZABLE, CollectionFeature.KNOWN_ORDER, CollectionFeature.RESTRICTS_ELEMENTS, CollectionSize.ANY) .suppressing(suppressForEnumSet()) .createTestSuite(); } public Test testsForTreeSetNatural() { return NavigableSetTestSuiteBuilder.using( new TestStringSortedSetGenerator() { @Override public SortedSet<String> create(String[] elements) { return new TreeSet<String>(MinimalCollection.of(elements)); } }) .named("TreeSet, natural") .withFeatures( SetFeature.GENERAL_PURPOSE, CollectionFeature.SERIALIZABLE, CollectionFeature.KNOWN_ORDER, CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION, CollectionSize.ANY) .suppressing(suppressForTreeSetNatural()) .createTestSuite(); } public Test testsForTreeSetWithComparator() { return NavigableSetTestSuiteBuilder.using( new TestStringSortedSetGenerator() { @Override public SortedSet<String> create(String[] elements) { SortedSet<String> set = new TreeSet Other Java examples (source code examples)Here is a short list of links related to this Java TestsForSetsInJavaUtil.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.