title: How to get elements from Map when it is mocked
body: <p>I'm unable to verify whether object exists in mocked map and also unable to verify whether register() is called on that object.
  Below are the errors thrown in the test</p>
  
  <pre><code>Assert.assertNotNull(locationDataMonitor); //Throws assertionError
  Mockito.verify(locationDataMonitor, Mockito.times(1)).register()); //org.mockito.exceptions.misusing.NullInsteadOfMockException: 
  </code></pre>
  
  <p>Implementation</p>
  
  <pre><code>public class DataAcquisitionService {
  
    private Map&lt;String, IDataMonitor&gt; dataMonitors;
  
    public DataAcquisitionService (...) {
       this.dataMonitors = new ConcurrentHashMap&lt;&gt;();
    } 
  
    public void doSomething(String id) {      
      IDataMonitor dataMonitor = null;
      if (this.dataMonitors.containsKey(locationId)) {
          dataMonitor = this.dataMonitors.get(locationId);
          dataMonitor.register();
      }
    }
  }
  </code></pre>
  
  <p>Test</p>
  
  <pre><code>@RunWith(PowerMockRunner.class)
  public class DataAcquisitionServiceTest {
      @Mock
      private Map&lt;String, IDataMonitor&gt; dataMonitors;
  
      @Before
      public void setUp() {   
         MockitoAnnotations.initMocks(this);  
         locationDataMonitors = Mockito.mock(ConcurrentHashMap.class);    
         this.target = new DataAcquisitionService(..);
     }
  
     @Test
     public void test_doSomething() { 
         String id = "id1";   
         this.target.doSomething(id);
         IDataMonitor locationDataMonitor = this.dataMonitors.get(id)
         Assert.assertNotNull(locationDataMonitor);
         Mockito.verify(locationDataMonitor, Mockito.times(1)).register();  
     }
  }
  </code></pre>