title: Mock a class initialised by a static method
body: <p>I have the following class which has an object 'client' which is initialized by a static method.
  I do not want to use Powermock and let it get initialized by this static method.
  I am looking to use mockito to mock the this call =&gt; client.rxQueryWithParams().</p>
  <p>Is this possible? Tried with the mock up as follows but I still enter the client.rxQueryWithParams() call
  thus the mockup is not taking effect.</p>
  <p>This would have mocked fine it I had just Autowired the SQLClient instead in a framework like Spring. Unable to achieve this
  in a normal class as follows. If relevant, I am ok to mock that PostgreSQLClient.createShared() call but it doesn't seem to be achievable via mockito
  and not looking to introduce Powermock as mentioned. Is there a way around this? Thanks.</p>
  <pre><code>public class MainClass{
      private final SQLClient client;
  
      public MainClass(Vertx vertx, JsonObject config) {
          client = PostgreSQLClient.createShared(vertx, getData(config));
      }
  
      Single&lt;ResultSet&gt; insert(AddEventRequest request) {
          // some logic 
          return client.rxQueryWithParams(query, new JsonArray(params)); // I want to mock out this call. 
      }
  }
  </code></pre>
  <p>Test</p>
  <pre><code>@ExtendWith(MockitoExtension.class)
  public class MainClassTest {
  
      private TestSubscriber&lt;Response&gt; subscriber;
      private JsonObject configuration;
      private MainClass event;
  
      @Mock
      private SQLClient client;
  
      @BeforeEach
      public void init() {
          configuration = SomeStaticMethod.load();
          event = new MainClass(Vertx.vertx(), configuration);
          subscriber = new TestSubscriber&lt;&gt;();
      }
  
      @Test
      public void test() {
          Request request = getRequest(); // just a method creating an object with some values
          
          // this mock doesn't have any effect
          when(client.rxQueryWithParams(anyString(), any(JsonArray.class))).thenThrow(new RuntimeException());
  
          event.addEvent(request).subscribe(subscriber);
          subscriber.assertCompleted();
          subscriber.assertNoErrors();
      }
  }
  </code></pre>