Search in sources :

Example 6 with Feature

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

the class SortedMultisetTestSuiteBuilder method createSubMultisetSuite.

private TestSuite createSubMultisetSuite(SortedMultisetTestSuiteBuilder<E> parentBuilder, final Bound from, final Bound to) {
    final TestMultisetGenerator<E> delegate = (TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();
    Set<Feature<?>> features = new HashSet<Feature<?>>();
    features.add(NoRecurse.SUBMULTISET);
    features.add(RESTRICTS_ELEMENTS);
    features.addAll(parentBuilder.getFeatures());
    if (!features.remove(SERIALIZABLE_INCLUDING_VIEWS)) {
        features.remove(SERIALIZABLE);
    }
    SortedMultiset<E> emptyMultiset = (SortedMultiset<E>) delegate.create();
    final Comparator<? super E> comparator = emptyMultiset.comparator();
    SampleElements<E> samples = delegate.samples();
    @SuppressWarnings("unchecked") List<E> samplesList = Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());
    Collections.sort(samplesList, comparator);
    final E firstInclusive = samplesList.get(0);
    final E lastInclusive = samplesList.get(samplesList.size() - 1);
    return SortedMultisetTestSuiteBuilder.using(new ForwardingTestMultisetGenerator<E>(delegate) {

        @Override
        public SortedMultiset<E> create(Object... entries) {
            @SuppressWarnings("unchecked") List<E> // we dangerously assume E is a string
            extremeValues = (List) getExtremeValues();
            @SuppressWarnings("unchecked") List<E> // map generators must past entry objects
            normalValues = (List) Arrays.asList(entries);
            // prepare extreme values to be filtered out of view
            Collections.sort(extremeValues, comparator);
            E firstExclusive = extremeValues.get(1);
            E lastExclusive = extremeValues.get(2);
            if (from == Bound.NO_BOUND) {
                extremeValues.remove(0);
                extremeValues.remove(0);
            }
            if (to == Bound.NO_BOUND) {
                extremeValues.remove(extremeValues.size() - 1);
                extremeValues.remove(extremeValues.size() - 1);
            }
            // the regular values should be visible after filtering
            List<E> allEntries = new ArrayList<E>();
            allEntries.addAll(extremeValues);
            allEntries.addAll(normalValues);
            SortedMultiset<E> multiset = (SortedMultiset<E>) delegate.create(allEntries.toArray());
            // values
            if (from == Bound.INCLUSIVE) {
                multiset = multiset.tailMultiset(firstInclusive, BoundType.CLOSED);
            } else if (from == Bound.EXCLUSIVE) {
                multiset = multiset.tailMultiset(firstExclusive, BoundType.OPEN);
            }
            if (to == Bound.INCLUSIVE) {
                multiset = multiset.headMultiset(lastInclusive, BoundType.CLOSED);
            } else if (to == Bound.EXCLUSIVE) {
                multiset = multiset.headMultiset(lastExclusive, BoundType.OPEN);
            }
            return multiset;
        }
    }).named(parentBuilder.getName() + " subMultiset " + from + "-" + to).withFeatures(features).suppressing(parentBuilder.getSuppressedTests()).createTestSuite();
}
Also used : SERIALIZABLE(com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE) Feature(com.google.common.collect.testing.features.Feature) SortedMultiset(com.google.common.collect.SortedMultiset) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HashSet(java.util.HashSet)

Example 7 with Feature

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

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 8 with Feature

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

the class MapTestSuiteBuilder method computeCommonDerivedCollectionFeatures.

private static Set<Feature<?>> computeCommonDerivedCollectionFeatures(Set<Feature<?>> mapFeatures) {
    Set<Feature<?>> derivedFeatures = new HashSet<Feature<?>>();
    if (mapFeatures.contains(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
        derivedFeatures.add(CollectionFeature.SERIALIZABLE);
    }
    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);
    }
    if (mapFeatures.contains(MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION)) {
        derivedFeatures.add(CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION);
    }
    // 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)

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