So I've a Scheduler class where I inject a Service that calls a method at timeout. Basically like this:
@Singleton
@Startup
public class Scheduler{
@Resource
public TimerService timerService;
@Inject
private SomeService someService;
@PostConstruct
void postConstruct() {
TimerConfig config= new TimerConfig();
config.setPersistent(false);
timerService.createIntervalTimer(60000, 60000, config);
}
@Timeout
public void runsomeTask(Timer timer) {
someService.doSomething();
}
or this:
@Singleton
public class OtherScheduler{
@Inject
private SomeService someService;
@Schedule(second = "0", minute = "*/15", hour = "0", dayOfWeek = "*", persistent = false)
public void runsomeTask(Timer timer) {
someService.doSomething();
}
}
Until now i have only tested scheduler classes like those on my local server. So my question is how can I write a UnitTest for this? I would really appreciate some code examples or a good explanation.