title: How to stub private methods of class under test by Mockito
body: <p>Say we have java class called SomeClass</p>
  
  <pre><code>public class SomeClass {
  
      private boolean isMethod() {
  
          return false;
      }
  
      public void sendRequest(String json, String text) {
  
          int messageId;
  
          if (isMethod()) {
              messageId = getMessageId(json);
              sendMessage(messageId, text);
          } else {
              throw new IllegalArgumentException();
          }
      }
  
      private void sendMessage(int messageId, String text) {
  
      }
  
      private int getMessageId(String text) {
  
          Pattern p = Pattern.compile("messageId=(\\d+)&amp;");
          Matcher m = p.matcher(text);
  
          if (m.find()) {
              return Integer.valueOf(m.group(1));
          }
          return 0;
      }
  }
  </code></pre>
  
  <p>Don't pay attention to methods' name, they're all optional.</p>
  
  <ul>
  <li>I want to test <code>sendRequest(String json, String text)</code> method in isolation.</li>
  <li>I want to stub methods <code>isMethod()</code> and <code>getMessageId(json)</code>, and verify that <code>sendMessage(messageId, text)</code> method is called. </li>
  <li>I need to be sure that <code>getMessageId(json)</code> returns 25 and that <code>isMethod()</code> returns true no matter which argument value given.</li>
  </ul>