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

The following are top voted examples for showing how to use com.google.common.collect.testing.features.MapFeature. 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: MultimapPutIterableTester.java   Source Code and License 6 votes vote down vote up
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES)
public void testPutAllNullValueNullLast_unsupported() {
  int size = getNumElements();

  try {
    multimap().putAll(k3(), Lists.newArrayList(v3(), null));
    fail();
  } catch (NullPointerException expected) {
  }

  Collection<V> values = multimap().get(k3());
  if (values.size() == 0) {
    expectUnchanged();
    // Be extra thorough in case internal state was corrupted by the expected null.
    assertEquals(Lists.newArrayList(), Lists.newArrayList(values));
    assertEquals(size, multimap().size());
  } else {
    assertEquals(Lists.newArrayList(v3()), Lists.newArrayList(values));
    assertEquals(size + 1, multimap().size());
  }
}
 
Example 2
Project: guava-mock   File: TestsForMapsInJavaUtil.java   Source Code and License 6 votes vote down vote up
public Test testsForTreeMapNatural() {
  return NavigableMapTestSuiteBuilder.using(
          new TestStringSortedMapGenerator() {
            @Override
            protected SortedMap<String, String> create(Entry<String, String>[] entries) {
              /*
               * TODO(cpovirk): it would be nice to create an input Map and use
               * the copy constructor here and in the other tests
               */
              return populate(new TreeMap<String, String>(), entries);
            }
          })
      .named("TreeMap, natural")
      .withFeatures(
          MapFeature.GENERAL_PURPOSE,
          MapFeature.ALLOWS_NULL_VALUES,
          MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
          CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
          CollectionFeature.KNOWN_ORDER,
          CollectionFeature.SERIALIZABLE,
          CollectionSize.ANY)
      .suppressing(suppressForTreeMapNatural())
      .createTestSuite();
}
 
Example 3
Project: guava-mock   File: TestsForMapsInJavaUtil.java   Source Code and License 6 votes vote down vote up
public Test testsForUnmodifiableNavigableMap() {
  return MapTestSuiteBuilder.using(
      new TestStringSortedMapGenerator() {
        @Override
        protected NavigableMap<String, String> create(Entry<String, String>[] entries) {
          return Collections.unmodifiableNavigableMap(populate(new TreeMap<>(), entries));
        }
      })
      .named("unmodifiableNavigableMap/TreeMap, natural")
      .withFeatures(
          MapFeature.ALLOWS_NULL_VALUES,
          CollectionFeature.KNOWN_ORDER,
          CollectionFeature.SERIALIZABLE,
          CollectionSize.ANY)
      .suppressing(suppressForUnmodifiableNavigableMap())
      .createTestSuite();
}
 
Example 4
Project: guava-mock   File: TestsForMapsInJavaUtil.java   Source Code and License 6 votes vote down vote up
public Test testsForConcurrentSkipListMapNatural() {
  return NavigableMapTestSuiteBuilder.using(
          new TestStringSortedMapGenerator() {
            @Override
            protected SortedMap<String, String> create(Entry<String, String>[] entries) {
              return populate(new ConcurrentSkipListMap<String, String>(), entries);
            }
          })
      .named("ConcurrentSkipListMap, natural")
      .withFeatures(
          MapFeature.GENERAL_PURPOSE,
          CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
          CollectionFeature.KNOWN_ORDER,
          CollectionFeature.SERIALIZABLE,
          CollectionSize.ANY)
      .suppressing(suppressForConcurrentSkipListMap())
      .createTestSuite();
}
 
Example 5
Project: guava-mock   File: TestsForMapsInJavaUtil.java   Source Code and License 6 votes vote down vote up
public Test testsForConcurrentSkipListMapWithComparator() {
  return NavigableMapTestSuiteBuilder.using(
          new TestStringSortedMapGenerator() {
            @Override
            protected SortedMap<String, String> create(Entry<String, String>[] entries) {
              return populate(
                  new ConcurrentSkipListMap<String, String>(arbitraryNullFriendlyComparator()),
                  entries);
            }
          })
      .named("ConcurrentSkipListMap, with comparator")
      .withFeatures(
          MapFeature.GENERAL_PURPOSE,
          CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
          CollectionFeature.KNOWN_ORDER,
          CollectionFeature.SERIALIZABLE,
          CollectionSize.ANY)
      .suppressing(suppressForConcurrentSkipListMap())
      .createTestSuite();
}
 
Example 6
Project: googles-monorepo-demo   File: TestsForMapsInJavaUtil.java   Source Code and License 6 votes vote down vote up
public Test testsForUnmodifiableNavigableMap() {
  return MapTestSuiteBuilder.using(
      new TestStringSortedMapGenerator() {
        @Override
        protected NavigableMap<String, String> create(Entry<String, String>[] entries) {
          return Collections.unmodifiableNavigableMap(populate(new TreeMap<>(), entries));
        }
      })
      .named("unmodifiableNavigableMap/TreeMap, natural")
      .withFeatures(
          MapFeature.ALLOWS_NULL_VALUES,
          CollectionFeature.KNOWN_ORDER,
          CollectionFeature.SERIALIZABLE,
          CollectionSize.ANY)
      .suppressing(suppressForUnmodifiableNavigableMap())
      .createTestSuite();
}
 
Example 7
Project: googles-monorepo-demo   File: TestsForMapsInJavaUtil.java   Source Code and License 6 votes vote down vote up
public Test testsForEnumMap() {
  return MapTestSuiteBuilder.using(
          new TestEnumMapGenerator() {
            @Override
            protected Map<AnEnum, String> create(Entry<AnEnum, String>[] entries) {
              return populate(new EnumMap<AnEnum, String>(AnEnum.class), entries);
            }
          })
      .named("EnumMap")
      .withFeatures(
          MapFeature.GENERAL_PURPOSE,
          MapFeature.ALLOWS_NULL_VALUES,
          MapFeature.RESTRICTS_KEYS,
          CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
          CollectionFeature.KNOWN_ORDER,
          CollectionFeature.SERIALIZABLE,
          CollectionSize.ANY)
      .suppressing(suppressForEnumMap())
      .createTestSuite();
}
 
Example 8
Project: guava-mock   File: MapComputeTester.java   Source Code and License 6 votes vote down vote up
@MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
@CollectionSize.Require(absent = ZERO)
public void testCompute_presentToAbsent() {
  assertNull(
      "Map.compute(present, functionReturningNull) should return null",
      getMap()
          .compute(
              k0(),
              (k, v)
                  -> {
                    assertEquals(k0(), k);
                    assertEquals(v0(), v);
                    return null;
                  }));
  expectMissing(e0());
  expectMissingKeys(k0());
  assertEquals(getNumElements() - 1, getMap().size());
}
 
Example 9
Project: guava-mock   File: SetMultimapPutTester.java   Source Code and License 6 votes vote down vote up
@MapFeature.Require(SUPPORTS_PUT)
public void testPutDuplicateValue() {
  List<Entry<K, V>> entries = copyToList(multimap().entries());

  for (Entry<K, V> entry : entries) {
    resetContainer();
    K k = entry.getKey();
    V v = entry.getValue();

    Set<V> values = multimap().get(k);
    Set<V> expectedValues = copyToSet(values);

    assertFalse(multimap().put(k, v));
    assertEquals(expectedValues, values);
    assertGet(k, expectedValues);
  }
}
 
Example 10
Project: guava-mock   File: MultimapAsMapGetTester.java   Source Code and License 6 votes vote down vote up
@CollectionSize.Require(absent = ZERO)
@MapFeature.Require({SUPPORTS_REMOVE, SUPPORTS_PUT})
public void testPropagatesRemoveThenAddToMultimap() {
  int oldSize = getNumElements();

  Collection<V> result = multimap().asMap().get(k0());
  assertTrue(result.remove(v0()));

  assertFalse(multimap().containsKey(k0()));
  assertFalse(multimap().containsEntry(k0(), v0()));
  assertEmpty(result);

  assertTrue(result.add(v1()));
  assertTrue(result.add(v2()));

  assertContentsAnyOrder(result, v1(), v2());
  assertContentsAnyOrder(multimap().get(k0()), v1(), v2());
  assertTrue(multimap().containsKey(k0()));
  assertFalse(multimap().containsEntry(k0(), v0()));
  assertTrue(multimap().containsEntry(k0(), v2()));
  assertEquals(oldSize + 1, multimap().size());
}
 
Example 11
Project: guava-mock   File: MapMergeTester.java   Source Code and License 6 votes vote down vote up
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testMergePresentToNull() {
  assertNull(
      "Map.merge(present, value, functionReturningNull) should return null",
      getMap()
          .merge(
              k0(),
              v3(),
              (oldV, newV) -> {
                assertEquals(v0(), oldV);
                assertEquals(v3(), newV);
                return null;
              }));
  expectMissing(e0());
}
 
Example 12
Project: guava-mock   File: MultimapRemoveEntryTester.java   Source Code and License 6 votes vote down vote up
@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 13
Project: googles-monorepo-demo   File: TestsForMapsInJavaUtil.java   Source Code and License 6 votes vote down vote up
public Test testsForUnmodifiableSortedMap() {
  return MapTestSuiteBuilder.using(
      new TestStringSortedMapGenerator() {
        @Override
        protected SortedMap<String, String> create(Entry<String, String>[] entries) {
          SortedMap<String, String> map = populate(new TreeMap<String, String>(), entries);
          return Collections.unmodifiableSortedMap(map);
        }
      })
      .named("unmodifiableSortedMap/TreeMap, natural")
      .withFeatures(
          MapFeature.ALLOWS_NULL_VALUES,
          CollectionFeature.KNOWN_ORDER,
          CollectionFeature.SERIALIZABLE,
          CollectionSize.ANY)
      .suppressing(suppressForUnmodifiableSortedMap())
      .createTestSuite();
}
 
Example 14
Project: guava-mock   File: MapMergeTester.java   Source Code and License 6 votes vote down vote up
@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES})
@CollectionSize.Require(absent = ZERO)
public void testMappedToNull() {
  initMapWithNullValue();
  assertEquals(
      "Map.merge(keyMappedToNull, value, function) should return value",
      v3(),
      getMap()
          .merge(
              getKeyForNullValue(),
              v3(),
              (oldV, newV) -> {
                throw new AssertionFailedError(
                    "Should not call merge function if key was mapped to null");
              }));
  expectReplacement(entry(getKeyForNullValue(), v3()));
}
 
Example 15
Project: guava-mock   File: MapComputeTester.java   Source Code and License 6 votes vote down vote up
@MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE, ALLOWS_NULL_VALUES})
@CollectionSize.Require(absent = ZERO)
public void testCompute_presentNullToPresentNonnull() {
  initMapWithNullValue();
  V value = getValueForNullKey();
  assertEquals(
      "Map.compute(presentMappedToNull, functionReturningValue) should return new value",
      value,
      getMap()
          .compute(
              getKeyForNullValue(),
              (k, v)
                  -> {
                    assertEquals(getKeyForNullValue(), k);
                    assertNull(v);
                    return value;
                  }));
  expectReplacement(entry(getKeyForNullValue(), value));
  assertEquals(getNumElements(), getMap().size());
}
 
Example 16
Project: googles-monorepo-demo   File: BiMapPutTester.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(ZERO)
public void putDistinctKeysDistinctValues() {
  getMap().put(k0(), v0());
  getMap().put(k1(), v1());
  expectAdded(e0(), e1());
}
 
Example 17
Project: googles-monorepo-demo   File: MapTestSuiteBuilder.java   Source Code and License 5 votes vote down vote up
private static Set<Feature<?>> computeValuesCollectionFeatures(Set<Feature<?>> mapFeatures) {
  Set<Feature<?>> valuesCollectionFeatures = computeCommonDerivedCollectionFeatures(mapFeatures);
  if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUE_QUERIES)) {
    valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
  }
  if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUES)) {
    valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES);
  }

  return valuesCollectionFeatures;
}
 
Example 18
Project: googles-monorepo-demo   File: MapGetTester.java   Source Code and License 5 votes vote down vote up
@MapFeature.Require(absent = ALLOWS_NULL_KEY_QUERIES)
public void testGet_nullNotContainedAndUnsupported() {
  try {
    assertNull("get(null) should return null or throw", get(null));
  } catch (NullPointerException tolerated) {
  }
}
 
Example 19
Project: guava-mock   File: MultimapTestSuiteBuilder.java   Source Code and License 5 votes vote down vote up
static Set<Feature<?>> computeKeysFeatures(Set<Feature<?>> multimapFeatures) {
  Set<Feature<?>> result = computeDerivedCollectionFeatures(multimapFeatures);
  if (multimapFeatures.contains(MapFeature.ALLOWS_NULL_KEYS)) {
    result.add(CollectionFeature.ALLOWS_NULL_VALUES);
  }
  if (multimapFeatures.contains(MapFeature.ALLOWS_NULL_KEY_QUERIES)) {
    result.add(CollectionFeature.ALLOWS_NULL_QUERIES);
  }
  return result;
}
 
Example 20
Project: guava-mock   File: ConcurrentMapPutIfAbsentTester.java   Source Code and License 5 votes vote down vote up
@MapFeature.Require(absent = SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testPutIfAbsent_unsupportedPresentExistingValue() {
  try {
    assertEquals(
        "putIfAbsent(present, existingValue) should return present or throw",
        v0(),
        putIfAbsent(e0()));
  } catch (UnsupportedOperationException tolerated) {
  }
  expectUnchanged();
}
 
Example 21
Project: googles-monorepo-demo   File: ConcurrentMapReplaceTester.java   Source Code and License 5 votes vote down vote up
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_KEY_QUERIES)
public void testReplace_absentNullKeyUnsupported() {
  try {
    getMap().replace(null, v3());
  } catch (NullPointerException tolerated) {
    // permitted not to throw because it would be a no-op
  }
  expectUnchanged();
}
 
Example 22
Project: guava-mock   File: MapComputeIfPresentTester.java   Source Code and License 5 votes vote down vote up
@MapFeature.Require(absent = SUPPORTS_PUT)
public void testComputeIfPresent_unsupportedAbsent() {
  try {
    getMap()
        .computeIfPresent(
            k3(),
            (k, v) -> {
              throw new AssertionFailedError();
            });
  } catch (UnsupportedOperationException tolerated) {
  }
  expectUnchanged();
}
 
Example 23
Project: googles-monorepo-demo   File: ConcurrentMapPutIfAbsentTester.java   Source Code and License 5 votes vote down vote up
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_KEYS)
public void testPutIfAbsent_nullKeyUnsupported() {
  try {
    getMap().putIfAbsent(null, v3());
    fail("putIfAbsent(null, value) should throw");
  } catch (NullPointerException expected) {
  }
  expectUnchanged();
  expectNullKeyMissingWhenNullKeysUnsupported(
      "Should not contain null key after unsupported putIfAbsent(null, value)");
}
 
Example 24
Project: guava-mock   File: MultimapTestSuiteBuilder.java   Source Code and License 5 votes vote down vote up
static Set<Feature<?>> computeEntriesFeatures(Set<Feature<?>> multimapFeatures) {
  Set<Feature<?>> result = computeDerivedCollectionFeatures(multimapFeatures);
  if (multimapFeatures.contains(MapFeature.ALLOWS_NULL_ENTRY_QUERIES)) {
    result.add(CollectionFeature.ALLOWS_NULL_QUERIES);
  }
  return result;
}
 
Example 25
Project: googles-monorepo-demo   File: ConcurrentMapReplaceEntryTester.java   Source Code and License 5 votes vote down vote up
@MapFeature.Require(absent = SUPPORTS_PUT)
public void testReplaceEntry_unsupportedAbsentKey() {
  try {
    getMap().replace(k3(), v3(), v4());
  } catch (UnsupportedOperationException tolerated) {
    // the operation would be a no-op, so exceptions are allowed but not required
  }
  expectUnchanged();
}
 
Example 26
Project: googles-monorepo-demo   File: BiMapClearTester.java   Source Code and License 5 votes vote down vote up
@MapFeature.Require(SUPPORTS_REMOVE)
public void testValuesClearClearsInverse() {
  BiMap<V, K> inv = getMap().inverse();
  getMap().values().clear();
  assertTrue(getMap().isEmpty());
  assertTrue(inv.isEmpty());
}
 
Example 27
Project: googles-monorepo-demo   File: MapRemoveEntryTester.java   Source Code and License 5 votes vote down vote up
@MapFeature.Require(absent = SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemove_unsupportedPresent() {
  try {
    getMap().remove(k0(), v0());
    fail("Expected UnsupportedOperationException");
  } catch (UnsupportedOperationException expected) {}
  expectUnchanged();
}
 
Example 28
Project: guava-mock   File: MapTestSuiteBuilder.java   Source Code and License 5 votes vote down vote up
private static Set<Feature<?>> computeValuesCollectionFeatures(Set<Feature<?>> mapFeatures) {
  Set<Feature<?>> valuesCollectionFeatures = computeCommonDerivedCollectionFeatures(mapFeatures);
  if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUE_QUERIES)) {
    valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
  }
  if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUES)) {
    valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES);
  }

  return valuesCollectionFeatures;
}
 
Example 29
Project: guava-mock   File: MapTestSuiteBuilder.java   Source Code and License 5 votes vote down vote up
public static Set<Feature<?>> computeCommonDerivedCollectionFeatures(
    Set<Feature<?>> mapFeatures) {
  mapFeatures = new HashSet<Feature<?>>(mapFeatures);
  Set<Feature<?>> derivedFeatures = new HashSet<Feature<?>>();
  mapFeatures.remove(CollectionFeature.SERIALIZABLE);
  if (mapFeatures.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
    derivedFeatures.add(CollectionFeature.SERIALIZABLE);
  }
  if (mapFeatures.contains(MapFeature.SUPPORTS_REMOVE)) {
    derivedFeatures.add(CollectionFeature.SUPPORTS_REMOVE);
  }
  if (mapFeatures.contains(MapFeature.REJECTS_DUPLICATES_AT_CREATION)) {
    derivedFeatures.add(CollectionFeature.REJECTS_DUPLICATES_AT_CREATION);
  }
  if (mapFeatures.contains(MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION)) {
    derivedFeatures.add(CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION);
  }
  // add the intersection of CollectionFeature.values() and mapFeatures
  for (CollectionFeature feature : CollectionFeature.values()) {
    if (mapFeatures.contains(feature)) {
      derivedFeatures.add(feature);
    }
  }
  // add the intersection of CollectionSize.values() and mapFeatures
  for (CollectionSize size : CollectionSize.values()) {
    if (mapFeatures.contains(size)) {
      derivedFeatures.add(size);
    }
  }
  return derivedFeatures;
}
 
Example 30
Project: guava-mock   File: MultimapGetTester.java   Source Code and License 5 votes vote down vote up
@CollectionSize.Require(SEVERAL)
@MapFeature.Require(SUPPORTS_REMOVE)
public void testPropagatesRemoveToMultimap() {
  resetContainer(
      Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v3()), Helpers.mapEntry(k0(), v2()));
  Collection<V> result = multimap().get(k0());
  assertTrue(result.remove(v0()));
  assertFalse(multimap().containsEntry(k0(), v0()));
  assertEquals(2, multimap().size());
}
 
Example 31
Project: guava-mock   File: MapRemoveEntryTester.java   Source Code and License 5 votes vote down vote up
@MapFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_KEY_QUERIES)
public void testRemove_nullKeyQueriesUnsupported() {
  try {
    assertFalse(getMap().remove(null, v3()));
  } catch (NullPointerException tolerated) {
    // since the operation would be a no-op, the exception is not required
  }
  expectUnchanged();    
}
 
Example 32
Project: guava-mock   File: MapComputeIfPresentTester.java   Source Code and License 5 votes vote down vote up
@MapFeature.Require(SUPPORTS_PUT)
public void testComputeIfPresent_supportedAbsent() {
  assertNull(
      "computeIfPresent(notPresent, function) should return null",
      getMap()
          .computeIfPresent(
              k3(),
              (k, v) -> {
                throw new AssertionFailedError();
              }));
  expectUnchanged();
}
 
Example 33
Project: googles-monorepo-demo   File: BiMapPutTester.java   Source Code and License 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 34
Project: googles-monorepo-demo   File: MapMergeTester.java   Source Code and License 5 votes vote down vote up
@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_KEYS})
public void testMergeAbsentNullKey() {
  assertEquals(
      "Map.merge(null, value, function) should return value",
      v3(),
      getMap()
          .merge(
              null,
              v3(),
              (oldV, newV) -> {
                throw new AssertionFailedError(
                    "Should not call merge function if key was absent");
              }));
  expectAdded(entry(null, v3()));
}
 
Example 35
Project: googles-monorepo-demo   File: MultimapPutTester.java   Source Code and License 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 36
Project: googles-monorepo-demo   File: MapRemoveTester.java   Source Code and License 5 votes vote down vote up
@MapFeature.Require(absent = SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemove_unsupported() {
  try {
    getMap().remove(k0());
    fail("remove(present) should throw UnsupportedOperationException");
  } catch (UnsupportedOperationException expected) {
  }
  expectUnchanged();
  assertEquals("remove(present) should not remove the element", v0(), get(k0()));
}
 
Example 37
Project: googles-monorepo-demo   File: MultimapEqualsTester.java   Source Code and License 5 votes vote down vote up
@CollectionSize.Require(absent = ZERO)
@MapFeature.Require(ALLOWS_NULL_KEYS)
public void testEqualsMultimapWithNullKey() {
  Multimap<K, V> original = multimap();
  initMultimapWithNullKey();
  Multimap<K, V> withNull = multimap();
  new EqualsTester()
      .addEqualityGroup(original)
      .addEqualityGroup(
          withNull, getSubjectGenerator().create((Object[]) createArrayWithNullKey()))
      .testEquals();
}
 
Example 38
Project: guava-mock   File: MapRemoveTester.java   Source Code and License 5 votes vote down vote up
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemove_present() {
  int initialSize = getMap().size();
  assertEquals("remove(present) should return the associated value", v0(), getMap().remove(k0()));
  assertEquals(
      "remove(present) should decrease a map's size by one.", initialSize - 1, getMap().size());
  expectMissing(e0());
}
 
Example 39
Project: guava-mock   File: MultimapContainsEntryTester.java   Source Code and License 5 votes vote down vote up
/**
 * Copy of the {@link #testContainsEntryNullDisallowed} test. Needed because
 * "optional" feature requirements are not supported.
 */
@MapFeature.Require(absent = ALLOWS_NULL_VALUE_QUERIES)
public void testContainsEntryNullDisallowedBecauseValueQueriesDisallowed() {
  try {
    multimap().containsEntry(k3(), null);
    fail("Expected NullPointerException");
  } catch (NullPointerException expected) {
    // success
  }
}
 
Example 40
Project: guava-mock   File: NavigableMapNavigationTester.java   Source Code and License 5 votes vote down vote up
@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()));
}