Last active
April 24, 2025 10:42
-
-
Save kevinhooke/da53ba36f9e3755a664097236c96b74b to your computer and use it in GitHub Desktop.
Mocking static methods with Mockito
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# No longer need to use Powermock to mock statics, this is now supported in Mockito with .mockStatic() | |
# Alternative approach to https://gist.github.com/kevinhooke/b4035faa5f2c215e8166936a44db4fa3 | |
# Requires mockito-inline dependency instead of mockito-core | |
try (MockedStatic<ClassToMock> mock = Mockito.mockStatic(ClassToMock.class)) { | |
mock.when(ClassToMock::staticMethod).thenReturn(mockedReturn); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment