I am not able to mock StreamBridge in my Unit Tests.
@MockBean
private StreamBridge bridge;
I get an IllegalStateException due to:
Caused by: org.mockito.exceptions.base.MockitoException: Cannot mock/spy class org.springframework.cloud.stream.function.StreamBridge Mockito cannot mock/spy because :
StreamBridge is a final class, With Mockito2 we can mock the final class, but by default this feature is disabled and that need to enable with below steps:
Create a directory ‘mockito-extensions’ in src/test/resources/ folder.
Create a file ‘org.mockito.plugins.MockMaker’ in ‘src/test/resources/mockito-extensions/’ directory.
Write the content 'mock-maker-inline' in org.mockito.plugins.MockMaker file.
At test class level use ‘@ExtendWith(MockitoExtension.class)’
Then StreamBridge will be mocked successfully.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With