# micronaut

Andy Burdett

10/21/2019, 8:54 AM
Hi guys, I have a scheduled task I'm trying to write a Spek test for. The task calls different apis at sunset and sunrise. I have written tests that execute at sunset and sunrise by setting the calendar and executing the function once in the task but I need to test the transition so need. How can I execute the task in my test to check the transition from sunset to sunrise whilst maintaining state within the task?
I've sorted it now.


11/12/2019, 6:56 PM
What was your solution?

Andy Burdett

11/13/2019, 9:45 AM
The Issue I was having was around mocking Calendar.getInstance since I needed to get the time of sunset and sunrise. I used MockK to answer two different times for Calendar.getInstance() based on a flag I set in my test. This allowed me to run the test at sunset and then run the test at sunrise.
every { Calendar.getInstance() } answers { nowSunset.set(2019, 4, 16, 17, 5, 0) nowSunset.set(Calendar.MILLISECOND, 0) nowSunrise.set(2019, 4, 16, 8, 5, 0) nowSunrise.set(Calendar.MILLISECOND, 0) if (isSunset) nowSunset else nowSunrise }