A quick sanity test of this map using Guava's testlib found some simple violations. For example entrySet().iterator() does not throw an exception for the sequence [hasNext, hasNext, next, remove, remove]. In this case Iterator.remove() failed to null out the last property after the first call, so a subsequent call does not throw an IllegalStateException. As the keySet and values views delegate to entrySet, this error is found multiple times in Guava's suite. You might consider using this suite on other custom collections.
Unit Tests
import java.util.Map;
import org.springframework.util.ConcurrentReferenceHashMap;
import com.google.common.collect.testing.ConcurrentMapTestSuiteBuilder;
import com.google.common.collect.testing.TestStringMapGenerator;
import com.google.common.collect.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
import com.google.common.collect.testing.features.MapFeature;
import junit.framework.Test;
import junit.framework.TestCase;
/** Guava testlib map tests. */
public final class ConcurrentReferenceHashMapTests extends TestCase {
public static Test suite() {
var suite = ConcurrentMapTestSuiteBuilder
.using(new TestStringMapGenerator() {
@Override protected Map<String, String> create(Map.Entry<String, String>[] entries) {
var map = new ConcurrentReferenceHashMap<String, String>();
for (var entry : entries) {
map.put(entry.getKey(), entry.getValue());
}
return map;
}
})
.named("ConcurrentReferenceHashMap")
.withFeatures(
MapFeature.GENERAL_PURPOSE,
MapFeature.ALLOWS_ANY_NULL_QUERIES,
CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
CollectionSize.ANY);
return suite.createTestSuite();
}
}
A quick sanity test of this map using Guava's testlib found some simple violations. For example
entrySet().iterator()does not throw an exception for the sequence [hasNext, hasNext, next, remove, remove]. In this caseIterator.remove()failed to null out thelastproperty after the first call, so a subsequent call does not throw anIllegalStateException. As thekeySetandvaluesviews delegate toentrySet, this error is found multiple times in Guava's suite. You might consider using this suite on other custom collections.Unit Tests