HashMap extends AbstractMap<K, V> implements Map<K, V> { @NotNull @Override public Set<K> keySet() { return new KeySet(); } HashMap();  HashMap(int capacity);  HashMap(int capacity, float loadFactor); @Override int size(); @Override boolean isEmpty(); @Override void clear(); @Override V get(final Object key); @Override V put(final K key, @NotNull final V value); @Override boolean containsKey(final Object key); @Override V remove(final Object key); @NotNull @Override Set<K> keySet(); @NotNull @Override Collection<V> values(); @NotNull @Override 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()); }