• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.hamcrest.collection;
2 
3 
4 import org.hamcrest.AbstractMatcherTest;
5 import org.hamcrest.Matcher;
6 
7 import java.util.HashMap;
8 import java.util.Map;
9 import java.util.TreeMap;
10 
11 import static org.hamcrest.collection.IsMapContaining.hasValue;
12 
13 public class IsMapContainingValueTest extends AbstractMatcherTest {
14 
15     @Override
createMatcher()16     protected Matcher<?> createMatcher() {
17         return hasValue("foo");
18     }
19 
testHasReadableDescription()20     public void testHasReadableDescription() {
21         assertDescription("map containing [ANYTHING->\"a\"]", hasValue("a"));
22     }
23 
testDoesNotMatchEmptyMap()24     public void testDoesNotMatchEmptyMap() {
25         Map<String,Integer> map = new HashMap<String,Integer>();
26         assertMismatchDescription("map was []", hasValue(1), map);
27     }
28 
testMatchesSingletonMapContainingValue()29     public void testMatchesSingletonMapContainingValue() {
30         Map<String,Integer> map = new HashMap<String,Integer>();
31         map.put("a", 1);
32 
33         assertMatches("Singleton map", hasValue(1), map);
34     }
35 
testMatchesMapContainingValue()36     public void testMatchesMapContainingValue() {
37         Map<String,Integer> map = new TreeMap<String,Integer>();
38         map.put("a", 1);
39         map.put("b", 2);
40         map.put("c", 3);
41 
42         assertMatches("hasValue 1", hasValue(1), map);
43         assertMatches("hasValue 3", hasValue(3), map);
44         assertMismatchDescription("map was [<a=1>, <b=2>, <c=3>]", hasValue(4), map);
45     }
46 }
47