title: How to mock static method calls from multiple classes in a single try block using Mockito?
body: <p>I want to mock static methods from two different classes. Right now, my code is like this:</p>
  <pre><code>try(MockedStatic&lt;ObjectFactory&gt; objectFactory = mockStatic(ObjectFactory.class)){
      objectFactory.when(() -&gt; ObjectFactory.getObject(Provider.class)).thenReturn(new Provider());
      .....
  }
  </code></pre>
  <p>I want to mock another static method call from <code>Context.class</code>. Is there a way to define a <code>MockedStatic</code> object of context in the same try block, without using a nested try block.</p>
  <p>Without using try block I think we can use something like this</p>
  <pre><code>MockedStatic&lt;ObjectFactory&gt; objectFactory = mockStatic(ObjectFactory.class);
  MockedStatic&lt;Context&gt; contextMock = mockStatic(Context.class);
  ......
  objectFactory.close();
  contextMock.close();
  </code></pre>
  <p>but if the test throws exception, the mocks will not be closed and other tests that use the mock will throw an exception.</p>