Closed as not planned
Description
Problems:
When mocking org.springframework.context.MessageSource
, it will execute real method instead of mocked behavior.
org.springframework.context.NoSuchMessageException: No message found under code 'billing.cycle.created' for locale 'en_ID'.
at org.springframework.context.support.DelegatingMessageSource.getMessage(DelegatingMessageSource.java:76)
Steps to reproduce:
- Have a service class that include
MessageSource
as a bean. - Create a test class for that service class.
- Use
SpringExtension
- Mock all dependencies using
MockBean
- Mock the behavior of the method
getMessage
usingMockito.when
- Use
- Run the test.
Actual: throw exception and it seems to call real method.
Expected: no exception and returns the output specified via Mockito
Can use this code as a reference: https://github.com/andreasarf/simple-billing-engine/pull/1/files
NOTE: I have tried using the latest version of Spring Boot which uses MockitoBean
and the faulty behavior is still there.
Details:
- Spring Boot 3.3.4
- Java 21