HeaderValuesMap implements Map<String, String[]> { @Override public int hashCode() { int retValue = 0; for (Enumeration<String> attribs = request.getKeys(); attribs .hasMoreElements();) { String parameterName = attribs.nextElement(); Enumeration<String> values = request.getValues(parameterName); int valueHash = 0; while (values.hasMoreElements()) { valueHash += values.nextElement().hashCode(); } retValue += parameterName.hashCode() ^ valueHash; } return retValue; } HeaderValuesMap(EnumeratedValuesExtractor request); void clear(); boolean containsKey(Object key); boolean containsValue(Object value); Set<Map.Entry<String, String[]>> entrySet(); @Override boolean equals(Object o); String[] get(Object key); @Override int hashCode(); boolean isEmpty(); Set<String> keySet(); String[] put(String key, String[] value); void putAll(Map<? extends String, ? extends String[]> map); String[] remove(Object key); int size(); Collection<String[]> values();  }
@SuppressWarnings("unchecked") @Test public void testHashCode() { Enumeration<String> keys = createMock(Enumeration.class); Enumeration<String> values1 = createMock(Enumeration.class); Enumeration<String> values2 = createMock(Enumeration.class); expect(extractor.getKeys()).andReturn(keys); expect(keys.hasMoreElements()).andReturn(true); expect(keys.nextElement()).andReturn("one"); expect(keys.hasMoreElements()).andReturn(true); expect(keys.nextElement()).andReturn("two"); expect(keys.hasMoreElements()).andReturn(false); expect(extractor.getValues("one")).andReturn(values1); expect(values1.hasMoreElements()).andReturn(true); expect(values1.nextElement()).andReturn("value1"); expect(values1.hasMoreElements()).andReturn(false); expect(extractor.getValues("two")).andReturn(values2); expect(values2.hasMoreElements()).andReturn(true); expect(values2.nextElement()).andReturn("value2"); expect(values2.hasMoreElements()).andReturn(true); expect(values2.nextElement()).andReturn("value3"); expect(values2.hasMoreElements()).andReturn(false); replay(extractor, keys, values1, values2); assertEquals( ("one".hashCode() ^ "value1".hashCode()) + ("two".hashCode() ^ ("value2".hashCode() + "value3" .hashCode())), map.hashCode()); verify(extractor, keys, values1, values2); }