当前位置: 首页>>代码示例>>Java>>正文


Java MapFeature类代码示例

本文整理汇总了Java中com.google.common.collect.testing.features.MapFeature的典型用法代码示例。如果您正苦于以下问题:Java MapFeature类的具体用法?Java MapFeature怎么用?Java MapFeature使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MapFeature类属于com.google.common.collect.testing.features包,在下文中一共展示了MapFeature类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPutAllNullValueNullLast_unsupported

import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
@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());
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:22,代码来源:MultimapPutIterableTester.java

示例2: testsForTreeMapNatural

import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
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();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:25,代码来源:TestsForMapsInJavaUtil.java

示例3: testsForUnmodifiableNavigableMap

import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
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();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:18,代码来源:TestsForMapsInJavaUtil.java

示例4: testsForConcurrentSkipListMapNatural

import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
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();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:TestsForMapsInJavaUtil.java

示例5: testsForConcurrentSkipListMapWithComparator

import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
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();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:21,代码来源:TestsForMapsInJavaUtil.java

示例6: testsForEnumMap

import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
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();
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:21,代码来源:TestsForMapsInJavaUtil.java

示例7: testCompute_presentToAbsent

import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
@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());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:MapComputeTester.java

示例8: testPutDuplicateValue

import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:18,代码来源:SetMultimapPutTester.java

示例9: testPropagatesRemoveThenAddToMultimap

import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
@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());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:23,代码来源:MultimapAsMapGetTester.java

示例10: testMergePresentToNull

import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
@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());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:17,代码来源:MapMergeTester.java

示例11: testRemovePropagatesToGet

import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
@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));
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:21,代码来源:MultimapRemoveEntryTester.java

示例12: testsForUnmodifiableSortedMap

import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
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();
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:19,代码来源:TestsForMapsInJavaUtil.java

示例13: testMappedToNull

import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
@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()));
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:18,代码来源:MapMergeTester.java

示例14: testCompute_presentNullToPresentNonnull

import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
@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());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:21,代码来源:MapComputeTester.java

示例15: putDistinctKeysDistinctValues

import com.google.common.collect.testing.features.MapFeature; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(ZERO)
public void putDistinctKeysDistinctValues() {
  getMap().put(k0(), v0());
  getMap().put(k1(), v1());
  expectAdded(e0(), e1());
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:9,代码来源:BiMapPutTester.java


注:本文中的com.google.common.collect.testing.features.MapFeature类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。