HashMap extends AbstractMap<K, V> implements Map<K, V> { public Set<K> keySet() { return new KeySet(); } HashMap();  HashMap(int capacity);  HashMap(int capacity, float loadFactor); int size(); boolean isEmpty(); void clear(); V get(final Object key); V put(final K key, final @NotNull V value); boolean containsKey(final Object key); V remove(final Object key); Set<K> keySet(); Collection<V> values(); Set<Map.Entry<K, V>> entrySet();  }
@Test public void keySet() { final HashMap<Integer, String> tested = new HashMap<Integer, String>(); final Set<Integer> set = new HashSet<Integer>(); for (int i = 0; i < 10000; ++i) { tested.put(i, Integer.toString(i)); set.add(i); } for (Integer key : tested.keySet()) { Assert.assertTrue(set.remove(key)); } Assert.assertEquals(0, set.size()); }