use of org.openhab.core.scheduler.CronScheduler in project openhab-addons by openhab.
the class AstroCommandTest method testRefreshCommandUpdatesTheStateOfTheChannels.
@Test
public void testRefreshCommandUpdatesTheStateOfTheChannels() {
ThingUID thingUID = new ThingUID(THING_TYPE_SUN, TEST_SUN_THING_ID);
ChannelUID channelUID = new ChannelUID(thingUID, DEFAULT_TEST_CHANNEL_ID);
Channel channel = ChannelBuilder.create(channelUID, DEFAULT_IMEM_TYPE).build();
Configuration thingConfiguration = new Configuration();
thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE);
thingConfiguration.put(INTERVAL_PROPERTY, INTERVAL_DEFAULT_VALUE);
Thing thing = mock(Thing.class);
when(thing.getConfiguration()).thenReturn(thingConfiguration);
when(thing.getUID()).thenReturn(thingUID);
when(thing.getChannel(DEFAULT_TEST_CHANNEL_ID)).thenReturn(channel);
ThingHandlerCallback callback = mock(ThingHandlerCallback.class);
CronScheduler cronScheduler = mock(CronScheduler.class);
TimeZoneProvider timeZoneProvider = mock(TimeZoneProvider.class);
when(timeZoneProvider.getTimeZone()).thenReturn(ZoneId.systemDefault());
AstroThingHandler sunHandler = spy(new SunHandler(thing, cronScheduler, timeZoneProvider));
// Required from the AstroThingHandler to send the status update
doReturn(true).when(callback).isChannelLinked(eq(channelUID));
doReturn(new Sun()).when(sunHandler).getPlanet();
sunHandler.setCallback(callback);
sunHandler.handleCommand(channelUID, RefreshType.REFRESH);
verify(callback, times(1)).stateUpdated(eq(channelUID), any(State.class));
}
use of org.openhab.core.scheduler.CronScheduler in project openhab-addons by openhab.
the class AstroValidConfigurationTest method assertThingStatus.
private void assertThingStatus(Configuration configuration, ThingStatus expectedStatus, ThingStatusDetail expectedStatusDetail) {
ThingUID thingUID = new ThingUID(THING_TYPE_SUN, TEST_SUN_THING_ID);
Thing thing = mock(Thing.class);
when(thing.getConfiguration()).thenReturn(configuration);
when(thing.getUID()).thenReturn(thingUID);
ThingHandlerCallback callback = mock(ThingHandlerCallback.class);
CronScheduler cronScheduler = mock(CronScheduler.class);
TimeZoneProvider timeZoneProvider = mock(TimeZoneProvider.class);
when(timeZoneProvider.getTimeZone()).thenReturn(ZoneId.systemDefault());
ThingHandler sunHandler = new SunHandler(thing, cronScheduler, timeZoneProvider);
sunHandler.setCallback(callback);
sunHandler.initialize();
ThingStatusInfo expectedThingStatus = new ThingStatusInfo(expectedStatus, expectedStatusDetail, null);
verify(callback, times(1)).statusUpdated(thing, expectedThingStatus);
}
Aggregations