ReadOnlyEnumerationMap implements Map<String, V> { @SuppressWarnings("unchecked") public boolean containsValue(Object value) { V realValue = (V) value; for (Enumeration<String> keysIt = request.getKeys(); keysIt.hasMoreElements();) { if (realValue.equals(request.getValue(keysIt.nextElement()))) { return true; } } return false; } 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 testContainsValue() { Enumeration<String> keys = 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.getValue("one")).andReturn(1); expect(extractor.getValue("two")).andReturn(2); replay(extractor, keys); assertTrue(map.containsValue(2)); verify(extractor, keys); }
@SuppressWarnings("unchecked") @Test public void testContainsValueFalse() { Enumeration<String> keys = 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.getValue("one")).andReturn(1); expect(extractor.getValue("two")).andReturn(1); replay(extractor, keys); assertFalse(map.containsValue(3)); verify(extractor, keys); }