Java Code Examples for com.google.common.collect.testing.features.Feature

The following are top voted examples for showing how to use com.google.common.collect.testing.features.Feature. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: guava-mock   File: SortedSetTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a suite whose set has some elements filtered out of view.
 *
 * <p>Because the set may be ascending or descending, this test must derive
 * the relative order of these extreme values rather than relying on their
 * regular sort ordering.
 */
final TestSuite createSubsetSuite(
    final FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<Collection<E>, E>>
        parentBuilder,
    final Bound from,
    final Bound to) {
  final TestSortedSetGenerator<E> delegate =
      (TestSortedSetGenerator<E>) parentBuilder.getSubjectGenerator().getInnerGenerator();

  List<Feature<?>> features = new ArrayList<Feature<?>>();
  features.addAll(parentBuilder.getFeatures());
  features.remove(CollectionFeature.ALLOWS_NULL_VALUES);
  features.add(CollectionFeature.SUBSET_VIEW);

  return newBuilderUsing(delegate, to, from)
      .named(parentBuilder.getName() + " subSet " + from + "-" + to)
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
 
Example 2
Project: guava-mock   File: ListMultimapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
@Override
TestSuite computeMultimapAsMapGetTestSuite(
    FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<ListMultimap<K, V>, Entry<K, V>>>
        parentBuilder) {
  Set<Feature<?>> features = computeMultimapAsMapGetFeatures(parentBuilder.getFeatures());
  if (Collections.disjoint(features, EnumSet.allOf(CollectionSize.class))) {
    return new TestSuite();
  } else {
    return ListTestSuiteBuilder.using(
            new MultimapAsMapGetGenerator<K, V>(parentBuilder.getSubjectGenerator()))
        .withFeatures(features)
        .named(parentBuilder.getName() + ".asMap[].get[key]")
        .suppressing(parentBuilder.getSuppressedTests())
        .createTestSuite();
  }
}
 
Example 3
Project: guava-mock   File: SetMultimapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
@Override
TestSuite computeMultimapAsMapGetTestSuite(
    FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<SetMultimap<K, V>, Entry<K, V>>>
        parentBuilder) {
  Set<Feature<?>> features = computeMultimapAsMapGetFeatures(parentBuilder.getFeatures());
  if (Collections.disjoint(features, EnumSet.allOf(CollectionSize.class))) {
    return new TestSuite();
  } else {
    return SetTestSuiteBuilder.using(
            new MultimapAsMapGetGenerator<K, V>(parentBuilder.getSubjectGenerator()))
        .withFeatures(features)
        .named(parentBuilder.getName() + ".asMap[].get[key]")
        .suppressing(parentBuilder.getSuppressedTests())
        .createTestSuite();
  }
}
 
Example 4
Project: guava-mock   File: BiMapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
private static Set<Feature<?>> computeInverseFeatures(Set<Feature<?>> mapFeatures) {
  Set<Feature<?>> inverseFeatures = new HashSet<Feature<?>>(mapFeatures);

  boolean nullKeys = inverseFeatures.remove(MapFeature.ALLOWS_NULL_KEYS);
  boolean nullValues = inverseFeatures.remove(MapFeature.ALLOWS_NULL_VALUES);

  if (nullKeys) {
    inverseFeatures.add(MapFeature.ALLOWS_NULL_VALUES);
  }
  if (nullValues) {
    inverseFeatures.add(MapFeature.ALLOWS_NULL_KEYS);
  }

  inverseFeatures.add(NoRecurse.INVERSE);
  inverseFeatures.remove(CollectionFeature.KNOWN_ORDER);
  inverseFeatures.add(MapFeature.REJECTS_DUPLICATES_AT_CREATION);

  return inverseFeatures;
}
 
Example 5
Project: guava-mock   File: SortedMultisetTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
private TestSuite createReserializedSuite(SortedMultisetTestSuiteBuilder<E> parentBuilder) {
  final TestMultisetGenerator<E> delegate =
      (TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();

  Set<Feature<?>> features = new HashSet<Feature<?>>();
  features.addAll(parentBuilder.getFeatures());
  features.remove(SERIALIZABLE);
  features.remove(SERIALIZABLE_INCLUDING_VIEWS);

  return SortedMultisetTestSuiteBuilder.using(
          new ForwardingTestMultisetGenerator<E>(delegate) {
            @Override
            public SortedMultiset<E> create(Object... entries) {
              return SerializableTester.reserialize(((SortedMultiset<E>) super.create(entries)));
            }
          })
      .named(parentBuilder.getName() + " reserialized")
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
 
Example 6
Project: guava-mock   File: SortedSetMultimapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
@Override
TestSuite computeMultimapAsMapGetTestSuite(
    FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<SetMultimap<K, V>, Entry<K, V>>>
        parentBuilder) {
  Set<Feature<?>> features = computeMultimapAsMapGetFeatures(parentBuilder.getFeatures());
  if (Collections.disjoint(features, EnumSet.allOf(CollectionSize.class))) {
    return new TestSuite();
  } else {
    return SortedSetTestSuiteBuilder.using(
            new SetMultimapTestSuiteBuilder.MultimapAsMapGetGenerator<K, V>(
                parentBuilder.getSubjectGenerator()))
        .withFeatures(features)
        .named(parentBuilder.getName() + ".asMap[].get[key]")
        .suppressing(parentBuilder.getSuppressedTests())
        .createTestSuite();
  }
}
 
Example 7
Project: guava-mock   File: MultimapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
TestSuite computeMultimapAsMapGetTestSuite(
    FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<M, Map.Entry<K, V>>>
        parentBuilder) {
  Set<Feature<?>> features = computeMultimapAsMapGetFeatures(parentBuilder.getFeatures());
  if (Collections.disjoint(features, EnumSet.allOf(CollectionSize.class))) {
    return new TestSuite();
  } else {
    return CollectionTestSuiteBuilder.using(
            new MultimapAsMapGetGenerator<K, V, M>(parentBuilder.getSubjectGenerator()))
        .withFeatures(features)
        .named(parentBuilder.getName() + ".asMap[].get[key]")
        .suppressing(parentBuilder.getSuppressedTests())
        .createTestSuite();
  }
}
 
Example 8
Project: guava-mock   File: MultimapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
Set<Feature<?>> computeMultimapGetFeatures(Set<Feature<?>> multimapFeatures) {
  Set<Feature<?>> derivedFeatures = Helpers.copyToSet(multimapFeatures);
  for (Map.Entry<Feature<?>, Feature<?>> entry : GET_FEATURE_MAP.entries()) {
    if (derivedFeatures.contains(entry.getKey())) {
      derivedFeatures.add(entry.getValue());
    }
  }
  if (derivedFeatures.remove(MultimapFeature.VALUE_COLLECTIONS_SUPPORT_ITERATOR_REMOVE)) {
    derivedFeatures.add(CollectionFeature.SUPPORTS_ITERATOR_REMOVE);
  }
  if (!derivedFeatures.contains(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
    derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
  }
  derivedFeatures.removeAll(GET_FEATURE_MAP.keySet());
  return derivedFeatures;
}
 
Example 9
Project: guava-mock   File: NavigableMapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
/**
 * Create a suite whose maps are descending views of other maps.
 */
private TestSuite createDescendingSuite(
    final FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>>>
        parentBuilder) {
  final TestSortedMapGenerator<K, V> delegate =
      (TestSortedMapGenerator<K, V>) parentBuilder.getSubjectGenerator().getInnerGenerator();

  List<Feature<?>> features = new ArrayList<Feature<?>>();
  features.add(NoRecurse.DESCENDING);
  features.addAll(parentBuilder.getFeatures());

  return subSuiteUsing(new DescendingTestMapGenerator<K, V>(delegate))
      .named(parentBuilder.getName() + " descending")
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
 
Example 10
Project: guava-mock   File: SortedMapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a suite whose map has some elements filtered out of view.
 *
 * <p>Because the map may be ascending or descending, this test must derive
 * the relative order of these extreme values rather than relying on their
 * regular sort ordering.
 */
final TestSuite createSubmapSuite(
    final FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>>>
        parentBuilder,
    final Bound from,
    final Bound to) {
  final TestSortedMapGenerator<K, V> delegate =
      (TestSortedMapGenerator<K, V>) parentBuilder.getSubjectGenerator().getInnerGenerator();

  List<Feature<?>> features = new ArrayList<Feature<?>>();
  features.add(NoRecurse.SUBMAP);
  features.addAll(parentBuilder.getFeatures());

  return newBuilderUsing(delegate, to, from)
      .named(parentBuilder.getName() + " subMap " + from + "-" + to)
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
 
Example 11
Project: googles-monorepo-demo   File: SortedSetTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a suite whose set has some elements filtered out of view.
 *
 * <p>Because the set may be ascending or descending, this test must derive
 * the relative order of these extreme values rather than relying on their
 * regular sort ordering.
 */
final TestSuite createSubsetSuite(
    final FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<Collection<E>, E>>
        parentBuilder,
    final Bound from,
    final Bound to) {
  final TestSortedSetGenerator<E> delegate =
      (TestSortedSetGenerator<E>) parentBuilder.getSubjectGenerator().getInnerGenerator();

  List<Feature<?>> features = new ArrayList<Feature<?>>();
  features.addAll(parentBuilder.getFeatures());
  features.remove(CollectionFeature.ALLOWS_NULL_VALUES);
  features.add(CollectionFeature.SUBSET_VIEW);

  return newBuilderUsing(delegate, to, from)
      .named(parentBuilder.getName() + " subSet " + from + "-" + to)
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
 
Example 12
Project: googles-monorepo-demo   File: ListMultimapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
@Override
TestSuite computeMultimapAsMapGetTestSuite(
    FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<ListMultimap<K, V>, Entry<K, V>>>
        parentBuilder) {
  Set<Feature<?>> features = computeMultimapAsMapGetFeatures(parentBuilder.getFeatures());
  if (Collections.disjoint(features, EnumSet.allOf(CollectionSize.class))) {
    return new TestSuite();
  } else {
    return ListTestSuiteBuilder.using(
            new MultimapAsMapGetGenerator<K, V>(parentBuilder.getSubjectGenerator()))
        .withFeatures(features)
        .named(parentBuilder.getName() + ".asMap[].get[key]")
        .suppressing(parentBuilder.getSuppressedTests())
        .createTestSuite();
  }
}
 
Example 13
Project: googles-monorepo-demo   File: SetMultimapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
@Override
TestSuite computeMultimapAsMapGetTestSuite(
    FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<SetMultimap<K, V>, Entry<K, V>>>
        parentBuilder) {
  Set<Feature<?>> features = computeMultimapAsMapGetFeatures(parentBuilder.getFeatures());
  if (Collections.disjoint(features, EnumSet.allOf(CollectionSize.class))) {
    return new TestSuite();
  } else {
    return SetTestSuiteBuilder.using(
            new MultimapAsMapGetGenerator<K, V>(parentBuilder.getSubjectGenerator()))
        .withFeatures(features)
        .named(parentBuilder.getName() + ".asMap[].get[key]")
        .suppressing(parentBuilder.getSuppressedTests())
        .createTestSuite();
  }
}
 
Example 14
Project: googles-monorepo-demo   File: BiMapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
private static Set<Feature<?>> computeInverseFeatures(Set<Feature<?>> mapFeatures) {
  Set<Feature<?>> inverseFeatures = new HashSet<Feature<?>>(mapFeatures);

  boolean nullKeys = inverseFeatures.remove(MapFeature.ALLOWS_NULL_KEYS);
  boolean nullValues = inverseFeatures.remove(MapFeature.ALLOWS_NULL_VALUES);

  if (nullKeys) {
    inverseFeatures.add(MapFeature.ALLOWS_NULL_VALUES);
  }
  if (nullValues) {
    inverseFeatures.add(MapFeature.ALLOWS_NULL_KEYS);
  }

  inverseFeatures.add(NoRecurse.INVERSE);
  inverseFeatures.remove(CollectionFeature.KNOWN_ORDER);
  inverseFeatures.add(MapFeature.REJECTS_DUPLICATES_AT_CREATION);

  return inverseFeatures;
}
 
Example 15
Project: googles-monorepo-demo   File: SortedMultisetTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
private TestSuite createReserializedSuite(SortedMultisetTestSuiteBuilder<E> parentBuilder) {
  final TestMultisetGenerator<E> delegate =
      (TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();

  Set<Feature<?>> features = new HashSet<Feature<?>>();
  features.addAll(parentBuilder.getFeatures());
  features.remove(SERIALIZABLE);
  features.remove(SERIALIZABLE_INCLUDING_VIEWS);

  return SortedMultisetTestSuiteBuilder.using(
          new ForwardingTestMultisetGenerator<E>(delegate) {
            @Override
            public SortedMultiset<E> create(Object... entries) {
              return SerializableTester.reserialize(((SortedMultiset<E>) super.create(entries)));
            }
          })
      .named(parentBuilder.getName() + " reserialized")
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
 
Example 16
Project: googles-monorepo-demo   File: MultimapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
TestSuite computeMultimapAsMapGetTestSuite(
    FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<M, Map.Entry<K, V>>>
        parentBuilder) {
  Set<Feature<?>> features = computeMultimapAsMapGetFeatures(parentBuilder.getFeatures());
  if (Collections.disjoint(features, EnumSet.allOf(CollectionSize.class))) {
    return new TestSuite();
  } else {
    return CollectionTestSuiteBuilder.using(
            new MultimapAsMapGetGenerator<K, V, M>(parentBuilder.getSubjectGenerator()))
        .withFeatures(features)
        .named(parentBuilder.getName() + ".asMap[].get[key]")
        .suppressing(parentBuilder.getSuppressedTests())
        .createTestSuite();
  }
}
 
Example 17
Project: googles-monorepo-demo   File: MultimapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
Set<Feature<?>> computeMultimapGetFeatures(Set<Feature<?>> multimapFeatures) {
  Set<Feature<?>> derivedFeatures = Helpers.copyToSet(multimapFeatures);
  for (Map.Entry<Feature<?>, Feature<?>> entry : GET_FEATURE_MAP.entries()) {
    if (derivedFeatures.contains(entry.getKey())) {
      derivedFeatures.add(entry.getValue());
    }
  }
  if (derivedFeatures.remove(MultimapFeature.VALUE_COLLECTIONS_SUPPORT_ITERATOR_REMOVE)) {
    derivedFeatures.add(CollectionFeature.SUPPORTS_ITERATOR_REMOVE);
  }
  if (!derivedFeatures.contains(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
    derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
  }
  derivedFeatures.removeAll(GET_FEATURE_MAP.keySet());
  return derivedFeatures;
}
 
Example 18
Project: googles-monorepo-demo   File: NavigableMapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
/**
 * Create a suite whose maps are descending views of other maps.
 */
private TestSuite createDescendingSuite(
    final FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>>>
        parentBuilder) {
  final TestSortedMapGenerator<K, V> delegate =
      (TestSortedMapGenerator<K, V>) parentBuilder.getSubjectGenerator().getInnerGenerator();

  List<Feature<?>> features = new ArrayList<Feature<?>>();
  features.add(NoRecurse.DESCENDING);
  features.addAll(parentBuilder.getFeatures());

  return subSuiteUsing(new DescendingTestMapGenerator<K, V>(delegate))
      .named(parentBuilder.getName() + " descending")
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
 
Example 19
Project: googles-monorepo-demo   File: SortedMapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a suite whose map has some elements filtered out of view.
 *
 * <p>Because the map may be ascending or descending, this test must derive
 * the relative order of these extreme values rather than relying on their
 * regular sort ordering.
 */
final TestSuite createSubmapSuite(
    final FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>>>
        parentBuilder,
    final Bound from,
    final Bound to) {
  final TestSortedMapGenerator<K, V> delegate =
      (TestSortedMapGenerator<K, V>) parentBuilder.getSubjectGenerator().getInnerGenerator();

  List<Feature<?>> features = new ArrayList<Feature<?>>();
  features.add(NoRecurse.SUBMAP);
  features.addAll(parentBuilder.getFeatures());

  return newBuilderUsing(delegate, to, from)
      .named(parentBuilder.getName() + " subMap " + from + "-" + to)
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
 
Example 20
Project: guava-libraries   File: SortedSetTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a suite whose set has some elements filtered out of view.
 *
 * <p>Because the set may be ascending or descending, this test must derive
 * the relative order of these extreme values rather than relying on their
 * regular sort ordering.
 */
final TestSuite createSubsetSuite(final FeatureSpecificTestSuiteBuilder<?,
        ? extends OneSizeTestContainerGenerator<Collection<E>, E>>
        parentBuilder, final Bound from, final Bound to) {
  final TestSortedSetGenerator<E> delegate
      = (TestSortedSetGenerator<E>) parentBuilder.getSubjectGenerator().getInnerGenerator();

  List<Feature<?>> features = new ArrayList<Feature<?>>();
  features.addAll(parentBuilder.getFeatures());
  features.remove(CollectionFeature.ALLOWS_NULL_VALUES);
  features.add(CollectionFeature.SUBSET_VIEW);

  return newBuilderUsing(delegate, to, from)
      .named(parentBuilder.getName() + " subSet " + from + "-" + to)
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
 
Example 21
Project: guava-libraries   File: MapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
private static Set<Feature<?>> computeKeySetFeatures(
    Set<Feature<?>> mapFeatures) {
  Set<Feature<?>> keySetFeatures =
      computeCommonDerivedCollectionFeatures(mapFeatures);

  // TODO(user): make this trigger only if the map is a submap
  // currently, the KeySetGenerator won't work properly for a subset of a keyset of a submap
  keySetFeatures.add(CollectionFeature.SUBSET_VIEW);
  if (mapFeatures.contains(MapFeature.ALLOWS_NULL_KEYS)) {
    keySetFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES);
  } else if (mapFeatures.contains(MapFeature.ALLOWS_NULL_KEY_QUERIES)) {
    keySetFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
  }

  return keySetFeatures;
}
 
Example 22
Project: guava-libraries   File: ListMultimapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
@Override
TestSuite computeMultimapAsMapGetTestSuite(
    FeatureSpecificTestSuiteBuilder<?, ? extends
    OneSizeTestContainerGenerator<ListMultimap<K, V>, Entry<K, V>>> parentBuilder) {
  Set<Feature<?>> features = computeMultimapAsMapGetFeatures(parentBuilder.getFeatures());
  if (Collections.disjoint(features, EnumSet.allOf(CollectionSize.class))) {
    return new TestSuite();
  } else {
    return ListTestSuiteBuilder.using(
        new MultimapAsMapGetGenerator<K, V>(parentBuilder.getSubjectGenerator()))
        .withFeatures(features)
        .named(parentBuilder.getName() + ".asMap[].get[key]")
        .suppressing(parentBuilder.getSuppressedTests())
        .createTestSuite();
  }
}
 
Example 23
Project: guava-libraries   File: SetMultimapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
@Override
TestSuite computeMultimapAsMapGetTestSuite(
    FeatureSpecificTestSuiteBuilder<?, ? extends
    OneSizeTestContainerGenerator<SetMultimap<K, V>, Entry<K, V>>> parentBuilder) {
  Set<Feature<?>> features = computeMultimapAsMapGetFeatures(parentBuilder.getFeatures());
  if (Collections.disjoint(features, EnumSet.allOf(CollectionSize.class))) {
    return new TestSuite();
  } else {
    return SetTestSuiteBuilder.using(
        new MultimapAsMapGetGenerator<K, V>(parentBuilder.getSubjectGenerator()))
        .withFeatures(features)
        .named(parentBuilder.getName() + ".asMap[].get[key]")
        .suppressing(parentBuilder.getSuppressedTests())
        .createTestSuite();
  }
}
 
Example 24
Project: guava-libraries   File: BiMapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
private static Set<Feature<?>> computeInverseFeatures(Set<Feature<?>> mapFeatures) {
  Set<Feature<?>> inverseFeatures = new HashSet<Feature<?>>(mapFeatures);

  boolean nullKeys = inverseFeatures.remove(MapFeature.ALLOWS_NULL_KEYS);
  boolean nullValues = inverseFeatures.remove(MapFeature.ALLOWS_NULL_VALUES);

  if (nullKeys) {
    inverseFeatures.add(MapFeature.ALLOWS_NULL_VALUES);
  }
  if (nullValues) {
    inverseFeatures.add(MapFeature.ALLOWS_NULL_KEYS);
  }

  inverseFeatures.add(NoRecurse.INVERSE);
  inverseFeatures.remove(CollectionFeature.KNOWN_ORDER);
  inverseFeatures.add(MapFeature.REJECTS_DUPLICATES_AT_CREATION);

  return inverseFeatures;
}
 
Example 25
Project: guava-libraries   File: SortedMultisetTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
private TestSuite createReserializedSuite(
    SortedMultisetTestSuiteBuilder<E> parentBuilder) {
  final TestMultisetGenerator<E> delegate =
      (TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();

  Set<Feature<?>> features = new HashSet<Feature<?>>();
  features.addAll(parentBuilder.getFeatures());
  features.remove(CollectionFeature.SERIALIZABLE);
  features.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS);

  return SortedMultisetTestSuiteBuilder
      .using(new ForwardingTestMultisetGenerator<E>(delegate) {
        @Override
        public SortedMultiset<E> create(Object... entries) {
          return SerializableTester.reserialize(((SortedMultiset<E>) super.create(entries)));
        }
      })
      .named(parentBuilder.getName() + " reserialized")
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
 
Example 26
Project: guava-libraries   File: SortedSetMultimapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
@Override
TestSuite computeMultimapAsMapGetTestSuite(
    FeatureSpecificTestSuiteBuilder<?, ? extends
    OneSizeTestContainerGenerator<SetMultimap<K, V>, Entry<K, V>>> parentBuilder) {
  Set<Feature<?>> features = computeMultimapAsMapGetFeatures(parentBuilder.getFeatures());
  if (Collections.disjoint(features, EnumSet.allOf(CollectionSize.class))) {
    return new TestSuite();
  } else {
    return SortedSetTestSuiteBuilder.using(
        new SetMultimapTestSuiteBuilder.MultimapAsMapGetGenerator<K, V>(
            parentBuilder.getSubjectGenerator()))
        .withFeatures(features)
        .named(parentBuilder.getName() + ".asMap[].get[key]")
        .suppressing(parentBuilder.getSuppressedTests())
        .createTestSuite();
  }
}
 
Example 27
Project: guava-libraries   File: MultimapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
Set<Feature<?>> computeMultimapGetFeatures(
    Set<Feature<?>> multimapFeatures) {
  Set<Feature<?>> derivedFeatures = Helpers.copyToSet(multimapFeatures);
  for (Map.Entry<Feature<?>, Feature<?>> entry : GET_FEATURE_MAP.entries()) {
    if (derivedFeatures.contains(entry.getKey())) {
      derivedFeatures.add(entry.getValue());
    }
  }
  if (derivedFeatures.remove(MultimapFeature.VALUE_COLLECTIONS_SUPPORT_ITERATOR_REMOVE)) {
    derivedFeatures.add(CollectionFeature.SUPPORTS_ITERATOR_REMOVE);
  }
  if (!derivedFeatures.contains(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
    derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
  }
  derivedFeatures.removeAll(GET_FEATURE_MAP.keySet());
  return derivedFeatures;
}
 
Example 28
Project: guava-libraries   File: SortedMapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a suite whose map has some elements filtered out of view.
 *
 * <p>Because the map may be ascending or descending, this test must derive
 * the relative order of these extreme values rather than relying on their
 * regular sort ordering.
 */
final TestSuite createSubmapSuite(final FeatureSpecificTestSuiteBuilder<?,
        ? extends OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>>>
        parentBuilder, final Bound from, final Bound to) {
  final TestSortedMapGenerator<K, V> delegate
      = (TestSortedMapGenerator<K, V>) parentBuilder.getSubjectGenerator().getInnerGenerator();

  List<Feature<?>> features = new ArrayList<Feature<?>>();
  features.add(NoRecurse.SUBMAP);
  features.addAll(parentBuilder.getFeatures());

  return newBuilderUsing(delegate, to, from)
      .named(parentBuilder.getName() + " subMap " + from + "-" + to)
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
 
Example 29
Project: guava   File: SortedSetTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a suite whose set has some elements filtered out of view.
 *
 * <p>Because the set may be ascending or descending, this test must derive the relative order of
 * these extreme values rather than relying on their regular sort ordering.
 */
final TestSuite createSubsetSuite(
    final FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<Collection<E>, E>>
        parentBuilder,
    final Bound from,
    final Bound to) {
  final TestSortedSetGenerator<E> delegate =
      (TestSortedSetGenerator<E>) parentBuilder.getSubjectGenerator().getInnerGenerator();

  List<Feature<?>> features = new ArrayList<>();
  features.addAll(parentBuilder.getFeatures());
  features.remove(CollectionFeature.ALLOWS_NULL_VALUES);
  features.add(CollectionFeature.SUBSET_VIEW);

  return newBuilderUsing(delegate, to, from)
      .named(parentBuilder.getName() + " subSet " + from + "-" + to)
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
 
Example 30
Project: guava   File: ListMultimapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
@Override
TestSuite computeMultimapAsMapGetTestSuite(
    FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<ListMultimap<K, V>, Entry<K, V>>>
        parentBuilder) {
  Set<Feature<?>> features = computeMultimapAsMapGetFeatures(parentBuilder.getFeatures());
  if (Collections.disjoint(features, EnumSet.allOf(CollectionSize.class))) {
    return new TestSuite();
  } else {
    return ListTestSuiteBuilder.using(
            new MultimapAsMapGetGenerator<K, V>(parentBuilder.getSubjectGenerator()))
        .withFeatures(features)
        .named(parentBuilder.getName() + ".asMap[].get[key]")
        .suppressing(parentBuilder.getSuppressedTests())
        .createTestSuite();
  }
}
 
Example 31
Project: guava   File: SetMultimapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
@Override
TestSuite computeMultimapAsMapGetTestSuite(
    FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<SetMultimap<K, V>, Entry<K, V>>>
        parentBuilder) {
  Set<Feature<?>> features = computeMultimapAsMapGetFeatures(parentBuilder.getFeatures());
  if (Collections.disjoint(features, EnumSet.allOf(CollectionSize.class))) {
    return new TestSuite();
  } else {
    return SetTestSuiteBuilder.using(
            new MultimapAsMapGetGenerator<K, V>(parentBuilder.getSubjectGenerator()))
        .withFeatures(features)
        .named(parentBuilder.getName() + ".asMap[].get[key]")
        .suppressing(parentBuilder.getSuppressedTests())
        .createTestSuite();
  }
}
 
Example 32
Project: guava   File: BiMapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
private static Set<Feature<?>> computeInverseFeatures(Set<Feature<?>> mapFeatures) {
  Set<Feature<?>> inverseFeatures = new HashSet<>(mapFeatures);

  boolean nullKeys = inverseFeatures.remove(MapFeature.ALLOWS_NULL_KEYS);
  boolean nullValues = inverseFeatures.remove(MapFeature.ALLOWS_NULL_VALUES);

  if (nullKeys) {
    inverseFeatures.add(MapFeature.ALLOWS_NULL_VALUES);
  }
  if (nullValues) {
    inverseFeatures.add(MapFeature.ALLOWS_NULL_KEYS);
  }

  inverseFeatures.add(NoRecurse.INVERSE);
  inverseFeatures.remove(CollectionFeature.KNOWN_ORDER);
  inverseFeatures.add(MapFeature.REJECTS_DUPLICATES_AT_CREATION);

  return inverseFeatures;
}
 
Example 33
Project: guava   File: SortedMultisetTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
private TestSuite createReserializedSuite(SortedMultisetTestSuiteBuilder<E> parentBuilder) {
  final TestMultisetGenerator<E> delegate =
      (TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();

  Set<Feature<?>> features = new HashSet<>();
  features.addAll(parentBuilder.getFeatures());
  features.remove(SERIALIZABLE);
  features.remove(SERIALIZABLE_INCLUDING_VIEWS);

  return SortedMultisetTestSuiteBuilder.using(
          new ForwardingTestMultisetGenerator<E>(delegate) {
            @Override
            public SortedMultiset<E> create(Object... entries) {
              return SerializableTester.reserialize(((SortedMultiset<E>) super.create(entries)));
            }
          })
      .named(parentBuilder.getName() + " reserialized")
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
 
Example 34
Project: guava   File: SortedSetMultimapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
@Override
TestSuite computeMultimapAsMapGetTestSuite(
    FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<SetMultimap<K, V>, Entry<K, V>>>
        parentBuilder) {
  Set<Feature<?>> features = computeMultimapAsMapGetFeatures(parentBuilder.getFeatures());
  if (Collections.disjoint(features, EnumSet.allOf(CollectionSize.class))) {
    return new TestSuite();
  } else {
    return SortedSetTestSuiteBuilder.using(
            new SetMultimapTestSuiteBuilder.MultimapAsMapGetGenerator<K, V>(
                parentBuilder.getSubjectGenerator()))
        .withFeatures(features)
        .named(parentBuilder.getName() + ".asMap[].get[key]")
        .suppressing(parentBuilder.getSuppressedTests())
        .createTestSuite();
  }
}
 
Example 35
Project: guava   File: MultimapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
Set<Feature<?>> computeMultimapGetFeatures(Set<Feature<?>> multimapFeatures) {
  Set<Feature<?>> derivedFeatures = Helpers.copyToSet(multimapFeatures);
  for (Entry<Feature<?>, Feature<?>> entry : GET_FEATURE_MAP.entries()) {
    if (derivedFeatures.contains(entry.getKey())) {
      derivedFeatures.add(entry.getValue());
    }
  }
  if (derivedFeatures.remove(MultimapFeature.VALUE_COLLECTIONS_SUPPORT_ITERATOR_REMOVE)) {
    derivedFeatures.add(CollectionFeature.SUPPORTS_ITERATOR_REMOVE);
  }
  if (!derivedFeatures.contains(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
    derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
  }
  derivedFeatures.removeAll(GET_FEATURE_MAP.keySet());
  return derivedFeatures;
}
 
Example 36
Project: guava   File: NavigableMapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
/** Create a suite whose maps are descending views of other maps. */
private TestSuite createDescendingSuite(
    final FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>>>
        parentBuilder) {
  final TestSortedMapGenerator<K, V> delegate =
      (TestSortedMapGenerator<K, V>) parentBuilder.getSubjectGenerator().getInnerGenerator();

  List<Feature<?>> features = new ArrayList<>();
  features.add(NoRecurse.DESCENDING);
  features.addAll(parentBuilder.getFeatures());

  return subSuiteUsing(new DescendingTestMapGenerator<K, V>(delegate))
      .named(parentBuilder.getName() + " descending")
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
 
Example 37
Project: guava   File: SortedMapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a suite whose map has some elements filtered out of view.
 *
 * <p>Because the map may be ascending or descending, this test must derive the relative order of
 * these extreme values rather than relying on their regular sort ordering.
 */
final TestSuite createSubmapSuite(
    final FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>>>
        parentBuilder,
    final Bound from,
    final Bound to) {
  final TestSortedMapGenerator<K, V> delegate =
      (TestSortedMapGenerator<K, V>) parentBuilder.getSubjectGenerator().getInnerGenerator();

  List<Feature<?>> features = new ArrayList<>();
  features.add(NoRecurse.SUBMAP);
  features.addAll(parentBuilder.getFeatures());

  return newBuilderUsing(delegate, to, from)
      .named(parentBuilder.getName() + " subMap " + from + "-" + to)
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
 
Example 38
Project: guava   File: SortedSetTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a suite whose set has some elements filtered out of view.
 *
 * <p>Because the set may be ascending or descending, this test must derive the relative order of
 * these extreme values rather than relying on their regular sort ordering.
 */
final TestSuite createSubsetSuite(
    final FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<Collection<E>, E>>
        parentBuilder,
    final Bound from,
    final Bound to) {
  final TestSortedSetGenerator<E> delegate =
      (TestSortedSetGenerator<E>) parentBuilder.getSubjectGenerator().getInnerGenerator();

  List<Feature<?>> features = new ArrayList<>();
  features.addAll(parentBuilder.getFeatures());
  features.remove(CollectionFeature.ALLOWS_NULL_VALUES);
  features.add(CollectionFeature.SUBSET_VIEW);

  return newBuilderUsing(delegate, to, from)
      .named(parentBuilder.getName() + " subSet " + from + "-" + to)
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
 
Example 39
Project: guava   File: ListMultimapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
@Override
TestSuite computeMultimapAsMapGetTestSuite(
    FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<ListMultimap<K, V>, Entry<K, V>>>
        parentBuilder) {
  Set<Feature<?>> features = computeMultimapAsMapGetFeatures(parentBuilder.getFeatures());
  if (Collections.disjoint(features, EnumSet.allOf(CollectionSize.class))) {
    return new TestSuite();
  } else {
    return ListTestSuiteBuilder.using(
            new MultimapAsMapGetGenerator<K, V>(parentBuilder.getSubjectGenerator()))
        .withFeatures(features)
        .named(parentBuilder.getName() + ".asMap[].get[key]")
        .suppressing(parentBuilder.getSuppressedTests())
        .createTestSuite();
  }
}
 
Example 40
Project: guava   File: SetMultimapTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
@Override
TestSuite computeMultimapAsMapGetTestSuite(
    FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<SetMultimap<K, V>, Entry<K, V>>>
        parentBuilder) {
  Set<Feature<?>> features = computeMultimapAsMapGetFeatures(parentBuilder.getFeatures());
  if (Collections.disjoint(features, EnumSet.allOf(CollectionSize.class))) {
    return new TestSuite();
  } else {
    return SetTestSuiteBuilder.using(
            new MultimapAsMapGetGenerator<K, V>(parentBuilder.getSubjectGenerator()))
        .withFeatures(features)
        .named(parentBuilder.getName() + ".asMap[].get[key]")
        .suppressing(parentBuilder.getSuppressedTests())
        .createTestSuite();
  }
}