Search in sources :

Example 1 with ZERO

use of com.google.common.collect.testing.features.CollectionSize.ZERO 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 ZERO

use of com.google.common.collect.testing.features.CollectionSize.ZERO 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)

Example 3 with ZERO

use of com.google.common.collect.testing.features.CollectionSize.ZERO in project guava by google.

the class MapComputeIfAbsentTester method testComputeIfAbsent_supportedPresent.

@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testComputeIfAbsent_supportedPresent() {
    assertEquals("computeIfAbsent(present, function) should return existing value", v0(), getMap().computeIfAbsent(k0(), k -> {
        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) 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)

Aggregations

GwtCompatible (com.google.common.annotations.GwtCompatible)3 AbstractMapTester (com.google.common.collect.testing.AbstractMapTester)3 CollectionSize (com.google.common.collect.testing.features.CollectionSize)3 ZERO (com.google.common.collect.testing.features.CollectionSize.ZERO)3 MapFeature (com.google.common.collect.testing.features.MapFeature)3 ALLOWS_NULL_KEYS (com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS)3 ALLOWS_NULL_VALUES (com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES)3 SUPPORTS_PUT (com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT)3 Map (java.util.Map)3 AssertionFailedError (junit.framework.AssertionFailedError)3 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