I am building an application using spring boot which has couple of scheduling tasks which are executed one month after it is created. For testing this service, I need to change the server time to a time after one month, when the server is running. Can you please guide through the steps of how to achieve this?
For testing purpose, i would suggest you to create your service method with Date as parameter. ex :
public void myScheduledTack(){
myDate = getCurrentDate();
myService.myMethod(myDate);
}
public getCurrentDate(){
return new Date();
}
With this pattern, you could mock the getCurrentDate method and test your service.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.