title: How to override a method in unit tests that is called from which the class being tested
body: <p>I am testing a class A's function func1.</p>
  
  <p>Func1 has a local variable of Class B and calls B's function func2. Code looks something like this:</p>
  
  <pre><code>public Class A
  {
      public func1()
      {
         B object = new B();
         int x = object.func2(something);
      }
  }
  </code></pre>
  
  <p>When I am testing func1 in its unit tests, I don't want func2 to get called.</p>
  
  <p>So I am trying to do something like this in the test:</p>
  
  <pre><code>B textObject = new B()
  {
     @override
     int func2(something)
     {
        return 5;
     }
  }
  </code></pre>
  
  <p>But it is still calling the func2 in the class B. Please suggest how to handle this.</p>