Search in sources :

Example 1 with ALLOWS_NULL_VALUES

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

the class MapComputeIfPresentTester method testComputeIfPresent_nullTreatedAsAbsent.

@MapFeature.Require({ SUPPORTS_PUT, ALLOWS_NULL_VALUES })
@CollectionSize.Require(absent = ZERO)
public void testComputeIfPresent_nullTreatedAsAbsent() {
    initMapWithNullValue();
    assertNull("computeIfPresent(presentAssignedToNull, function) should return null", getMap().computeIfPresent(getKeyForNullValue(), (k, v) -> {
        throw new AssertionFailedError();
    }));
    expectReplacement(entry(getKeyForNullValue(), null));
}
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_VALUES

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

the class MapMergeTester method testMappedToNull.

@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()));
}
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