title: How to mock a map in mockito?
body: <p>I have two maps that have the same arguments. I would like to mock one of them to test my class. But I don't know a reason that it's not  working</p>
  
  <p>this is my class </p>
  
  <pre><code>public class A {
      private Map&lt;String, Foo&gt; map1;
      private Map&lt;String, Foo&gt; map2;
  
      public A() { 
         this.map1 = new HashMap&lt;String,Foo&gt;();
         map1.put("one",new Foo());
  
         this.map2 = new HashMap&lt;String, Foo&gt;();
         map2.put("two", new Foo());
      }
  
      public void doSomenthing(String str){
          Foo foo = map1.get(str)
          //other actions
      }
  
  }
  </code></pre>
  
  <p>and this is my test class:</p>
  
  <pre><code>public class ATest{
  
      @InjectMocks
      private A a;
  
      @Mock
      private  HashMap&lt;String, Foo&gt; mapTest;
  
      @Before
      public void initialize() throws Exception {
          when(mapTest.get(Mockito.anyString())).thenReturn(new Foo());
      }
  
      @Test
  public void testSomething() throws Exception {
         a.doSomething("blabla");
      }
  }
  </code></pre>