HeaderValuesMap implements Map<String, String[]> { public boolean containsValue(Object value) { if (!(value instanceof String[])) { return (false); } String[] test = (String[]) value; Enumeration<String> names = request.getKeys(); while (names.hasMoreElements()) { String name = names.nextElement(); if (compareHeaders(name, array2set(test))) { return true; } } return false; } 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 testContainsValue() { assertFalse(map.containsValue(1)); 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(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); assertTrue(map.containsValue(new String[] {"value2", "value3"})); verify(extractor, keys, values1, values2); }
@SuppressWarnings("unchecked") @Test public void testContainsValueFalse() { 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); assertFalse(map.containsValue(new String[] {"value2", "value4"})); verify(extractor, keys, values1, values2); }