ReadOnlyEnumerationMap implements Map<String, V> { @Override public int hashCode() { int retValue = 0; for (Enumeration<String> attribs = request.getKeys(); attribs .hasMoreElements();) { String parameterName = attribs.nextElement(); V value = request.getValue(parameterName); retValue += parameterName.hashCode() ^ (value == null ? 0 : value.hashCode()); } return retValue; } ReadOnlyEnumerationMap(HasKeys<V> request); void clear(); boolean containsKey(Object key); @SuppressWarnings("unchecked") boolean containsValue(Object value); Set<Map.Entry<String, V>> entrySet(); V get(Object key); boolean isEmpty(); Set<String> keySet(); V put(String key, V value); void putAll(Map<? extends String, ? extends V> map); V remove(Object key); int size(); Collection<V> values(); @SuppressWarnings("unchecked") @Override boolean equals(Object o); @Override int hashCode();  }
@SuppressWarnings("unchecked") @Test public void testHashCode() { Enumeration<String> keys = createMock(Enumeration.class); expect(extractor.getKeys()).andReturn(keys); expect(keys.hasMoreElements()).andReturn(true); expect(keys.nextElement()).andReturn("first"); expect(keys.hasMoreElements()).andReturn(true); expect(keys.nextElement()).andReturn("second"); expect(keys.hasMoreElements()).andReturn(false); Integer value1 = 1; expect(extractor.getValue("first")).andReturn(value1); expect(extractor.getValue("second")).andReturn(null); replay(extractor, keys); assertEquals(("first".hashCode() ^ value1.hashCode()) + ("second".hashCode() ^ 0), map.hashCode()); verify(extractor, keys); }