Preview:
@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");
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter