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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations