Java Code Examples for com.google.common.collect.testing.Helpers.copyToList()

The following are Jave code examples for showing how to use copyToList() of the com.google.common.collect.testing.Helpers class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: googles-monorepo-demo   File: NavigableSetNavigationTester.java   Source Code and License Vote up 6 votes
@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 2
Project: guava-mock   File: MultisetTestSuiteBuilder.java   Source Code and License Vote up 6 votes
@Override
protected List<Class<? extends AbstractTester>> getTesters() {
  List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
  testers.add(CollectionSerializationEqualTester.class);
  testers.add(MultisetAddTester.class);
  testers.add(MultisetContainsTester.class);
  testers.add(MultisetCountTester.class);
  testers.add(MultisetElementSetTester.class);
  testers.add(MultisetEqualsTester.class);
  testers.add(MultisetForEachEntryTester.class);
  testers.add(MultisetReadsTester.class);
  testers.add(MultisetSetCountConditionallyTester.class);
  testers.add(MultisetSetCountUnconditionallyTester.class);
  testers.add(MultisetRemoveTester.class);
  testers.add(MultisetEntrySetTester.class);
  testers.add(MultisetIteratorTester.class);
  testers.add(MultisetSerializationTester.class);
  return testers;
}
 
Example 3
Project: guava-mock   File: MultimapRemoveEntryTester.java   Source Code and License Vote up 6 votes
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemovePropagatesToGet() {
  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().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 4
Project: guava-mock   File: MultimapReplaceValuesTester.java   Source Code and License Vote up 6 votes
@CollectionSize.Require(absent = ZERO)
@MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
public void testReplaceNonEmptyValues() {
  List<K> keys = Helpers.copyToList(multimap().keySet());
  @SuppressWarnings("unchecked")
  List<V> values = Arrays.asList(v0(), v2(), v3());

  for (K k : keys) {
    resetContainer();

    int size = multimap().size();
    Collection<V> oldKeyValues = Helpers.copyToList(multimap().get(k));
    multimap().replaceValues(k, values);
    assertGet(k, values);
    assertEquals(size + values.size() - oldKeyValues.size(), multimap().size());
  }
}
 
Example 5
Project: googles-monorepo-demo   File: MultimapPutTester.java   Source Code and License Vote up 6 votes
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testPutPresentKeyPropagatesToGet() {
  List<K> keys = Helpers.copyToList(multimap().keySet());
  for (K key : keys) {
    resetContainer();

    int size = getNumElements();

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

    multimap().put(key, v3());
    expectedCollection.add(v3());
    assertEqualIgnoringOrder(expectedCollection, collection);
    assertEquals(size + 1, multimap().size());
  }
}
 
Example 6
Project: googles-monorepo-demo   File: MultimapPutTester.java   Source Code and License Vote up 6 votes
@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 7
Project: guava-mock   File: ListSubListTester.java   Source Code and License Vote up 5 votes
@ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testSubList_subListRemoveAffectsOriginalLargeList() {
  List<E> subList = getList().subList(1, 3);
  subList.remove(e2());
  List<E> expected = Helpers.copyToList(createSamplesArray());
  expected.remove(2);
  expectContents(expected);
}
 
Example 8
Project: guava-mock   File: SetMultimapTestSuiteBuilder.java   Source Code and License Vote up 5 votes
@Override
protected List<Class<? extends AbstractTester>> getTesters() {
  List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
  testers.add(SetMultimapAsMapTester.class);
  testers.add(SetMultimapEqualsTester.class);
  testers.add(SetMultimapPutTester.class);
  testers.add(SetMultimapPutAllTester.class);
  testers.add(SetMultimapReplaceValuesTester.class);
  return testers;
}
 
Example 9
Project: googles-monorepo-demo   File: MultimapRemoveEntryTester.java   Source Code and License Vote up 5 votes
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemovePropagatesToAsMapEntrySet() {
  List<Entry<K, V>> entries = Helpers.copyToList(multimap().entries());
  for (Entry<K, V> entry : entries) {
    resetContainer();

    K key = entry.getKey();
    V value = entry.getValue();

    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().remove(key, value);
    expectedCollection.remove(value);

    assertEqualIgnoringOrder(expectedCollection, collection);
    assertEquals(!expectedCollection.isEmpty(), multimap().containsKey(key));
  }
}
 
Example 10
Project: googles-monorepo-demo   File: SortedMapNavigationTester.java   Source Code and License Vote up 5 votes
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 11
Project: googles-monorepo-demo   File: SetMultimapTestSuiteBuilder.java   Source Code and License Vote up 5 votes
@Override
protected List<Class<? extends AbstractTester>> getTesters() {
  List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
  testers.add(SetMultimapAsMapTester.class);
  testers.add(SetMultimapEqualsTester.class);
  testers.add(SetMultimapPutTester.class);
  testers.add(SetMultimapPutAllTester.class);
  testers.add(SetMultimapReplaceValuesTester.class);
  return testers;
}
 
Example 12
Project: guava-mock   File: MultimapRemoveEntryTester.java   Source Code and License Vote up 5 votes
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemovePropagatesToAsMapEntrySet() {
  List<Entry<K, V>> entries = Helpers.copyToList(multimap().entries());
  for (Entry<K, V> entry : entries) {
    resetContainer();

    K key = entry.getKey();
    V value = entry.getValue();

    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().remove(key, value);
    expectedCollection.remove(value);

    assertEqualIgnoringOrder(expectedCollection, collection);
    assertEquals(!expectedCollection.isEmpty(), multimap().containsKey(key));
  }
}
 
Example 13
Project: googles-monorepo-demo   File: CollectionForEachTester.java   Source Code and License Vote up 5 votes
@CollectionFeature.Require(KNOWN_ORDER)
public void testForEachKnownOrder() {
  List<E> elements = new ArrayList<E>();
  collection.forEach(elements::add);
  List<E> expected = Helpers.copyToList(getOrderedElements());
  assertEquals("Different ordered iteration", expected, elements);
}
 
Example 14
Project: googles-monorepo-demo   File: MultimapPutTester.java   Source Code and License Vote up 5 votes
@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: MultimapPutTester.java   Source Code and License Vote up 5 votes
@MapFeature.Require(SUPPORTS_PUT)
public void testPutTwoElements() {
  int size = getNumElements();

  List<V> values = Helpers.copyToList(multimap().get(k0()));

  assertTrue(multimap().put(k0(), v1()));
  assertTrue(multimap().put(k0(), v2()));

  values.add(v1());
  values.add(v2());

  assertGet(k0(), values);
  assertEquals(size + 2, multimap().size());
}
 
Example 16
Project: googles-monorepo-demo   File: CollectionIteratorTester.java   Source Code and License Vote up 5 votes
@CollectionFeature.Require(KNOWN_ORDER)
public void testIterationOrdering() {
  List<E> iteratorElements = new ArrayList<E>();
  for (E element : collection) { // uses iterator()
    iteratorElements.add(element);
  }
  List<E> expected = Helpers.copyToList(getOrderedElements());
  assertEquals("Different ordered iteration", expected, iteratorElements);
}
 
Example 17
Project: googles-monorepo-demo   File: ListRemoveAtIndexTester.java   Source Code and License Vote up 5 votes
private void runRemoveTest(int index) {
  assertEquals(
      Platform.format("remove(%d) should return the element at index %d", index, index),
      getList().get(index),
      getList().remove(index));
  List<E> expected = Helpers.copyToList(createSamplesArray());
  expected.remove(index);
  expectContents(expected);
}
 
Example 18
Project: guava-mock   File: ListRemoveAtIndexTester.java   Source Code and License Vote up 5 votes
private void runRemoveTest(int index) {
  assertEquals(
      Platform.format("remove(%d) should return the element at index %d", index, index),
      getList().get(index),
      getList().remove(index));
  List<E> expected = Helpers.copyToList(createSamplesArray());
  expected.remove(index);
  expectContents(expected);
}
 
Example 19
Project: guava-mock   File: CollectionIteratorTester.java   Source Code and License Vote up 5 votes
@CollectionFeature.Require(KNOWN_ORDER)
public void testIterationOrdering() {
  List<E> iteratorElements = new ArrayList<E>();
  for (E element : collection) { // uses iterator()
    iteratorElements.add(element);
  }
  List<E> expected = Helpers.copyToList(getOrderedElements());
  assertEquals("Different ordered iteration", expected, iteratorElements);
}
 
Example 20
Project: guava-mock   File: SortedMapNavigationTester.java   Source Code and License Vote up 5 votes
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());
  }
}