Skip to content

Instantly share code, notes, and snippets.

@jieniu
Created January 10, 2019 07:04
Show Gist options
  • Save jieniu/23ea51e6bf55fcee495c68015438ae87 to your computer and use it in GitHub Desktop.
Save jieniu/23ea51e6bf55fcee495c68015438ae87 to your computer and use it in GitHub Desktop.
power mock static
@RunWith(PowerMockRunner.class)
@PrepareForTest(DriverManager.class)
public class Mocker {
@Test
public void testName() throws Exception {
//given
PowerMockito.mockStatic(DriverManager.class);
BDDMockito.given(DriverManager.getConnection(...)).willReturn(...);
//when
sut.execute();
//then
PowerMockito.verifyStatic();
DriverManager.getConnection(...);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment