У меня есть служба с аннотацией @Scheduled, и я пытаюсь ее протестировать.
@Slf4j
@Service
public class CreatorService {
private final MyService myService;
public CreatorService(MyService myService) {
this.myService= myService;
}
@PostConstruct
@Scheduled(cron = "${test.cron.expression}")
public void initAndCheckTimers() {
myService.goToDb();
}
}
и я написал модульный тест для этой службы
@RunWith(MockitoJUnitRunner.class)
@PropertySource("classpath:application-default-test.properties")
@EnableScheduling
public class AlertsSchedulerCreatorServiceTest {
@InjectMocks
CreatorService service;
@Mock
MyService myService;
@Test
public void test() throws InterruptedException {
TimeUnit.MINUTES.sleep(1);
}
}
Мок введен нормально, но метод initAndCheckTimers () не запускается. Как я могу проверить свой метод @Scheduled?