Java Code Examples for com.google.common.collect.testing.SampleElements

The following are top voted examples for showing how to use com.google.common.collect.testing.SampleElements. 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: TestStringBiMapGenerator.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Map.Entry<String, String>> samples() {
  return new SampleElements<Map.Entry<String, String>>(
      Helpers.mapEntry("one", "January"),
      Helpers.mapEntry("two", "February"),
      Helpers.mapEntry("three", "March"),
      Helpers.mapEntry("four", "April"),
      Helpers.mapEntry("five", "May"));
}
 
Example 2
Project: guava-mock   File: TestStringListMultimapGenerator.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Map.Entry<String, String>> samples() {
  return new SampleElements<Map.Entry<String, String>>(
      Helpers.mapEntry("one", "January"),
      Helpers.mapEntry("two", "February"),
      Helpers.mapEntry("three", "March"),
      Helpers.mapEntry("four", "April"),
      Helpers.mapEntry("five", "May"));
}
 
Example 3
Project: guava-mock   File: SortedMapGenerators.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Entry<String, Integer>> samples() {
  return new SampleElements<Entry<String, Integer>>(
      mapEntry("foo", 5),
      mapEntry("bar", 3),
      mapEntry("baz", 17),
      mapEntry("quux", 1),
      mapEntry("toaster", -2));
}
 
Example 4
Project: guava-mock   File: MapGenerators.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Entry<String, Integer>> samples() {
  return new SampleElements<>(
      mapEntry("foo", 5),
      mapEntry("bar", 3),
      mapEntry("baz", 17),
      mapEntry("quux", 1),
      mapEntry("toaster", -2));
}
 
Example 5
Project: guava-mock   File: MapGenerators.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Entry<String, Collection<Integer>>> samples() {
  return new SampleElements<>(
      mapEntry("one", ImmutableSet.of(10000)),
      mapEntry("two", ImmutableSet.of(-2000)),
      mapEntry("three", ImmutableSet.of(300)),
      mapEntry("four", ImmutableSet.of(-40)),
      mapEntry("five", ImmutableSet.of(5)));
}
 
Example 6
Project: guava-mock   File: DerivedGoogleCollectionGenerators.java   Source Code and License 5 votes vote down vote up
public BiMapValueSetGenerator(
    OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> mapGenerator) {
  this.mapGenerator = mapGenerator;
  final SampleElements<Map.Entry<K, V>> mapSamples = this.mapGenerator.samples();
  this.samples =
      new SampleElements<V>(
          mapSamples.e0().getValue(),
          mapSamples.e1().getValue(),
          mapSamples.e2().getValue(),
          mapSamples.e3().getValue(),
          mapSamples.e4().getValue());
}
 
Example 7
Project: guava-mock   File: TestStringSetMultimapGenerator.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Map.Entry<String, String>> samples() {
  return new SampleElements<Map.Entry<String, String>>(
      Helpers.mapEntry("one", "January"),
      Helpers.mapEntry("two", "February"),
      Helpers.mapEntry("three", "March"),
      Helpers.mapEntry("four", "April"),
      Helpers.mapEntry("five", "May"));
}
 
Example 8
Project: guava-mock   File: MultimapTestSuiteBuilder.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Entry<K, Collection<V>>> samples() {
  SampleElements<K> sampleKeys =
      ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator()).sampleKeys();
  SampleElements<V> sampleValues =
      ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator()).sampleValues();
  return new SampleElements<Entry<K, Collection<V>>>(
      mapEntry(sampleKeys.e0(), createCollection(sampleValues.e0())),
      mapEntry(sampleKeys.e1(), createCollection(sampleValues.e1())),
      mapEntry(sampleKeys.e2(), createCollection(sampleValues.e2())),
      mapEntry(sampleKeys.e3(), createCollection(sampleValues.e3())),
      mapEntry(sampleKeys.e4(), createCollection(sampleValues.e4())));
}
 
Example 9
Project: googles-monorepo-demo   File: ImmutableMultimapTest.java   Source Code and License 5 votes vote down vote up
public void testUnhashableMixedValues() {
  SampleElements<UnhashableObject> unhashables = new Unhashables();
  Multimap<Integer, Object> multimap = ImmutableMultimap.<Integer, Object>of(
      0, unhashables.e0(), 2, "hey you", 0, unhashables.e1());
  assertEquals(2, multimap.get(0).size());
  assertTrue(multimap.get(0).contains(unhashables.e0()));
  assertTrue(multimap.get(0).contains(unhashables.e1()));
  assertTrue(multimap.get(2).contains("hey you"));
}
 
Example 10
Project: guava-mock   File: TableCollectionTest.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Cell<String, Integer, Character>> samples() {
  return new SampleElements<Cell<String, Integer, Character>>(
      Tables.immutableCell("bar", 1, 'a'),
      Tables.immutableCell("bar", 2, 'b'),
      Tables.immutableCell("foo", 3, 'c'),
      Tables.immutableCell("bar", 1, 'b'),
      Tables.immutableCell("cat", 2, 'b'));
}
 
Example 11
Project: guava-mock   File: MultimapsCollectionTest.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Entry<String, String>> samples() {
  return new SampleElements<Entry<String, String>>(
      mapEntry("one", "january"),
      mapEntry("two", "february"),
      mapEntry("three", "march"),
      mapEntry("four", "april"),
      mapEntry("five", "may"));
}
 
Example 12
Project: guava-mock   File: MultimapsCollectionTest.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Entry<String, Integer>> samples() {
  return new SampleElements<Entry<String, Integer>>(
      mapEntry("one", 114),
      mapEntry("two", 37),
      mapEntry("three", 42),
      mapEntry("four", 19),
      mapEntry("five", 82));
}
 
Example 13
Project: guava-mock   File: ImmutableClassToInstanceMapTest.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Entry<Class, Impl>> samples() {
  return new SampleElements<Entry<Class, Impl>>(
      immutableEntry((Class) One.class, new Impl(1)),
      immutableEntry((Class) Two.class, new Impl(2)),
      immutableEntry((Class) Three.class, new Impl(3)),
      immutableEntry((Class) Four.class, new Impl(4)),
      immutableEntry((Class) Five.class, new Impl(5)));
}
 
Example 14
Project: guava-mock   File: EnumHashBiMapTest.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Entry<Country, String>> samples() {
  return new SampleElements<Entry<Country, String>>(
      Maps.immutableEntry(Country.CANADA, "DOLLAR"),
      Maps.immutableEntry(Country.CHILE, "PESO"),
      Maps.immutableEntry(Country.UK, "POUND"),
      Maps.immutableEntry(Country.JAPAN, "YEN"),
      Maps.immutableEntry(Country.SWITZERLAND, "FRANC"));
}
 
Example 15
Project: guava-mock   File: EnumBiMapTest.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Entry<Country, Currency>> samples() {
  return new SampleElements<Entry<Country, Currency>>(
      Helpers.mapEntry(Country.CANADA, Currency.DOLLAR),
      Helpers.mapEntry(Country.CHILE, Currency.PESO),
      Helpers.mapEntry(Country.UK, Currency.POUND),
      Helpers.mapEntry(Country.JAPAN, Currency.YEN),
      Helpers.mapEntry(Country.SWITZERLAND, Currency.FRANC));
}
 
Example 16
Project: guava-mock   File: ImmutableRangeSetTest.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<BigInteger> samples() {
  return new SampleElements<BigInteger>(
      BigInteger.valueOf(1),
      BigInteger.valueOf(4),
      BigInteger.valueOf(3),
      BigInteger.valueOf(2),
      BigInteger.valueOf(5));
}
 
Example 17
Project: guava-mock   File: ImmutableMultimapTest.java   Source Code and License 5 votes vote down vote up
public void testUnhashableSingletonValue() {
  SampleElements<UnhashableObject> unhashables = new Unhashables();
  Multimap<Integer, UnhashableObject> multimap = ImmutableMultimap.of(
      0, unhashables.e0());
  assertEquals(1, multimap.get(0).size());
  assertTrue(multimap.get(0).contains(unhashables.e0()));
}
 
Example 18
Project: guava-mock   File: ImmutableMultimapTest.java   Source Code and License 5 votes vote down vote up
public void testUnhashableMixedValues() {
  SampleElements<UnhashableObject> unhashables = new Unhashables();
  Multimap<Integer, Object> multimap = ImmutableMultimap.<Integer, Object>of(
      0, unhashables.e0(), 2, "hey you", 0, unhashables.e1());
  assertEquals(2, multimap.get(0).size());
  assertTrue(multimap.get(0).contains(unhashables.e0()));
  assertTrue(multimap.get(0).contains(unhashables.e1()));
  assertTrue(multimap.get(2).contains("hey you"));
}
 
Example 19
Project: guava-mock   File: ImmutableTypeToInstanceMapTest.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Entry<TypeToken, Object>> samples() {
  return new SampleElements<Entry<TypeToken, Object>>(
      entry(TypeToken.of(Integer.class), 0),
      entry(TypeToken.of(Number.class), 1),
      entry(new TypeToken<ImmutableList<Integer>>() {}, ImmutableList.of(2)),
      entry(new TypeToken<int[]>() {}, new int[] {3}),
      entry(new TypeToken<Iterable<?>>() {}, ImmutableList.of("4")));
}
 
Example 20
Project: googles-monorepo-demo   File: ImmutableMultimapTest.java   Source Code and License 5 votes vote down vote up
public void testUnhashableSingletonValue() {
  SampleElements<UnhashableObject> unhashables = new Unhashables();
  Multimap<Integer, UnhashableObject> multimap = ImmutableMultimap.of(
      0, unhashables.e0());
  assertEquals(1, multimap.get(0).size());
  assertTrue(multimap.get(0).contains(unhashables.e0()));
}
 
Example 21
Project: googles-monorepo-demo   File: TestStringListMultimapGenerator.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Map.Entry<String, String>> samples() {
  return new SampleElements<Map.Entry<String, String>>(
      Helpers.mapEntry("one", "January"),
      Helpers.mapEntry("two", "February"),
      Helpers.mapEntry("three", "March"),
      Helpers.mapEntry("four", "April"),
      Helpers.mapEntry("five", "May"));
}
 
Example 22
Project: googles-monorepo-demo   File: SortedMapGenerators.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Entry<String, Integer>> samples() {
  return new SampleElements<Entry<String, Integer>>(
      mapEntry("foo", 5),
      mapEntry("bar", 3),
      mapEntry("baz", 17),
      mapEntry("quux", 1),
      mapEntry("toaster", -2));
}
 
Example 23
Project: googles-monorepo-demo   File: MapGenerators.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Entry<String, Integer>> samples() {
  return new SampleElements<Entry<String, Integer>>(
      mapEntry("foo", 5),
      mapEntry("bar", 3),
      mapEntry("baz", 17),
      mapEntry("quux", 1),
      mapEntry("toaster", -2));
}
 
Example 24
Project: googles-monorepo-demo   File: DerivedGoogleCollectionGenerators.java   Source Code and License 5 votes vote down vote up
public BiMapValueSetGenerator(
    OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> mapGenerator) {
  this.mapGenerator = mapGenerator;
  final SampleElements<Map.Entry<K, V>> mapSamples = this.mapGenerator.samples();
  this.samples =
      new SampleElements<V>(
          mapSamples.e0().getValue(),
          mapSamples.e1().getValue(),
          mapSamples.e2().getValue(),
          mapSamples.e3().getValue(),
          mapSamples.e4().getValue());
}
 
Example 25
Project: googles-monorepo-demo   File: ImmutableRangeSetTest.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<BigInteger> samples() {
  return new SampleElements<BigInteger>(
      BigInteger.valueOf(1),
      BigInteger.valueOf(4),
      BigInteger.valueOf(3),
      BigInteger.valueOf(2),
      BigInteger.valueOf(5));
}
 
Example 26
Project: googles-monorepo-demo   File: TestStringSetMultimapGenerator.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Map.Entry<String, String>> samples() {
  return new SampleElements<Map.Entry<String, String>>(
      Helpers.mapEntry("one", "January"),
      Helpers.mapEntry("two", "February"),
      Helpers.mapEntry("three", "March"),
      Helpers.mapEntry("four", "April"),
      Helpers.mapEntry("five", "May"));
}
 
Example 27
Project: googles-monorepo-demo   File: MultimapTestSuiteBuilder.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Entry<K, Collection<V>>> samples() {
  SampleElements<K> sampleKeys =
      ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator()).sampleKeys();
  SampleElements<V> sampleValues =
      ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator()).sampleValues();
  return new SampleElements<Entry<K, Collection<V>>>(
      mapEntry(sampleKeys.e0(), createCollection(sampleValues.e0())),
      mapEntry(sampleKeys.e1(), createCollection(sampleValues.e1())),
      mapEntry(sampleKeys.e2(), createCollection(sampleValues.e2())),
      mapEntry(sampleKeys.e3(), createCollection(sampleValues.e3())),
      mapEntry(sampleKeys.e4(), createCollection(sampleValues.e4())));
}
 
Example 28
Project: googles-monorepo-demo   File: ImmutableTypeToInstanceMapTest.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Entry<TypeToken, Object>> samples() {
  return new SampleElements<Entry<TypeToken, Object>>(
      entry(TypeToken.of(Integer.class), 0),
      entry(TypeToken.of(Number.class), 1),
      entry(new TypeToken<ImmutableList<Integer>>() {}, ImmutableList.of(2)),
      entry(new TypeToken<int[]>() {}, new int[] {3}),
      entry(new TypeToken<Iterable<?>>() {}, ImmutableList.of("4")));
}
 
Example 29
Project: googles-monorepo-demo   File: TableCollectionTest.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Cell<String, Integer, Character>> samples() {
  return new SampleElements<Cell<String, Integer, Character>>(
      Tables.immutableCell("bar", 1, 'a'),
      Tables.immutableCell("bar", 2, 'b'),
      Tables.immutableCell("foo", 3, 'c'),
      Tables.immutableCell("bar", 1, 'b'),
      Tables.immutableCell("cat", 2, 'b'));
}
 
Example 30
Project: googles-monorepo-demo   File: MultimapsCollectionTest.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Entry<String, String>> samples() {
  return new SampleElements<Entry<String, String>>(
      mapEntry("one", "january"),
      mapEntry("two", "february"),
      mapEntry("three", "march"),
      mapEntry("four", "april"),
      mapEntry("five", "may"));
}
 
Example 31
Project: googles-monorepo-demo   File: MultimapsCollectionTest.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Entry<String, Integer>> samples() {
  return new SampleElements<Entry<String, Integer>>(
      mapEntry("one", 114),
      mapEntry("two", 37),
      mapEntry("three", 42),
      mapEntry("four", 19),
      mapEntry("five", 82));
}
 
Example 32
Project: googles-monorepo-demo   File: ImmutableClassToInstanceMapTest.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Entry<Class, Impl>> samples() {
  return new SampleElements<Entry<Class, Impl>>(
      immutableEntry((Class) One.class, new Impl(1)),
      immutableEntry((Class) Two.class, new Impl(2)),
      immutableEntry((Class) Three.class, new Impl(3)),
      immutableEntry((Class) Four.class, new Impl(4)),
      immutableEntry((Class) Five.class, new Impl(5)));
}
 
Example 33
Project: googles-monorepo-demo   File: EnumBiMapTest.java   Source Code and License 5 votes vote down vote up
@Override
public SampleElements<Entry<Country, Currency>> samples() {
  return new SampleElements<Entry<Country, Currency>>(
      Helpers.mapEntry(Country.CANADA, Currency.DOLLAR),
      Helpers.mapEntry(Country.CHILE, Currency.PESO),
      Helpers.mapEntry(Country.UK, Currency.POUND),
      Helpers.mapEntry(Country.JAPAN, Currency.YEN),
      Helpers.mapEntry(Country.SWITZERLAND, Currency.FRANC));
}
 
Example 34
Project: guava-mock   File: TestEnumMultisetGenerator.java   Source Code and License 4 votes vote down vote up
@Override
public SampleElements<AnEnum> samples() {
  return new Enums();
}
 
Example 35
Project: guava-mock   File: TestStringListMultimapGenerator.java   Source Code and License 4 votes vote down vote up
@Override
public SampleElements<String> sampleKeys() {
  return new SampleElements<String>("one", "two", "three", "four", "five");
}
 
Example 36
Project: guava-mock   File: TestStringListMultimapGenerator.java   Source Code and License 4 votes vote down vote up
@Override
public SampleElements<String> sampleValues() {
  return new SampleElements<String>("January", "February", "March", "April", "May");
}
 
Example 37
Project: guava-mock   File: MultisetTestSuiteBuilder.java   Source Code and License 4 votes vote down vote up
@Override
public SampleElements<E> samples() {
  return gen.samples();
}
 
Example 38
Project: guava-mock   File: MultisetTestSuiteBuilder.java   Source Code and License 4 votes vote down vote up
@Override
public SampleElements<E> samples() {
  return gen.samples();
}
 
Example 39
Project: guava-mock   File: TestStringMultisetGenerator.java   Source Code and License 4 votes vote down vote up
@Override
public SampleElements<String> samples() {
  return new Strings();
}
 
Example 40
Project: guava-mock   File: SortedMultisetTestSuiteBuilder.java   Source Code and License 4 votes vote down vote up
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")
              // we dangerously assume E is a string
              List<E> extremeValues = (List) getExtremeValues();
              @SuppressWarnings("unchecked")
              // map generators must past entry objects
              List<E> 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());

              // call the smallest subMap overload that filters out the extreme
              // 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();
}