Skip to content

Commit

Permalink
openhab#15 Write test for special command to turn white color or turn…
Browse files Browse the repository at this point in the history
… off lights
  • Loading branch information
magx2 committed May 17, 2019
1 parent 2d23d5e commit bb7c43a
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.github.glytching.junit.extension.random.RandomBeansExtension;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.core.library.types.HSBType;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.OpenClosedType;
import org.eclipse.smarthome.core.library.types.PercentType;
Expand Down Expand Up @@ -62,8 +63,11 @@
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.openhab.binding.supla.SuplaBindingConstants.Commands.OFF_LIGHT_COMMAND;
import static org.openhab.binding.supla.SuplaBindingConstants.Commands.OPEN_CLOSE_GATE_COMMAND;
import static org.openhab.binding.supla.SuplaBindingConstants.Commands.WHITE_LIGHT_COMMAND;
import static org.openhab.binding.supla.SuplaBindingConstants.SUPLA_DEVICE_CLOUD_ID;
import static org.openhab.binding.supla.internal.cloud.AdditionalChannelType.EXTRA_LIGHT_ACTIONS;
import static org.openhab.binding.supla.internal.cloud.AdditionalChannelType.LED_BRIGHTNESS;
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.CLOSE;
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.OPEN;
Expand Down Expand Up @@ -437,10 +441,51 @@ void openCloseGateAndGarage(String idFieldName) throws Exception {
assertThat(value.getAction()).isEqualTo(OPEN_CLOSE);
}

@ParameterizedTest
@ValueSource(strings = {"rgbChannelId", "dimmerAndRgbChannelId"})
@DisplayName("should send request to LedExecutor to change color to white")
void setLightColorToWhite(String idFieldName) throws Exception {

// given
final int id = (int) FieldUtils.readDeclaredField(this, idFieldName, true);
final ChannelUID channelUID = buildChannelUID(id, EXTRA_LIGHT_ACTIONS);
final ChannelUID parentChannelUID = buildChannelUID(id);

// when
handler.handleStringCommand(channelUID, new StringType(WHITE_LIGHT_COMMAND));

// then
verify(ledCommandExecutor).changeColor(id, parentChannelUID, HSBType.WHITE);
verify(callback).stateUpdated(parentChannelUID, HSBType.WHITE);
}

@ParameterizedTest
@ValueSource(strings = {"rgbChannelId", "dimmerAndRgbChannelId"})
@DisplayName("should send request to LedExecutor to change color to black")
void turnOffRgbLights(String idFieldName) throws Exception {

// given
final int id = (int) FieldUtils.readDeclaredField(this, idFieldName, true);
final ChannelUID channelUID = buildChannelUID(id, EXTRA_LIGHT_ACTIONS);
final ChannelUID parentChannelUID = buildChannelUID(id);

// when
handler.handleStringCommand(channelUID, new StringType(OFF_LIGHT_COMMAND));

// then
verify(ledCommandExecutor).changeColor(id, parentChannelUID, HSBType.BLACK);
verify(callback).stateUpdated(parentChannelUID, HSBType.BLACK);
}

ChannelUID buildChannelUID(int id) {
return new ChannelUID(thingUID, valueOf(id));
}

@SuppressWarnings("SameParameterValue")
ChannelUID buildChannelUID(int id, AdditionalChannelType channelType) {
return new ChannelUID(thingUID, id + channelType.getSuffix());
}

ChannelUID findLightChannelUID() {
return buildChannelUID(lightChannelId);
}
Expand Down

0 comments on commit bb7c43a

Please sign in to comment.