Search in sources :

Example 1 with ALLOWS_NULL_KEYS

use of com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS in project guava by google.

the class MapComputeIfPresentTester method testComputeIfPresent_nullKeySupportedAbsent.

@MapFeature.Require({ SUPPORTS_PUT, ALLOWS_NULL_KEYS })
public void testComputeIfPresent_nullKeySupportedAbsent() {
    assertNull("computeIfPresent(null, function) should return null", getMap().computeIfPresent(null, (k, v) -> {
        throw new AssertionFailedError();
    }));
    expectUnchanged();
}
Also used : GwtCompatible(com.google.common.annotations.GwtCompatible) AbstractMapTester(com.google.common.collect.testing.AbstractMapTester) ZERO(com.google.common.collect.testing.features.CollectionSize.ZERO) Map(java.util.Map) Entry(java.util.Map.Entry) SUPPORTS_PUT(com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT) ALLOWS_NULL_VALUES(com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES) AssertionFailedError(junit.framework.AssertionFailedError) ALLOWS_NULL_KEYS(com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS) MapFeature(com.google.common.collect.testing.features.MapFeature) CollectionSize(com.google.common.collect.testing.features.CollectionSize) AssertionFailedError(junit.framework.AssertionFailedError)

Example 2 with ALLOWS_NULL_KEYS

use of com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS in project guava by google.

the class MapMergeTester method testMergeAbsentNullKey.

@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()));
}
Also used : AbstractMapTester(com.google.common.collect.testing.AbstractMapTester) ZERO(com.google.common.collect.testing.features.CollectionSize.ZERO) ALLOWS_NULL_VALUES(com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES) GwtIncompatible(com.google.common.annotations.GwtIncompatible) AssertionFailedError(junit.framework.AssertionFailedError) ALLOWS_NULL_KEYS(com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS) CollectionSize(com.google.common.collect.testing.features.CollectionSize) GwtCompatible(com.google.common.annotations.GwtCompatible) Helpers(com.google.common.collect.testing.Helpers) Map(java.util.Map) SUPPORTS_PUT(com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT) SUPPORTS_REMOVE(com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE) MapFeature(com.google.common.collect.testing.features.MapFeature) Method(java.lang.reflect.Method) AssertionFailedError(junit.framework.AssertionFailedError)

Aggregations

GwtCompatible (com.google.common.annotations.GwtCompatible)2 AbstractMapTester (com.google.common.collect.testing.AbstractMapTester)2 CollectionSize (com.google.common.collect.testing.features.CollectionSize)2 ZERO (com.google.common.collect.testing.features.CollectionSize.ZERO)2 MapFeature (com.google.common.collect.testing.features.MapFeature)2 ALLOWS_NULL_KEYS (com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS)2 ALLOWS_NULL_VALUES (com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES)2 SUPPORTS_PUT (com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT)2 Map (java.util.Map)2 AssertionFailedError (junit.framework.AssertionFailedError)2 GwtIncompatible (com.google.common.annotations.GwtIncompatible)1 Helpers (com.google.common.collect.testing.Helpers)1 SUPPORTS_REMOVE (com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE)1 Method (java.lang.reflect.Method)1 Entry (java.util.Map.Entry)1