You can try removing the @EventListener from the initialization function and replacing it with a @PostConstruct
@PostConstruct
public void init() {
startup();
}
This way, you can change the functioning of the initialization function without changing the functioning of the ManagementService
@BeforeEach
public void preventConnection() {
Mockito.doNothing().when(temp).print();
}