title: Writing unit test for Map injection in Guice
body: <p>I am new to Guice. I have written following class that depends on generic map which is managerMap that maps object type to specific manager responsible for handling that type of object.</p>
  
  <pre><code>public class MyClass&lt;T extends MyClass&gt; {
  
      @Inject
      @Named("ManagerMap")
      private Map&lt;String, Manager&gt; managerMap;
  
      @Override
      public void myFunc(@NotNull T myObj) {
          Manager manager = managerMap.get(myObj.getClass().getName());
          manager.call(myObj);
      }
  }
  </code></pre>
  
  <p>Above code is running fine. Now I would like to write unit test for above. I have written like following, it is working, but I think there is a better way to do that.</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  public class MyClassTest {
  
      @InjectMocks
      private MyClass myclass;
  
      @Mock
      private Map&lt;String, Manager&gt; managerMap;
  
      private final MyClass1 myObj;     &lt;--MyClass1 extends from MyClass
  
      @Test
      public void testmyFunc() {
          Mockito.when(managerMap.get(myObj.getClass().getName())).thenReturn(new MyManager1());
          myclass.myFunc(myObj);
      }
  }
  </code></pre>