title: How to mock the return value of a Map?
body: <p>I have code that looks like so:</p>
  
  <pre><code>for (Map.Entry&lt;Integer, Action&gt; entry : availableActions.entrySet()) {
    ...
  }
  </code></pre>
  
  <p>I've tried to mock it like this:</p>
  
  <pre><code>Map mockAvailableActions = mock(Map.class, Mockito.RETURNS_DEEP_STUBS);
  mockAvailableActions.put(new Integer(1), mockAction);
  </code></pre>
  
  <p>I would think that would be enough. But entrySet is empty. So I added this:</p>
  
  <pre><code>when(mockAvailableActions.entrySet().iterator()).thenReturn(mockIterator);
  when(mockIterator.next()).thenReturn(mockAction);
  </code></pre>
  
  <p>Still entrySet is empty. What am I doing wrong? Thanks for any input!</p>