Skip to content

Commit 190b851

Browse files
authored
feat: adding more tests (#132)
1 parent a0c165c commit 190b851

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.bigboxer23.switch_bot;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import com.bigboxer23.switch_bot.data.DeviceCommand;
6+
import org.junit.jupiter.api.Test;
7+
8+
public class IDeviceCommandsTest {
9+
10+
@Test
11+
public void testCommandConstants() {
12+
assertEquals("turnOff", IDeviceCommands.TURN_OFF);
13+
assertEquals("turnOn", IDeviceCommands.TURN_ON);
14+
}
15+
16+
@Test
17+
public void testCurtainCloseCommand() {
18+
DeviceCommand curtainClose = IDeviceCommands.CURTAIN_CLOSE;
19+
assertNotNull(curtainClose);
20+
assertEquals("turnOff", curtainClose.getCommand());
21+
assertEquals("default", curtainClose.getParameter());
22+
}
23+
24+
@Test
25+
public void testCurtainOpenCommand() {
26+
DeviceCommand curtainOpen = IDeviceCommands.CURTAIN_OPEN;
27+
assertNotNull(curtainOpen);
28+
assertEquals("turnOn", curtainOpen.getCommand());
29+
assertEquals("default", curtainOpen.getParameter());
30+
}
31+
32+
@Test
33+
public void testPlugMiniOffCommand() {
34+
DeviceCommand plugMiniOff = IDeviceCommands.PLUG_MINI_OFF;
35+
assertNotNull(plugMiniOff);
36+
assertEquals("turnOff", plugMiniOff.getCommand());
37+
assertEquals("default", plugMiniOff.getParameter());
38+
}
39+
40+
@Test
41+
public void testPlugMiniOnCommand() {
42+
DeviceCommand plugMiniOn = IDeviceCommands.PLUG_MINI_ON;
43+
assertNotNull(plugMiniOn);
44+
assertEquals("turnOn", plugMiniOn.getCommand());
45+
assertEquals("default", plugMiniOn.getParameter());
46+
}
47+
48+
@Test
49+
public void testCommandConsistency() {
50+
assertEquals(IDeviceCommands.CURTAIN_CLOSE.getCommand(), IDeviceCommands.PLUG_MINI_OFF.getCommand());
51+
assertEquals(IDeviceCommands.CURTAIN_OPEN.getCommand(), IDeviceCommands.PLUG_MINI_ON.getCommand());
52+
53+
assertEquals(IDeviceCommands.CURTAIN_CLOSE.getParameter(), IDeviceCommands.CURTAIN_OPEN.getParameter());
54+
assertEquals(IDeviceCommands.PLUG_MINI_OFF.getParameter(), IDeviceCommands.PLUG_MINI_ON.getParameter());
55+
}
56+
57+
@Test
58+
public void testCommandObjectsAreNotNull() {
59+
assertNotNull(IDeviceCommands.CURTAIN_CLOSE);
60+
assertNotNull(IDeviceCommands.CURTAIN_OPEN);
61+
assertNotNull(IDeviceCommands.PLUG_MINI_OFF);
62+
assertNotNull(IDeviceCommands.PLUG_MINI_ON);
63+
}
64+
}

src/test/java/com/bigboxer23/switch_bot/SwitchBotDeviceApiTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,26 @@ public void testConcurrentCacheRefresh() throws InterruptedException {
170170
fail("Verification failed: " + e.getMessage());
171171
}
172172
}
173+
174+
@Test
175+
public void testSendDeviceControlCommandsInputValidation() {
176+
DeviceCommand command = new DeviceCommand("turnOn", "default");
177+
String deviceId = "test-device-id";
178+
179+
assertNotNull(command);
180+
assertEquals("turnOn", command.getCommand());
181+
assertEquals("default", command.getParameter());
182+
assertNotNull(deviceId);
183+
}
184+
185+
@Test
186+
public void testGetDeviceStatusReturnsNullForNullInput() throws IOException {
187+
Device result = deviceApi.getDeviceStatus(null);
188+
assertNull(result);
189+
}
190+
191+
@Test
192+
public void testDeviceApiNotNull() {
193+
assertNotNull(deviceApi);
194+
}
173195
}

0 commit comments

Comments
 (0)