void (Map<Object, Object> map, @NotNull Runnable putKey) { assertTrue(map.isEmpty()); assertEquals(0, map.size()); putKey.run(); Object strong = new Object(); //noinspection SizeReplaceableByIsEmpty do { map.put(strong, strong); // to run processQueues(); assertFalse(map.isEmpty()); map.remove(strong); assertNull(map.get(strong)); GCUtil.tryGcSoftlyReachableObjects(() -> map.isEmpty()); } while (map.size() != 0); assertTrue(map.isEmpty()); assertEquals(0, map.size()); map.put(this, this); assertEquals(1, map.size()); map.clear(); assertEquals(0, map.size()); assertNull(map.get(strong)); }