What is the scope of MockedStatic?

Viewed 65

I was looking for solution on mocking static classes and I found one here https://asolntsev.github.io/en/2020/07/11/mockito-static-methods/

It looks very neat to be honest but the question is if it will work with parallel tests. To clarify lets assume I have two tests that use this mocking below, is this mocking test scope or global?

@Test
void lookMomICanMockStaticMethods() {
  assertThat(Buddy.name()).isEqualTo("John");

  try (MockedStatic<Buddy> theMock = Mockito.mockStatic(Buddy.class)) {
    theMock.when(Buddy::name).thenReturn("Rafael");
    assertThat(Buddy.name()).isEqualTo("Rafael");
  }

  assertThat(Buddy.name()).isEqualTo("John");
}
0 Answers
Related