title: Mock method in junit test
body: <p>I have to make some jUnit tests (with mocks) for some methods and I can't change the source code. Is there any possibility to change the behavior of a function (with mocks maybe) without change source code?</p>
  
  <p>Look a straight-forward example:
  Class <code>A</code> and <code>B</code> are source code (can't change them). I want to change behavior of <code>run()</code> method from <code>A</code> when I call it in <code>B</code>. Any ideas?</p>
  
  <pre><code>public class A {
      public String run(){
          return "test";
      }
  }
  
  public class B extends A {
      public void testing() {
          String fromA = run(); //I want a mocked result here
          System.out.println(fromA);
      }
  }
  
  public class C {
      B mockB = null;
  
      @Test
      public void jUnitTest() {
          mockB = Mockito.mock(B.class);
  
          // And here i want to call testing method from B but with a "mock return" from run()         
      }
  }
  </code></pre>