title: How to deal with org.mockito.exceptions.misusing.MissingMethodInvocationException?
body: <p>I have a class that looks like  </p>
  
  <pre><code>@Stateless
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public class ClientRegistrationManager {
      private CrudService crudService;
      private UniqueIdGenerator uniqueIdGenerator;
  
      @SuppressWarnings("UnusedDeclaration")
      public ClientRegistrationManager() {
      }
  
      @Inject
      public ClientRegistrationManager(@Nonnull final CrudService crudService, @Nonnull final UniqueIdGenerator uniqueIdGenerator) {
          this.crudService = crudService;
          this.uniqueIdGenerator = uniqueIdGenerator;
      }
  
      public Member register(@Nonnull final String email, @Nonnull final String userExternalId, @Nonnull final String password) {
          final Member existingMember;
          try {
              existingMember = getMemberQueries().getMemberByEmail(email);
          } catch (final NoResultException e) {
              return createNewMemberAndGetClientDetail(email, userExternalId);
          }
          return existingMember;
      }
  
      ...
  
      @Nonnull
      protected MemberQueries getMemberQueries() {
          return new MemberQueries(crudService);
      }
  }
  </code></pre>
  
  <p>I wanted to test it by mocking out any external behavior, so I created <code>getMemberQueries()</code> using Pattern - 1 described in <a href="https://code.google.com/p/mockito/wiki/MockingObjectCreation" rel="nofollow">doc</a>  </p>
  
  <p>I, then write my test as following  </p>
  
  <pre><code>public class ClientRegistrationManagerTest {
  
      @Mock
      private MemberQueries memberQueries;
  
      @Mock
      private CrudService crudService;
  
      @Mock
      private UniqueIdGenerator uniqueIdGenerator;
  
      @Before
      public void setUp() {
          MockitoAnnotations.initMocks(this);
      }
  
      @Test
      public void testMockedMemberQueries() {
          final ClientRegistrationManager clientRegistrationManager = new ClientRegistrationManager(crudService, uniqueIdGenerator);
          Mockito.when(clientRegistrationManager.getMemberQueries()).thenReturn(memberQueries);
          clientRegistrationManager.getMemberQueries();
          assertTrue(true);
      }
  }
  </code></pre>
  
  <p>When I run this, I get the error as  </p>
  
  <pre><code>org.mockito.exceptions.misusing.MissingMethodInvocationException: 
  when() requires an argument which has to be 'a method call on a mock'.
  For example:
      when(mock.getArticles()).thenReturn(articles);
  
  Also, this error might show up because:
  1. you stub either of: final/private/equals()/hashCode() methods.
     Those methods *cannot* be stubbed/verified.
  2. inside when() you don't call method on mock but on some other object.
  3. the parent of the mocked class is not public.
     It is a limitation of the mock engine.
  </code></pre>
  
  <p>Now what it means I need to mock out the entire <code>ClientRegistrationManager</code>, but that the class I want to test, I can not just mock that entire class.  </p>
  
  <p>I am trying to understand my options here, I really do not want to depend on <code>persistence</code> layer, that will be too heavy</p>