title: Unit test static method with dependency
body: <p>I have not much experience in unit testing, especially with Mockito and now I have encountered the following situation.</p>
  
  <pre><code>class A {
  
      void setField(String obj) {
      }
  
      Object execute() {
          throw new RuntimeException("Meh!");
      }
  
  }
  </code></pre>
  
  <hr/>
  
  <pre><code>class B {
      //function to be tested
      static Object someMethod() {
  
          A a = new A();
          a.setField("test");
          Object response = a.execute();
          //logic here
  
          return response;
      }
  }
  </code></pre>
  
  <hr/>
  
  <pre><code>class BTest() {
  
     A aInstance = mock(A.class);
  
     @Test
     public void test_someMethod_when_exec_returns_X() {
        when(aInstance.execute()).thenReturns("X");// doesn’t work
        assertTrue("X", B.someMethod());
     }
  }
  </code></pre>
  
  <p>I want to test the someMethod static method when a.execute() returns specific value. 
  I know, I can create a mock object of A and pass it to someMethod function, which is not a good solution as I should change the signature of someMethod. </p>
  
  <p>What is the correct solution in this case?</p>