jhalterman / expiringmap

A high performance thread-safe map that expires entries
Apache License 2.0
1k stars 142 forks source link

Failures in Guava's MapTestSuiteBuilder suite #48

Open ben-manes opened 7 years ago

ben-manes commented 7 years ago

It appears that there are some small coverage mistakes that break the Map contract. Guava's testlib provides a nice way to perform a deep validation in a pluggable manner. In the following configuration there are 7 errors and 40 failures (many are duplicates at different population counts).

For example, testPutAll_nullKeyUnsupported fails due to putAll delegating to putInternal which does not perform a null key check. Instead it could delegate to any of the put(...) methods which includes it.

public final class ExpiringMapTest {

  public static Test suite() throws Exception {
    TestSuite suite = new TestSuite();
    suite.addTest(ExpiringMapTest.suite("ExpiringMap", () -> {
      return ExpiringMap.builder().build();
    }));
    return suite;
  }

  private static Test suite(String name, Supplier<Map<String, String>> supplier) {
    return MapTestSuiteBuilder
        .using(new TestStringMapGenerator() {
          @Override protected Map<String, String> create(Entry<String, String>[] entries) {
            Map<String, String> map = supplier.get();
            for (Entry<String, String> entry : entries) {
              map.put(entry.getKey(), entry.getValue());
            }
            return map;
          }
        })
        .named(name)
        .withFeatures(
            MapFeature.GENERAL_PURPOSE,
            MapFeature.ALLOWS_NULL_ENTRY_QUERIES,
            MapFeature.ALLOWS_NULL_VALUES,
            CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
            CollectionSize.ANY)
        .createTestSuite();
  }
}