HeaderValuesMap implements Map<String, String[]> { @Override public boolean equals(Object o) { EnumeratedValuesExtractor otherRequest = ((HeaderValuesMap) o).request; boolean retValue = true; for (Enumeration<String> attribs = request.getKeys(); attribs .hasMoreElements() && retValue;) { String parameterName = attribs.nextElement(); Set<String> valueSet = enumeration2set(otherRequest.getValues(parameterName)); retValue = compareHeaders(parameterName, valueSet); } 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 testEqualsObject() { Enumeration<String> keys = createMock(Enumeration.class); Enumeration<String> values1 = createMock(Enumeration.class); Enumeration<String> values2 = createMock(Enumeration.class); EnumeratedValuesExtractor otherExtractor = createMock(EnumeratedValuesExtractor.class); Enumeration<String> otherValues1 = createMock(Enumeration.class); Enumeration<String> otherValues2 = 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); expect(otherExtractor.getValues("one")).andReturn(otherValues1); expect(otherValues1.hasMoreElements()).andReturn(true); expect(otherValues1.nextElement()).andReturn("value1"); expect(otherValues1.hasMoreElements()).andReturn(false); expect(otherExtractor.getValues("two")).andReturn(otherValues2); expect(otherValues2.hasMoreElements()).andReturn(true); expect(otherValues2.nextElement()).andReturn("value2"); expect(otherValues2.hasMoreElements()).andReturn(true); expect(otherValues2.nextElement()).andReturn("value3"); expect(otherValues2.hasMoreElements()).andReturn(false); replay(extractor, otherExtractor, keys, values1, values2, otherValues1, otherValues2); HeaderValuesMap otherMap = new HeaderValuesMap(otherExtractor); assertTrue(map.equals(otherMap)); verify(extractor, otherExtractor, keys, values1, values2, otherValues1, otherValues2); }