@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, sampleValues().e3);
      expectedCollection.add(sampleValues().e3);
      assertThat(collection).has().exactlyAs(expectedCollection);
      assertEquals(size + 1, multimap().size());
    }
  }
  @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);

      ASSERT.that(collection).hasContentsAnyOrder(expectedCollection.toArray());
      assertEquals(!expectedCollection.isEmpty(), multimap().containsKey(key));
    }
  }
Example #3
0
 @MapFeature.Require(SUPPORTS_REMOVE)
 @CollectionSize.Require(SEVERAL)
 public void testPollLast() {
   assertEquals(c, navigableMap.pollLastEntry());
   assertEquals(
       entries.subList(0, entries.size() - 1), Helpers.copyToList(navigableMap.entrySet()));
 }
 @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);
 }
  @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, sampleValues().e3);
      expectedCollection.add(sampleValues().e3);
      assertThat(collection).has().exactlyAs(expectedCollection);
      assertEquals(size + 1, multimap().size());
    }
  }
  @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);

      ASSERT.that(collection).hasContentsAnyOrder(expectedCollection.toArray());
      assertEquals(!expectedCollection.isEmpty(), multimap().containsKey(key));
    }
  }
 @Override
 protected List<Class<? extends AbstractTester>> getTesters() {
   List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
   testers.add(CollectionSerializationEqualTester.class);
   testers.add(MultisetReadsTester.class);
   testers.add(MultisetSetCountConditionallyTester.class);
   testers.add(MultisetSetCountUnconditionallyTester.class);
   testers.add(MultisetWritesTester.class);
   testers.add(MultisetIteratorTester.class);
   testers.add(MultisetSerializationTester.class);
   return testers;
 }
Example #8
0
  @Override
  public void setUp() throws Exception {
    super.setUp();
    navigableMap = (NavigableMap<K, V>) getMap();
    entries =
        Helpers.copyToList(
            getSubjectGenerator()
                .getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements()));
    Collections.sort(entries, Helpers.<K, V>entryComparator(navigableMap.comparator()));

    // some tests assume SEVERAL == 3
    if (entries.size() >= 1) {
      a = entries.get(0);
      if (entries.size() >= 3) {
        b = entries.get(1);
        c = entries.get(2);
      }
    }
  }
  @MapFeature.Require(SUPPORTS_PUT)
  public void testPutTwoElements() {
    int size = getNumElements();

    K key = sampleKeys().e0;
    V v1 = sampleValues().e3;
    V v2 = sampleValues().e4;

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

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

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

    assertGet(key, values);
    assertEquals(size + 2, multimap().size());
  }
  private void runListIteratorTest(Set<IteratorFeature> features) {
    new ListIteratorTester<E>(
        listListIteratorTesterNumIterations(),
        singleton(samples.e4),
        features,
        Helpers.copyToList(getSampleElements()),
        0) {
      {
        // TODO: don't set this universally
        stopTestingWhenAddThrowsException();
      }

      @Override
      protected ListIterator<E> newTargetIterator() {
        resetCollection();
        return getList().listIterator();
      }

      @Override
      protected void verify(List<E> elements) {
        expectContents(elements);
      }
    }.test();
  }
 protected final void expectReplacement(Entry<K, V> newEntry) {
   List<Entry<K, V>> expected = Helpers.copyToList(getSampleElements());
   replaceValue(expected, newEntry);
   expectContents(expected);
 }
 @Override
 protected List<Class<? extends AbstractTester>> getTesters() {
   List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
   testers.add(NavigableMapNavigationTester.class);
   return testers;
 }
Example #13
0
 public void testEquals_list() {
   assertFalse("A List should never equal a Set.", getSet().equals(Helpers.copyToList(getSet())));
 }