Search in sources :

Example 1 with SUPPORTS_PUT

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

use of com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT 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 3 with SUPPORTS_PUT

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

the class MapComputeIfPresentTester method testComputeIfPresent_supportedAbsent.

@MapFeature.Require(SUPPORTS_PUT)
public void testComputeIfPresent_supportedAbsent() {
    assertNull("computeIfPresent(notPresent, function) should return null", getMap().computeIfPresent(k3(), (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 4 with SUPPORTS_PUT

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

the class MapMergeTester method testAbsent.

@MapFeature.Require(SUPPORTS_PUT)
public void testAbsent() {
    assertEquals("Map.merge(absent, value, function) should return value", v3(), getMap().merge(k3(), v3(), (oldV, newV) -> {
        throw new AssertionFailedError("Should not call merge function if key was absent");
    }));
    expectAdded(e3());
}
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 5 with SUPPORTS_PUT

use of com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT 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)7 AbstractMapTester (com.google.common.collect.testing.AbstractMapTester)7 CollectionSize (com.google.common.collect.testing.features.CollectionSize)7 ZERO (com.google.common.collect.testing.features.CollectionSize.ZERO)7 MapFeature (com.google.common.collect.testing.features.MapFeature)7 ALLOWS_NULL_KEYS (com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS)7 ALLOWS_NULL_VALUES (com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES)7 SUPPORTS_PUT (com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT)7 Map (java.util.Map)7 AssertionFailedError (junit.framework.AssertionFailedError)7 GwtIncompatible (com.google.common.annotations.GwtIncompatible)3 Helpers (com.google.common.collect.testing.Helpers)3 SUPPORTS_REMOVE (com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE)3 Method (java.lang.reflect.Method)3 Entry (java.util.Map.Entry)3