]> git.basschouten.com Git - openhab-addons.git/blob
21570cb723b9d82d92fab32b56c86374b817a7ae
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.tplinksmarthome.internal.device;
14
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.openhab.binding.tplinksmarthome.internal.ChannelUIDConstants.*;
17
18 import java.io.IOException;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.core.library.types.OnOffType;
23 import org.openhab.core.types.UnDefType;
24
25 /**
26  * Test class for {@link SwitchDevice} class.
27  *
28  * @author Hilbrand Bouwkamp - Initial contribution
29  */
30 @NonNullByDefault
31 public class SwitchDeviceTest extends DeviceTestBase<SwitchDevice> {
32
33     public SwitchDeviceTest() throws IOException {
34         super(new SwitchDevice(), "plug_get_sysinfo_response");
35     }
36
37     @Test
38     public void testHandleCommandSwitch() throws IOException {
39         assertInput("plug_set_relay_state_on");
40         setSocketReturnAssert("plug_set_relay_state_on");
41         assertTrue(device.handleCommand(CHANNEL_UID_SWITCH, OnOffType.ON), "Switch channel should be handled");
42     }
43
44     @Test
45     public void testHandleCommandLed() throws IOException {
46         assertInput("plug_set_led_on");
47         setSocketReturnAssert("plug_set_led_on");
48         assertTrue(device.handleCommand(CHANNEL_UID_LED, OnOffType.ON), "Led channel should be handled");
49     }
50
51     @Test
52     public void testUpdateChannelSwitch() {
53         assertSame(OnOffType.ON, device.updateChannel(CHANNEL_UID_SWITCH, deviceState), "Switch should be on");
54     }
55
56     @Test
57     public void testUpdateChannelLed() {
58         assertSame(OnOffType.ON, device.updateChannel(CHANNEL_UID_LED, deviceState), "Led should be on");
59     }
60
61     @Test
62     public void testUpdateChannelOther() {
63         assertSame(UnDefType.UNDEF, device.updateChannel(CHANNEL_UID_OTHER, deviceState),
64                 "Unknown channel should return UNDEF");
65     }
66 }