Ik this is late but for the 2nd part of your question, you can add the
objectFactory.close();
contextMock.close();
in the @AfterAll or @AfterEach method which tears down the test
@AfterEach
public void teardown() {
objectFactory.close();
contextMock.close();
}
This will ensure even if an exception occurs, the mocks are closed or de-registered properly.