In my MQ application, the flow of the program is Route class -> Service class -> DAO class. In the service class, I have used an objectMapper to register time module in an init method annotated with @PostConstruct as follows :
@PostConstruct
public void init() {
mapper.registerModule(new JavaTimeModule())
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}
But while testing the service class with JUnit 5, I have mocked the DAO class and used @InjectMocks for the service class. But, the registration of time module which I had done in the method annotated with @PostConstruct is not loaded to the test class.
I tried two ways :
- Using @PostConstruct in test class for registering time module.
- Registering time module in @BeforeEach method.
Both don't seem to work. Is there a way to bring in the time registration in service class to the JUnit or a way to implement the @PostConstruct from service class to the test class?