title: Mocking private method of class under test using JMockit
body: <p>I want to mock private method of a class under test but method return false first two times when the method is called after that it should return false.
  Here is the code what I tried.
  This is the class which is being tested</p>
  
  <pre><code>public class ClassToTest 
  {
      public void methodToTest()
      {
          Integer integerInstance = new Integer(0);
          boolean returnValue= methodToMock(integerInstance);
          if(returnValue)
          {
              System.out.println("methodToMock returned true");
          }
          else
          {
              System.out.println("methodToMock returned true");
          }
          System.out.println();
      }
      private boolean methodToMock(int value)
      {
          return true;
      }
  }
  </code></pre>
  
  <p>Test class</p>
  
  <pre><code>import org.junit.Test;
  import static mockit.Deencapsulation.*;
  
  import mockit.*;
  public class TestAClass 
  {
      @Tested ClassToTest classToTestInstance;
      @Test
      public void test1()
      {
  
          new NonStrictExpectations(classToTestInstance)
          {
              {
                  invoke(classToTestInstance, "methodToMock", anyInt);
                  returns(false);
                  times = 2;
  
                  invoke(classToTestInstance, "methodToMock", anyInt);
                  returns(true);
                  times = 1;
  
              }
          };
  
          classToTestInstance.methodToTest();
          classToTestInstance.methodToTest();
          classToTestInstance.methodToTest();
  
      }
  }
  </code></pre>
  
  <p>I did this to get desired results</p>
  
  <pre><code>    final StringBuffer count = new StringBuffer("0");
      new NonStrictExpectations(classToTestInstance)
      {
  
          {
              invoke(classToTestInstance, "methodToMock", anyInt);
              result= new Delegate() 
              {
                  boolean methodToMock(int value)
                  {                   
                      count.replace(0, count.length(), Integer.valueOf(Integer.valueOf(count.toString())+1).toString());
                      if(Integer.valueOf(count.toString())==3)
                      {
                          return true;
                      }
                      return false;
                  }
              };
  
          }
      };
  </code></pre>