Search in sources :

Example 1 with Feature

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

the class MapTestSuiteBuilder method computeCommonDerivedCollectionFeatures.

public static Set<Feature<?>> computeCommonDerivedCollectionFeatures(Set<Feature<?>> mapFeatures) {
    mapFeatures = new HashSet<Feature<?>>(mapFeatures);
    Set<Feature<?>> derivedFeatures = new HashSet<Feature<?>>();
    mapFeatures.remove(CollectionFeature.SERIALIZABLE);
    if (mapFeatures.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
        derivedFeatures.add(CollectionFeature.SERIALIZABLE);
    }
    if (mapFeatures.contains(MapFeature.SUPPORTS_REMOVE)) {
        derivedFeatures.add(CollectionFeature.SUPPORTS_REMOVE);
    }
    if (mapFeatures.contains(MapFeature.REJECTS_DUPLICATES_AT_CREATION)) {
        derivedFeatures.add(CollectionFeature.REJECTS_DUPLICATES_AT_CREATION);
    }
    if (mapFeatures.contains(MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION)) {
        derivedFeatures.add(CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION);
    }
    // add the intersection of CollectionFeature.values() and mapFeatures
    for (CollectionFeature feature : CollectionFeature.values()) {
        if (mapFeatures.contains(feature)) {
            derivedFeatures.add(feature);
        }
    }
    // add the intersection of CollectionSize.values() and mapFeatures
    for (CollectionSize size : CollectionSize.values()) {
        if (mapFeatures.contains(size)) {
            derivedFeatures.add(size);
        }
    }
    return derivedFeatures;
}
Also used : CollectionSize(com.google.common.collect.testing.features.CollectionSize) CollectionFeature(com.google.common.collect.testing.features.CollectionFeature) CollectionFeature(com.google.common.collect.testing.features.CollectionFeature) Feature(com.google.common.collect.testing.features.Feature) MapFeature(com.google.common.collect.testing.features.MapFeature) HashSet(java.util.HashSet)

Example 2 with Feature

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

the class FeatureSpecificTestSuiteBuilder method matches.

private boolean matches(Test test) {
    final Method method;
    try {
        method = extractMethod(test);
    } catch (IllegalArgumentException e) {
        logger.finer(Platform.format("%s: including by default: %s", test, e.getMessage()));
        return true;
    }
    if (suppressedTests.contains(method)) {
        logger.finer(Platform.format("%s: excluding because it was explicitly suppressed.", test));
        return false;
    }
    final TesterRequirements requirements;
    try {
        requirements = FeatureUtil.getTesterRequirements(method);
    } catch (ConflictingRequirementsException e) {
        throw new RuntimeException(e);
    }
    if (!features.containsAll(requirements.getPresentFeatures())) {
        if (logger.isLoggable(FINER)) {
            Set<Feature<?>> missingFeatures = Helpers.copyToSet(requirements.getPresentFeatures());
            missingFeatures.removeAll(features);
            logger.finer(Platform.format("%s: skipping because these features are absent: %s", method, missingFeatures));
        }
        return false;
    }
    if (intersect(features, requirements.getAbsentFeatures())) {
        if (logger.isLoggable(FINER)) {
            Set<Feature<?>> unwantedFeatures = Helpers.copyToSet(requirements.getAbsentFeatures());
            unwantedFeatures.retainAll(features);
            logger.finer(Platform.format("%s: skipping because these features are present: %s", method, unwantedFeatures));
        }
        return false;
    }
    return true;
}
Also used : TesterRequirements(com.google.common.collect.testing.features.TesterRequirements) ConflictingRequirementsException(com.google.common.collect.testing.features.ConflictingRequirementsException) Method(java.lang.reflect.Method) Feature(com.google.common.collect.testing.features.Feature)

Example 3 with Feature

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

the class PerCollectionSizeTestSuiteBuilder method createTestSuite.

/**
   * Creates a runnable JUnit test suite based on the criteria already given.
   */
@Override
public TestSuite createTestSuite() {
    checkCanCreate();
    String name = getName();
    // Copy this set, so we can modify it.
    Set<Feature<?>> features = Helpers.copyToSet(getFeatures());
    List<Class<? extends AbstractTester>> testers = getTesters();
    logger.fine(" Testing: " + name);
    // Split out all the specified sizes.
    Set<Feature<?>> sizesToTest = Helpers.<Feature<?>>copyToSet(CollectionSize.values());
    sizesToTest.retainAll(features);
    features.removeAll(sizesToTest);
    FeatureUtil.addImpliedFeatures(sizesToTest);
    sizesToTest.retainAll(Arrays.asList(CollectionSize.ZERO, CollectionSize.ONE, CollectionSize.SEVERAL));
    logger.fine("   Sizes: " + formatFeatureSet(sizesToTest));
    if (sizesToTest.isEmpty()) {
        throw new IllegalStateException(name + ": no CollectionSizes specified (check the argument to " + "FeatureSpecificTestSuiteBuilder.withFeatures().)");
    }
    TestSuite suite = new TestSuite(name);
    for (Feature<?> collectionSize : sizesToTest) {
        String oneSizeName = Platform.format("%s [collection size: %s]", name, collectionSize.toString().toLowerCase());
        OneSizeGenerator<T, E> oneSizeGenerator = new OneSizeGenerator<T, E>(getSubjectGenerator(), (CollectionSize) collectionSize);
        Set<Feature<?>> oneSizeFeatures = Helpers.copyToSet(features);
        oneSizeFeatures.add(collectionSize);
        Set<Method> oneSizeSuppressedTests = getSuppressedTests();
        OneSizeTestSuiteBuilder<T, E> oneSizeBuilder = new OneSizeTestSuiteBuilder<T, E>(testers).named(oneSizeName).usingGenerator(oneSizeGenerator).withFeatures(oneSizeFeatures).withSetUp(getSetUp()).withTearDown(getTearDown()).suppressing(oneSizeSuppressedTests);
        TestSuite oneSizeSuite = oneSizeBuilder.createTestSuite();
        suite.addTest(oneSizeSuite);
        for (TestSuite derivedSuite : createDerivedSuites(oneSizeBuilder)) {
            oneSizeSuite.addTest(derivedSuite);
        }
    }
    return suite;
}
Also used : Method(java.lang.reflect.Method) Feature(com.google.common.collect.testing.features.Feature) TestSuite(junit.framework.TestSuite)

Example 4 with Feature

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

the class BiMapTestSuiteBuilder method computeCommonDerivedCollectionFeatures.

private static Set<Feature<?>> computeCommonDerivedCollectionFeatures(Set<Feature<?>> mapFeatures) {
    Set<Feature<?>> derivedFeatures = new HashSet<Feature<?>>();
    if (mapFeatures.contains(MapFeature.SUPPORTS_REMOVE)) {
        derivedFeatures.add(CollectionFeature.SUPPORTS_REMOVE);
        derivedFeatures.add(CollectionFeature.SUPPORTS_REMOVE_ALL);
        derivedFeatures.add(CollectionFeature.SUPPORTS_RETAIN_ALL);
    }
    if (mapFeatures.contains(MapFeature.SUPPORTS_CLEAR)) {
        derivedFeatures.add(CollectionFeature.SUPPORTS_CLEAR);
    }
    if (mapFeatures.contains(MapFeature.REJECTS_DUPLICATES_AT_CREATION)) {
        derivedFeatures.add(CollectionFeature.REJECTS_DUPLICATES_AT_CREATION);
    }
    // add the intersection of CollectionSize.values() and mapFeatures
    for (CollectionSize size : CollectionSize.values()) {
        if (mapFeatures.contains(size)) {
            derivedFeatures.add(size);
        }
    }
    return derivedFeatures;
}
Also used : CollectionSize(com.google.common.collect.testing.features.CollectionSize) CollectionFeature(com.google.common.collect.testing.features.CollectionFeature) Feature(com.google.common.collect.testing.features.Feature) MapFeature(com.google.common.collect.testing.features.MapFeature) HashSet(java.util.HashSet)

Example 5 with Feature

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

the class PerCollectionSizeTestSuiteBuilder method createTestSuite.

/**
   * Creates a runnable JUnit test suite based on the criteria already given.
   */
@Override
public TestSuite createTestSuite() {
    checkCanCreate();
    String name = getName();
    // Copy this set, so we can modify it.
    Set<Feature<?>> features = Helpers.copyToSet(getFeatures());
    List<Class<? extends AbstractTester>> testers = getTesters();
    logger.fine(" Testing: " + name);
    // Split out all the specified sizes.
    Set<Feature<?>> sizesToTest = Helpers.<Feature<?>>copyToSet(CollectionSize.values());
    sizesToTest.retainAll(features);
    features.removeAll(sizesToTest);
    FeatureUtil.addImpliedFeatures(sizesToTest);
    sizesToTest.retainAll(Arrays.asList(CollectionSize.ZERO, CollectionSize.ONE, CollectionSize.SEVERAL));
    logger.fine("   Sizes: " + formatFeatureSet(sizesToTest));
    if (sizesToTest.isEmpty()) {
        throw new IllegalStateException(name + ": no CollectionSizes specified (check the argument to " + "FeatureSpecificTestSuiteBuilder.withFeatures().)");
    }
    TestSuite suite = new TestSuite(name);
    for (Feature<?> collectionSize : sizesToTest) {
        String oneSizeName = Platform.format("%s [collection size: %s]", name, collectionSize.toString().toLowerCase());
        OneSizeGenerator<T, E> oneSizeGenerator = new OneSizeGenerator<T, E>(getSubjectGenerator(), (CollectionSize) collectionSize);
        Set<Feature<?>> oneSizeFeatures = Helpers.copyToSet(features);
        oneSizeFeatures.add(collectionSize);
        Set<Method> oneSizeSuppressedTests = getSuppressedTests();
        OneSizeTestSuiteBuilder<T, E> oneSizeBuilder = new OneSizeTestSuiteBuilder<T, E>(testers).named(oneSizeName).usingGenerator(oneSizeGenerator).withFeatures(oneSizeFeatures).withSetUp(getSetUp()).withTearDown(getTearDown()).suppressing(oneSizeSuppressedTests);
        TestSuite oneSizeSuite = oneSizeBuilder.createTestSuite();
        suite.addTest(oneSizeSuite);
        for (TestSuite derivedSuite : createDerivedSuites(oneSizeBuilder)) {
            oneSizeSuite.addTest(derivedSuite);
        }
    }
    return suite;
}
Also used : Method(java.lang.reflect.Method) Feature(com.google.common.collect.testing.features.Feature) TestSuite(junit.framework.TestSuite)

Aggregations

Feature (com.google.common.collect.testing.features.Feature)8 Method (java.lang.reflect.Method)4 HashSet (java.util.HashSet)4 CollectionFeature (com.google.common.collect.testing.features.CollectionFeature)3 CollectionSize (com.google.common.collect.testing.features.CollectionSize)3 MapFeature (com.google.common.collect.testing.features.MapFeature)3 ConflictingRequirementsException (com.google.common.collect.testing.features.ConflictingRequirementsException)2 TesterRequirements (com.google.common.collect.testing.features.TesterRequirements)2 TestSuite (junit.framework.TestSuite)2 ImmutableList (com.google.common.collect.ImmutableList)1 SortedMultiset (com.google.common.collect.SortedMultiset)1 SERIALIZABLE (com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1