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

The following are top voted examples for showing how to use com.google.common.collect.testing.Helpers. 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: googles-monorepo-demo   File: MultimapTestSuiteBuilder.java   View source code 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 2
Project: guava-mock   File: MultimapRemoveEntryTester.java   View source code 6 votes vote down vote up
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemovePropagatesToAsMap() {
  List<Entry<K, V>> entries = Helpers.copyToList(multimap().entries());
  for (Entry<K, V> entry : entries) {
    resetContainer();

    K key = entry.getKey();
    V value = entry.getValue();
    Collection<V> collection = multimap().asMap().get(key);
    assertNotNull(collection);
    Collection<V> expectedCollection = Helpers.copyToList(collection);

    multimap().remove(key, value);
    expectedCollection.remove(value);

    assertEqualIgnoringOrder(expectedCollection, collection);
    assertEquals(!expectedCollection.isEmpty(), multimap().containsKey(key));
  }
}
 
Example 3
Project: googles-monorepo-demo   File: OrderingTest.java   View source code 6 votes vote down vote up
public void testArbitrary_withCollisions() {
  List<Integer> list = Lists.newArrayList();
  for (int i = 0; i < 50; i++) {
    list.add(i);
  }

  Ordering<Object> arbitrary = new ArbitraryOrdering() {
    @Override int identityHashCode(Object object) {
      return ((Integer) object) % 5; // fake tons of collisions!
    }
  };

  // Don't let the elements be in such a predictable order
  list = shuffledCopy(list, new Random(1));

  Collections.sort(list, arbitrary);

  // Now we don't care what order it's put the list in, only that
  // comparing any pair of elements gives the answer we expect.
  Helpers.testComparator(arbitrary, list);
}
 
Example 4
Project: googles-monorepo-demo   File: MultimapPutTester.java   View source code 6 votes vote down vote up
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testPutPresentKeyPropagatesToAsMapGet() {
  List<K> keys = Helpers.copyToList(multimap().keySet());
  for (K key : keys) {
    resetContainer();

    int size = getNumElements();

    Collection<V> collection = multimap().asMap().get(key);
    assertNotNull(collection);
    Collection<V> expectedCollection = Helpers.copyToList(collection);

    multimap().put(key, v3());
    expectedCollection.add(v3());
    assertEqualIgnoringOrder(expectedCollection, collection);
    assertEquals(size + 1, multimap().size());
  }
}
 
Example 5
Project: googles-monorepo-demo   File: SetMultimapEqualsTester.java   View source code 6 votes vote down vote up
@CollectionSize.Require(SEVERAL)
public void testOrderingDoesntAffectEqualsComparisons() {
  SetMultimap<K, V> multimap1 =
      getSubjectGenerator()
          .create(
              Helpers.mapEntry(k0(), v0()),
              Helpers.mapEntry(k0(), v1()),
              Helpers.mapEntry(k0(), v4()));
  SetMultimap<K, V> multimap2 =
      getSubjectGenerator()
          .create(
              Helpers.mapEntry(k0(), v1()),
              Helpers.mapEntry(k0(), v0()),
              Helpers.mapEntry(k0(), v4()));
  new EqualsTester().addEqualityGroup(multimap1, multimap2).testEquals();
}
 
Example 6
Project: guava-mock   File: OrderingTest.java   View source code 6 votes vote down vote up
public void testArbitrary_withCollisions() {
  List<Integer> list = Lists.newArrayList();
  for (int i = 0; i < 50; i++) {
    list.add(i);
  }

  Ordering<Object> arbitrary = new ArbitraryOrdering() {
    @Override int identityHashCode(Object object) {
      return ((Integer) object) % 5; // fake tons of collisions!
    }
  };

  // Don't let the elements be in such a predictable order
  list = shuffledCopy(list, new Random(1));

  Collections.sort(list, arbitrary);

  // Now we don't care what order it's put the list in, only that
  // comparing any pair of elements gives the answer we expect.
  Helpers.testComparator(arbitrary, list);
}
 
Example 7
Project: googles-monorepo-demo   File: ComparatorsTest.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked") // dang varargs
public void testLexicographical() {
  Comparator<String> comparator = Ordering.natural();
  Comparator<Iterable<String>> lexy = Comparators.lexicographical(comparator);

  ImmutableList<String> empty = ImmutableList.of();
  ImmutableList<String> a = ImmutableList.of("a");
  ImmutableList<String> aa = ImmutableList.of("a", "a");
  ImmutableList<String> ab = ImmutableList.of("a", "b");
  ImmutableList<String> b = ImmutableList.of("b");

  Helpers.testComparator(lexy, empty, a, aa, ab, b);

  new EqualsTester()
      .addEqualityGroup(lexy, Comparators.lexicographical(comparator))
      .addEqualityGroup(Comparators.lexicographical(String.CASE_INSENSITIVE_ORDER))
      .addEqualityGroup(Ordering.natural())
      .testEquals();
}
 
Example 8
Project: guava-mock   File: AbstractImmutableSetTest.java   View source code 6 votes vote down vote up
/**
 * Verify thread safety by using a collection whose size() may be inconsistent
 * with the actual number of elements.  Tests using this method might fail in
 * GWT because the GWT emulations might count on size() during copy.  It is
 * safe to do so in GWT because javascript is single-threaded.
 */
// TODO(benyu): turn this into a test once all copyOf(Collection) are
// thread-safe
@GwtIncompatible // GWT is single threaded
void verifyThreadSafe() {
  List<String> sample = Lists.newArrayList("a", "b", "c");
  for (int delta : new int[] {-1, 0, 1}) {
    for (int i = 0; i < sample.size(); i++) {
      Collection<String> misleading = Helpers.misleadingSizeCollection(delta);
      List<String> expected = sample.subList(0, i);
      misleading.addAll(expected);
      assertEquals("delta: " + delta + " sample size: " + i,
          Sets.newHashSet(expected), copyOf(misleading));
    }
  }
}
 
Example 9
Project: googles-monorepo-demo   File: NavigableSetNavigationTester.java   View source code 6 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();
  navigableSet = (NavigableSet<E>) getSet();
  values =
      Helpers.copyToList(
          getSubjectGenerator()
              .getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements()));
  Collections.sort(values, navigableSet.comparator());

  // some tests assume SEVERAL == 3
  if (values.size() >= 1) {
    a = values.get(0);
    if (values.size() >= 3) {
      b = values.get(1);
      c = values.get(2);
    }
  }
}
 
Example 10
Project: googles-monorepo-demo   File: MultimapEntriesTester.java   View source code 5 votes vote down vote up
@CollectionSize.Require(ONE)
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
public void testIteratorRemovePropagatesToMultimap() {
  Iterator<Entry<K, V>> iterator = multimap().entries().iterator();
  assertEquals(Helpers.mapEntry(k0(), v0()), iterator.next());
  iterator.remove();
  assertTrue(multimap().isEmpty());
}
 
Example 11
Project: googles-monorepo-demo   File: DoublesTest.java   View source code 5 votes vote down vote up
public void testLexicographicalComparator() {
  List<double[]> ordered = Arrays.asList(
      new double[] {},
      new double[] {LEAST},
      new double[] {LEAST, LEAST},
      new double[] {LEAST, (double) 1},
      new double[] {(double) 1},
      new double[] {(double) 1, LEAST},
      new double[] {GREATEST, Double.MAX_VALUE},
      new double[] {GREATEST, GREATEST},
      new double[] {GREATEST, GREATEST, GREATEST});

  Comparator<double[]> comparator = Doubles.lexicographicalComparator();
  Helpers.testComparator(comparator, ordered);
}
 
Example 12
Project: guava-mock   File: MultisetForEachEntryTester.java   View source code 5 votes vote down vote up
public void testForEachEntry() {
  List<Entry<E>> expected = new ArrayList<>(getMultiset().entrySet());
  List<Entry<E>> actual = new ArrayList<>();
  getMultiset()
      .forEachEntry((element, count) -> actual.add(Multisets.immutableEntry(element, count)));
  Helpers.assertEqualIgnoringOrder(expected, actual);
}
 
Example 13
Project: guava-mock   File: OrderingTest.java   View source code 5 votes vote down vote up
public void testArbitrary_withoutCollisions() {
  List<Object> list = Lists.newArrayList();
  for (int i = 0; i < 50; i++) {
    list.add(new Object());
  }

  Ordering<Object> arbitrary = Ordering.arbitrary();
  Collections.sort(list, arbitrary);

  // Now we don't care what order it's put the list in, only that
  // comparing any pair of elements gives the answer we expect.
  Helpers.testComparator(arbitrary, list);

  assertEquals("Ordering.arbitrary()", arbitrary.toString());
}
 
Example 14
Project: googles-monorepo-demo   File: MultimapPutTester.java   View source code 5 votes vote down vote up
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testPutPresentKeyPropagatesToAsMapEntrySet() {
  List<K> keys = Helpers.copyToList(multimap().keySet());
  for (K key : keys) {
    resetContainer();

    int size = getNumElements();

    Iterator<Entry<K, Collection<V>>> asMapItr = multimap().asMap().entrySet().iterator();
    Collection<V> collection = null;
    while (asMapItr.hasNext()) {
      Entry<K, Collection<V>> asMapEntry = asMapItr.next();
      if (key.equals(asMapEntry.getKey())) {
        collection = asMapEntry.getValue();
        break;
      }
    }
    assertNotNull(collection);
    Collection<V> expectedCollection = Helpers.copyToList(collection);

    multimap().put(key, v3());
    expectedCollection.add(v3());
    assertEqualIgnoringOrder(expectedCollection, collection);
    assertEquals(size + 1, multimap().size());
  }
}
 
Example 15
Project: googles-monorepo-demo   File: LongsTest.java   View source code 5 votes vote down vote up
public void testLexicographicalComparator() {
  List<long[]> ordered = Arrays.asList(
      new long[] {},
      new long[] {MIN_VALUE},
      new long[] {MIN_VALUE, MIN_VALUE},
      new long[] {MIN_VALUE, (long) 1},
      new long[] {(long) 1},
      new long[] {(long) 1, MIN_VALUE},
      new long[] {MAX_VALUE, MAX_VALUE - (long) 1},
      new long[] {MAX_VALUE, MAX_VALUE},
      new long[] {MAX_VALUE, MAX_VALUE, MAX_VALUE});

  Comparator<long[]> comparator = Longs.lexicographicalComparator();
  Helpers.testComparator(comparator, ordered);
}
 
Example 16
Project: googles-monorepo-demo   File: LongsTest.java   View source code 5 votes vote down vote up
public void testToArray_threadSafe() {
  for (int delta : new int[] { +1, 0, -1 }) {
    for (int i = 0; i < VALUES.length; i++) {
      List<Long> list = Longs.asList(VALUES).subList(0, i);
      Collection<Long> misleadingSize =
          Helpers.misleadingSizeCollection(delta);
      misleadingSize.addAll(list);
      long[] arr = Longs.toArray(misleadingSize);
      assertEquals(i, arr.length);
      for (int j = 0; j < i; j++) {
        assertEquals(VALUES[j], arr[j]);
      }
    }
  }
}
 
Example 17
Project: guava-mock   File: ListMultimapTestSuiteBuilder.java   View source code 5 votes vote down vote up
@Override
protected List<Class<? extends AbstractTester>> getTesters() {
  List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
  testers.add(ListMultimapAsMapTester.class);
  testers.add(ListMultimapEqualsTester.class);
  testers.add(ListMultimapPutTester.class);
  testers.add(ListMultimapPutAllTester.class);
  testers.add(ListMultimapRemoveTester.class);
  testers.add(ListMultimapReplaceValuesTester.class);
  return testers;
}
 
Example 18
Project: guava-mock   File: TestStringListMultimapGenerator.java   View source code 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 19
Project: googles-monorepo-demo   File: CollectionStreamTester.java   View source code 5 votes vote down vote up
@CollectionFeature.Require(absent = KNOWN_ORDER)
public void testStreamToArrayUnknownOrder() {
  synchronized (collection) { // to allow Collections.synchronized* tests to pass
    Helpers.assertEqualIgnoringOrder(
        getSampleElements(), Arrays.asList(collection.stream().toArray()));
  }
}
 
Example 20
Project: googles-monorepo-demo   File: MultimapPutTester.java   View source code 5 votes vote down vote up
@CollectionSize.Require(absent = ZERO)
@MapFeature.Require(SUPPORTS_PUT)
public void testPutPresentKeyPropagatesToEntries() {
  Collection<Entry<K, V>> entries = multimap().entries();
  assertFalse(entries.contains(Helpers.mapEntry(k0(), v3())));
  multimap().put(k0(), v3());
  assertContains(entries, Helpers.mapEntry(k0(), v3()));
}
 
Example 21
Project: guava-mock   File: OrderingTest.java   View source code 5 votes vote down vote up
public void testNullsLast() {
  Ordering<Integer> ordering = Ordering.natural().nullsLast();
  Helpers.testComparator(ordering, 0, 1, Integer.MAX_VALUE, null);

  new EqualsTester()
      .addEqualityGroup(ordering, Ordering.natural().nullsLast())
      .addEqualityGroup(numberOrdering.nullsLast())
      .addEqualityGroup(Ordering.natural())
      .testEquals();
}
 
Example 22
Project: guava-mock   File: MultisetIteratorTester.java   View source code 5 votes vote down vote up
/**
 * Returns {@link Method} instances for the tests that assume multisets support duplicates so that
 * the test of {@code Multisets.forSet()} can suppress them.
 */
@GwtIncompatible // reflection
public static List<Method> getIteratorDuplicateInitializingMethods() {
  return Arrays.asList(
      Helpers.getMethod(MultisetIteratorTester.class, "testIteratorKnownOrder"),
      Helpers.getMethod(MultisetIteratorTester.class, "testIteratorUnknownOrder"),
      Helpers.getMethod(MultisetIteratorTester.class, "testRemovingIteratorKnownOrder"),
      Helpers.getMethod(MultisetIteratorTester.class, "testRemovingIteratorUnknownOrder"));
}
 
Example 23
Project: guava-mock   File: MultisetRemoveTester.java   View source code 5 votes vote down vote up
@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testRetainAllIgnoresCount() {
  initThreeCopies();
  List<E> contents = Helpers.copyToList(getMultiset());
  assertFalse(getMultiset().retainAll(Collections.singleton(e0())));
  expectContents(contents);
}
 
Example 24
Project: googles-monorepo-demo   File: ImmutableEnumMapTest.java   View source code 5 votes vote down vote up
public void testImmutableEnumMapOrdering() {
  ImmutableMap<AnEnum, String> map = Maps.immutableEnumMap(
      ImmutableMap.of(AnEnum.C, "c", AnEnum.A, "a", AnEnum.E, "e"));

  assertThat(map.entrySet()).containsExactly(
      Helpers.mapEntry(AnEnum.A, "a"),
      Helpers.mapEntry(AnEnum.C, "c"),
      Helpers.mapEntry(AnEnum.E, "e")).inOrder();
}
 
Example 25
Project: guava-mock   File: MultimapRemoveEntryTester.java   View source code 5 votes vote down vote up
@CollectionSize.Require(absent = ZERO)
@MapFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_KEYS})
public void testRemoveNullKeyPresent() {
  initMultimapWithNullKey();

  assertTrue(multimap().remove(null, getValueForNullKey()));

  expectMissing(Helpers.mapEntry((K) null, getValueForNullKey()));
  assertGet(getKeyForNullValue(), ImmutableList.<V>of());
}
 
Example 26
Project: guava-mock   File: MultimapRemoveEntryTester.java   View source code 5 votes vote down vote up
@CollectionSize.Require(absent = ZERO)
@MapFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_VALUES})
public void testRemoveNullValuePresent() {
  initMultimapWithNullValue();

  assertTrue(multimap().remove(getKeyForNullValue(), null));

  expectMissing(Helpers.mapEntry(getKeyForNullValue(), (V) null));
  assertGet(getKeyForNullValue(), ImmutableList.<V>of());
}
 
Example 27
Project: guava-mock   File: MultimapKeysTester.java   View source code 5 votes vote down vote up
@CollectionSize.Require(SEVERAL)
public void testKeys() {
  resetContainer(
      Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v1()), Helpers.mapEntry(k1(), v0()));
  Multiset<K> keys = multimap().keys();
  assertEquals(2, keys.count(k0()));
  assertEquals(1, keys.count(k1()));
  assertEquals(3, keys.size());
  assertContainsAllOf(keys, k0(), k1());
  assertContainsAllOf(
      keys.entrySet(), Multisets.immutableEntry(k0(), 2), Multisets.immutableEntry(k1(), 1));
}
 
Example 28
Project: guava-mock   File: EnumBiMapTest.java   View source code 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 29
Project: googles-monorepo-demo   File: ListMultimapTestSuiteBuilder.java   View source code 5 votes vote down vote up
@Override
protected List<Class<? extends AbstractTester>> getTesters() {
  List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
  testers.add(ListMultimapAsMapTester.class);
  testers.add(ListMultimapEqualsTester.class);
  testers.add(ListMultimapPutTester.class);
  testers.add(ListMultimapPutAllTester.class);
  testers.add(ListMultimapRemoveTester.class);
  testers.add(ListMultimapReplaceValuesTester.class);
  return testers;
}
 
Example 30
Project: googles-monorepo-demo   File: CollectionIteratorTester.java   View source code 5 votes vote down vote up
public void testIterator() {
  List<E> iteratorElements = new ArrayList<E>();
  for (E element : collection) { // uses iterator()
    iteratorElements.add(element);
  }
  Helpers.assertEqualIgnoringOrder(Arrays.asList(createSamplesArray()), iteratorElements);
}
 
Example 31
Project: guava-mock   File: ListMultimapAsMapTester.java   View source code 5 votes vote down vote up
@CollectionSize.Require(SEVERAL)
@MapFeature.Require(SUPPORTS_REMOVE)
public void testValuesRemove() {
  resetContainer(
      Helpers.mapEntry(k0(), v0()),
      Helpers.mapEntry(k1(), v0()),
      Helpers.mapEntry(k0(), v3()));
  assertTrue(multimap().asMap().values().remove(Collections.singletonList(v0())));
  assertEquals(2, multimap().size());
  assertEquals(
      Collections.singletonMap(k0(), Lists.newArrayList(v0(), v3())), multimap().asMap());
}
 
Example 32
Project: googles-monorepo-demo   File: MapForEachTester.java   View source code 5 votes vote down vote up
@MapFeature.Require(ALLOWS_NULL_VALUES)
@CollectionSize.Require(absent = ZERO)
public void testForEach_nullValues() {
  initMapWithNullValue();
  List<Entry<K, V>> expectedEntries = Arrays.asList(createArrayWithNullValue());
  List<Entry<K, V>> entries = new ArrayList<>();
  getMap().forEach((k, v) -> entries.add(entry(k, v)));
  Helpers.assertEqualIgnoringOrder(expectedEntries, entries);
}
 
Example 33
Project: googles-monorepo-demo   File: SortedMapNavigationTester.java   View source code 5 votes vote down vote up
public void testHeadMap() {
  List<Entry<K, V>> entries =
      Helpers.copyToList(
          getSubjectGenerator()
              .getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements()));
  Collections.sort(entries, Helpers.<K, V>entryComparator(navigableMap.comparator()));
  for (int i = 0; i < entries.size(); i++) {
    assertEqualInOrder(
        entries.subList(0, i), navigableMap.headMap(entries.get(i).getKey()).entrySet());
  }
}
 
Example 34
Project: googles-monorepo-demo   File: ListSubListTester.java   View source code 5 votes vote down vote up
@ListFeature.Require(SUPPORTS_SET)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testSubList_subListSetAffectsOriginalLargeList() {
  List<E> subList = getList().subList(1, 2);
  subList.set(0, e3());
  List<E> expected = Helpers.copyToList(createSamplesArray());
  expected.set(1, e3());
  expectContents(expected);
}
 
Example 35
Project: guava-mock   File: IntsTest.java   View source code 5 votes vote down vote up
public void testLexicographicalComparator() {
  List<int[]> ordered = Arrays.asList(
      new int[] {},
      new int[] {LEAST},
      new int[] {LEAST, LEAST},
      new int[] {LEAST, (int) 1},
      new int[] {(int) 1},
      new int[] {(int) 1, LEAST},
      new int[] {GREATEST, GREATEST - (int) 1},
      new int[] {GREATEST, GREATEST},
      new int[] {GREATEST, GREATEST, GREATEST});

  Comparator<int[]> comparator = Ints.lexicographicalComparator();
  Helpers.testComparator(comparator, ordered);
}
 
Example 36
Project: guava-mock   File: BiMapPutTester.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(ZERO)
public void testForcePutOverwritesOldValueEntry() {
  getMap().put(k0(), v0());
  getMap().forcePut(k1(), v0());
  // verify that the bimap is unchanged
  expectAdded(Helpers.mapEntry(k1(), v0()));
}
 
Example 37
Project: guava-mock   File: ImmutableListTest.java   View source code 5 votes vote down vote up
public void testCopyOf_concurrentlyMutating() {
  List<String> sample = Lists.newArrayList("a", "b", "c");
  for (int delta : new int[] {-1, 0, 1}) {
    for (int i = 0; i < sample.size(); i++) {
      Collection<String> misleading =
          Helpers.misleadingSizeCollection(delta);
      List<String> expected = sample.subList(0, i);
      misleading.addAll(expected);
      assertEquals(expected, ImmutableList.copyOf(misleading));
      assertEquals(expected,
          ImmutableList.copyOf((Iterable<String>) misleading));
    }
  }
}
 
Example 38
Project: googles-monorepo-demo   File: OrderingTest.java   View source code 5 votes vote down vote up
public void testCompound_instance() {
  Comparator<String> comparator = byCharAt(1).compound(byCharAt(0));
  Helpers.testComparator(comparator, ImmutableList.of(
      "red",
      "yellow",
      "violet",
      "blue",
      "indigo",
      "green",
      "orange"));
}
 
Example 39
Project: guava-mock   File: MapEntrySetTester.java   View source code 5 votes vote down vote up
public void testContainsEntryWithIncomparableKey() {
  try {
    assertFalse(getMap().entrySet().contains(Helpers.mapEntry(IncomparableType.INSTANCE, v0())));
  } catch (ClassCastException acceptable) {
    // allowed by the spec
  }
}
 
Example 40
Project: googles-monorepo-demo   File: MultimapEntriesTester.java   View source code 5 votes vote down vote up
@CollectionSize.Require(absent = ZERO)
@MapFeature.Require(SUPPORTS_REMOVE)
public void testRemovePropagatesToMultimap() {
  assertTrue(multimap().entries().remove(Helpers.mapEntry(k0(), v0())));
  expectMissing(Helpers.mapEntry(k0(), v0()));
  assertEquals(getNumElements() - 1, multimap().size());
  assertFalse(multimap().containsEntry(k0(), v0()));
}