From f6aceacb5fd8b7cceb47065cb15d3e5fdd1b1ffd Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Fri, 15 Aug 2025 14:43:03 -0500 Subject: [PATCH 1/2] feat: adding model tests --- pom.xml | 40 +++ .../bigboxer23/switch_bot/data/Device.java | 3 +- .../switch_bot/SwitchBotApiUnitTest.java | 79 +++++- .../switch_bot/SwitchBotDeviceApiTest.java | 173 +++++++++++++ .../switch_bot/data/DeviceCommandTest.java | 169 ++++++++++++ .../switch_bot/data/DeviceTest.java | 240 ++++++++++++++++++ 6 files changed, 700 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/bigboxer23/switch_bot/SwitchBotDeviceApiTest.java create mode 100644 src/test/java/com/bigboxer23/switch_bot/data/DeviceCommandTest.java create mode 100644 src/test/java/com/bigboxer23/switch_bot/data/DeviceTest.java diff --git a/pom.xml b/pom.xml index 58e5223..a0a7ea6 100644 --- a/pom.xml +++ b/pom.xml @@ -176,6 +176,46 @@ test + + check + + check + + + + + BUNDLE + + + INSTRUCTION + COVEREDRATIO + 0.80 + + + BRANCH + COVEREDRATIO + 0.75 + + + + + CLASS + + *Test + *IT + *IntegrationTest + + + + LINE + COVEREDRATIO + 0.70 + + + + + + diff --git a/src/main/java/com/bigboxer23/switch_bot/data/Device.java b/src/main/java/com/bigboxer23/switch_bot/data/Device.java index e49363f..0358173 100644 --- a/src/main/java/com/bigboxer23/switch_bot/data/Device.java +++ b/src/main/java/com/bigboxer23/switch_bot/data/Device.java @@ -1,9 +1,8 @@ package com.bigboxer23.switch_bot.data; import com.squareup.moshi.Json; -import lombok.Data; - import java.util.List; +import lombok.Data; /** */ @Data diff --git a/src/test/java/com/bigboxer23/switch_bot/SwitchBotApiUnitTest.java b/src/test/java/com/bigboxer23/switch_bot/SwitchBotApiUnitTest.java index 8bbab63..506e3b2 100644 --- a/src/test/java/com/bigboxer23/switch_bot/SwitchBotApiUnitTest.java +++ b/src/test/java/com/bigboxer23/switch_bot/SwitchBotApiUnitTest.java @@ -3,14 +3,24 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; -import com.bigboxer23.switch_bot.data.Device; -import com.bigboxer23.switch_bot.data.DeviceCommand; +import com.bigboxer23.switch_bot.data.*; import com.bigboxer23.utils.time.ITimeConstants; import java.io.IOException; import java.util.List; +import java.util.Optional; +import okhttp3.Response; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class SwitchBotApiUnitTest { + + @BeforeEach + void resetSingleton() throws Exception { + java.lang.reflect.Field instanceField = SwitchBotApi.class.getDeclaredField("instance"); + instanceField.setAccessible(true); + instanceField.set(null, null); + } + @Test public void testSingletonBehavior() { SwitchBotApi mockApi1 = SwitchBotApi.getInstance("token", "secret"); @@ -18,6 +28,71 @@ public void testSingletonBehavior() { assertSame(mockApi1, mockApi2, "Should return the same singleton instance"); } + @Test + public void testGetInstanceWithNullToken() { + RuntimeException exception = assertThrows(RuntimeException.class, () -> { + SwitchBotApi.getInstance(null, "secret"); + }); + assertEquals("need to define token and secret values.", exception.getMessage()); + } + + @Test + public void testGetInstanceWithNullSecret() { + RuntimeException exception = assertThrows(RuntimeException.class, () -> { + SwitchBotApi.getInstance("token", null); + }); + assertEquals("need to define token and secret values.", exception.getMessage()); + } + + @Test + public void testAddAuthReturnsCallback() { + assertNotNull(SwitchBotApi.getInstance("testToken", "testSecret")); + } + + @Test + public void testCheckForErrorWithSuccessfulResponse() { + SwitchBotApi api = SwitchBotApi.getInstance("token", "secret"); + Response mockResponse = mock(Response.class); + ApiResponse successResponse = new ApiResponse(); + successResponse.setStatusCode(100); + successResponse.setMessage("success"); + + IApiResponse result = api.checkForError(mockResponse, Optional.of(successResponse)); + + assertTrue(result.isSuccess()); + assertEquals(100, result.getStatusCode()); + } + + @Test + public void testCheckForErrorWithFailedResponse() { + SwitchBotApi api = SwitchBotApi.getInstance("token", "secret"); + Response mockResponse = mock(Response.class); + ApiResponse failedResponse = new ApiResponse(); + failedResponse.setStatusCode(190); + failedResponse.setMessage("Device not found"); + + IApiResponse result = api.checkForError(mockResponse, Optional.of(failedResponse)); + + assertFalse(result.isSuccess()); + assertEquals(190, result.getStatusCode()); + assertEquals("Device not found", result.getMessage()); + } + + @Test + public void testCheckForErrorWithEmptyResponse() { + SwitchBotApi api = SwitchBotApi.getInstance("token", "secret"); + Response mockResponse = mock(Response.class); + when(mockResponse.code()).thenReturn(404); + when(mockResponse.message()).thenReturn("Not Found"); + + IApiResponse result = api.checkForError(mockResponse, Optional.empty()); + + assertFalse(result.isSuccess()); + assertEquals(404, result.getStatusCode()); + assertEquals("Not Found", result.getMessage()); + assertInstanceOf(BadApiResponse.class, result); + } + @Test public void testDeviceCommandSerialization() throws IOException { SwitchBotApi api = SwitchBotApi.getInstance("token", "secret"); diff --git a/src/test/java/com/bigboxer23/switch_bot/SwitchBotDeviceApiTest.java b/src/test/java/com/bigboxer23/switch_bot/SwitchBotDeviceApiTest.java new file mode 100644 index 0000000..d28a558 --- /dev/null +++ b/src/test/java/com/bigboxer23/switch_bot/SwitchBotDeviceApiTest.java @@ -0,0 +1,173 @@ +package com.bigboxer23.switch_bot; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +import com.bigboxer23.switch_bot.data.*; +import com.bigboxer23.utils.time.ITimeConstants; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +public class SwitchBotDeviceApiTest { + + @Mock + private SwitchBotApi mockSwitchBotApi; + + private SwitchBotDeviceApi deviceApi; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + deviceApi = new SwitchBotDeviceApi(mockSwitchBotApi); + } + + @Test + public void testGetDeviceNameFromIdWithFreshCache() throws IOException { + Device device1 = new Device(); + device1.setDeviceId("device1"); + device1.setDeviceName("Living Room Light"); + + Device device2 = new Device(); + device2.setDeviceId("device2"); + device2.setDeviceName("Bedroom Curtain"); + + SwitchBotDeviceApi spyDeviceApi = spy(deviceApi); + doReturn(Arrays.asList(device1, device2)).when(spyDeviceApi).getDevices(); + + String result = spyDeviceApi.getDeviceNameFromId("device1"); + assertEquals("Living Room Light", result); + + String result2 = spyDeviceApi.getDeviceNameFromId("device2"); + assertEquals("Bedroom Curtain", result2); + } + + @Test + public void testGetDeviceNameFromIdWithUnknownDevice() throws IOException { + Device device = new Device(); + device.setDeviceId("known-device"); + device.setDeviceName("Known Device"); + + SwitchBotDeviceApi spyDeviceApi = spy(deviceApi); + doReturn(Arrays.asList(device)).when(spyDeviceApi).getDevices(); + + String result = spyDeviceApi.getDeviceNameFromId("unknown-device"); + assertEquals("unknown-device", result); + } + + @Test + public void testGetDeviceNameFromIdCacheExpiry() throws IOException { + Device device = new Device(); + device.setDeviceId("device1"); + device.setDeviceName("Test Device"); + + SwitchBotDeviceApi spyDeviceApi = spy(deviceApi); + spyDeviceApi.deviceIdToNamesCacheTime = System.currentTimeMillis() - (ITimeConstants.HOUR * 2); + + doReturn(Arrays.asList(device)).when(spyDeviceApi).getDevices(); + + String result = spyDeviceApi.getDeviceNameFromId("device1"); + assertEquals("Test Device", result); + + verify(spyDeviceApi, times(1)).getDevices(); + } + + @Test + public void testGetDeviceNameFromIdWithValidCache() throws IOException { + Device device = new Device(); + device.setDeviceId("device1"); + device.setDeviceName("Cached Device"); + + SwitchBotDeviceApi spyDeviceApi = spy(deviceApi); + spyDeviceApi.deviceIdToNamesCacheTime = System.currentTimeMillis(); + + doReturn(Arrays.asList(device)).when(spyDeviceApi).getDevices(); + spyDeviceApi.getDeviceNameFromId("device1"); + + reset(spyDeviceApi); + spyDeviceApi.deviceIdToNamesCacheTime = System.currentTimeMillis(); + spyDeviceApi.getDeviceNameFromId("device1"); + + verify(spyDeviceApi, never()).getDevices(); + } + + @Test + public void testGetDeviceNameFromIdWithIOException() throws IOException { + SwitchBotDeviceApi spyDeviceApi = spy(deviceApi); + doThrow(new IOException("Network error")).when(spyDeviceApi).getDevices(); + + String result = spyDeviceApi.getDeviceNameFromId("device1"); + assertEquals("device1", result); + } + + @Test + public void testGetDeviceStatusWithNullDeviceId() throws IOException { + Device result = deviceApi.getDeviceStatus(null); + assertNull(result); + } + + @Test + public void testGetDeviceStatusInputValidation() { + assertDoesNotThrow(() -> { + assertNotNull(deviceApi); + }); + } + + @Test + public void testSendDeviceControlCommandsValidation() { + DeviceCommand command = new DeviceCommand("turnOn", "default"); + when(mockSwitchBotApi.getMoshi()).thenReturn(new com.squareup.moshi.Moshi.Builder().build()); + + assertNotNull(command); + assertEquals("turnOn", command.getCommand()); + assertEquals("default", command.getParameter()); + } + + @Test + public void testRefreshDeviceNameMapWithEmptyList() throws IOException { + SwitchBotDeviceApi spyDeviceApi = spy(deviceApi); + doReturn(Collections.emptyList()).when(spyDeviceApi).getDevices(); + + String result = spyDeviceApi.getDeviceNameFromId("any-device"); + assertEquals("any-device", result); + } + + @Test + public void testConcurrentCacheRefresh() throws InterruptedException { + SwitchBotDeviceApi spyDeviceApi = spy(deviceApi); + spyDeviceApi.deviceIdToNamesCacheTime = System.currentTimeMillis() - (ITimeConstants.HOUR * 2); + + Device device = new Device(); + device.setDeviceId("concurrent-device"); + device.setDeviceName("Concurrent Test"); + try { + doReturn(Arrays.asList(device)).when(spyDeviceApi).getDevices(); + } catch (IOException e) { + fail("Setup failed: " + e.getMessage()); + } + + Thread thread1 = new Thread(() -> { + spyDeviceApi.getDeviceNameFromId("concurrent-device"); + }); + + Thread thread2 = new Thread(() -> { + spyDeviceApi.getDeviceNameFromId("concurrent-device"); + }); + + thread1.start(); + thread2.start(); + + thread1.join(); + thread2.join(); + + try { + verify(spyDeviceApi, atLeastOnce()).getDevices(); + } catch (IOException e) { + fail("Verification failed: " + e.getMessage()); + } + } +} diff --git a/src/test/java/com/bigboxer23/switch_bot/data/DeviceCommandTest.java b/src/test/java/com/bigboxer23/switch_bot/data/DeviceCommandTest.java new file mode 100644 index 0000000..94de19e --- /dev/null +++ b/src/test/java/com/bigboxer23/switch_bot/data/DeviceCommandTest.java @@ -0,0 +1,169 @@ +package com.bigboxer23.switch_bot.data; + +import static org.junit.jupiter.api.Assertions.*; + +import com.squareup.moshi.JsonAdapter; +import com.squareup.moshi.Moshi; +import java.io.IOException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class DeviceCommandTest { + + private Moshi moshi; + private JsonAdapter adapter; + + @BeforeEach + void setUp() { + moshi = new Moshi.Builder().build(); + adapter = moshi.adapter(DeviceCommand.class); + } + + @Test + public void testDeviceCommandConstructor() { + DeviceCommand command = new DeviceCommand("turnOn", "default"); + + assertEquals("turnOn", command.getCommand()); + assertEquals("default", command.getParameter()); + assertEquals("command", command.getCommandType()); + } + + @Test + public void testDeviceCommandConstructorWithNullValues() { + DeviceCommand command = new DeviceCommand(null, null); + + assertNull(command.getCommand()); + assertNull(command.getParameter()); + assertEquals("command", command.getCommandType()); + } + + @Test + public void testDeviceCommandConstructorWithEmptyValues() { + DeviceCommand command = new DeviceCommand("", ""); + + assertEquals("", command.getCommand()); + assertEquals("", command.getParameter()); + assertEquals("command", command.getCommandType()); + } + + @Test + public void testDeviceCommandJsonSerialization() throws IOException { + DeviceCommand command = new DeviceCommand("turnOff", "immediate"); + + String json = adapter.toJson(command); + + assertNotNull(json); + assertTrue(json.contains("\"command\":\"turnOff\"")); + assertTrue(json.contains("\"parameter\":\"immediate\"")); + assertTrue(json.contains("\"commandType\":\"command\"")); + } + + @Test + public void testDeviceCommandJsonSerializationWithSpecialCharacters() throws IOException { + DeviceCommand command = new DeviceCommand("setPosition", "50%"); + + String json = adapter.toJson(command); + + assertNotNull(json); + assertTrue(json.contains("\"command\":\"setPosition\"")); + assertTrue(json.contains("\"parameter\":\"50%\"")); + } + + @Test + public void testDeviceCommandJsonDeserialization() throws IOException { + String json = + "{" + "\"command\":\"setBrightness\"," + "\"parameter\":\"75\"," + "\"commandType\":\"command\"" + "}"; + + DeviceCommand command = adapter.fromJson(json); + + assertNotNull(command); + assertEquals("setBrightness", command.getCommand()); + assertEquals("75", command.getParameter()); + assertEquals("command", command.getCommandType()); + } + + @Test + public void testDeviceCommandJsonDeserializationWithMissingFields() throws IOException { + String json = "{\"command\":\"toggle\"}"; + + DeviceCommand command = adapter.fromJson(json); + + assertNotNull(command); + assertEquals("toggle", command.getCommand()); + assertNull(command.getParameter()); + assertNull(command.getCommandType()); + } + + @Test + public void testDeviceCommandJsonDeserializationWithNullValues() throws IOException { + String json = "{" + "\"command\":null," + "\"parameter\":null," + "\"commandType\":null" + "}"; + + DeviceCommand command = adapter.fromJson(json); + + assertNotNull(command); + assertNull(command.getCommand()); + assertNull(command.getParameter()); + assertNull(command.getCommandType()); + } + + @Test + public void testDeviceCommandSettersAndGetters() { + DeviceCommand command = new DeviceCommand("initial", "param"); + + command.setCommand("updated"); + command.setParameter("newParam"); + command.setCommandType("newType"); + + assertEquals("updated", command.getCommand()); + assertEquals("newParam", command.getParameter()); + assertEquals("newType", command.getCommandType()); + } + + @Test + public void testDeviceCommandEqualsAndHashCode() { + DeviceCommand command1 = new DeviceCommand("turnOn", "default"); + DeviceCommand command2 = new DeviceCommand("turnOn", "default"); + DeviceCommand command3 = new DeviceCommand("turnOff", "default"); + + assertEquals(command1, command2); + assertEquals(command1.hashCode(), command2.hashCode()); + assertNotEquals(command1, command3); + assertNotEquals(command1.hashCode(), command3.hashCode()); + } + + @Test + public void testDeviceCommandToString() { + DeviceCommand command = new DeviceCommand("setTimer", "30min"); + + String toString = command.toString(); + + assertNotNull(toString); + assertTrue(toString.contains("setTimer")); + assertTrue(toString.contains("30min")); + assertTrue(toString.contains("command")); + } + + @Test + public void testDeviceCommandWithComplexParameters() throws IOException { + DeviceCommand command = new DeviceCommand("setSchedule", "{\"time\":\"08:00\",\"days\":[\"mon\",\"tue\"]}"); + + String json = adapter.toJson(command); + DeviceCommand deserializedCommand = adapter.fromJson(json); + + assertEquals(command.getCommand(), deserializedCommand.getCommand()); + assertEquals(command.getParameter(), deserializedCommand.getParameter()); + assertEquals(command.getCommandType(), deserializedCommand.getCommandType()); + } + + @Test + public void testDeviceCommandRoundTripSerialization() throws IOException { + DeviceCommand originalCommand = new DeviceCommand("testCommand", "testParameter"); + + String json = adapter.toJson(originalCommand); + DeviceCommand deserializedCommand = adapter.fromJson(json); + + assertEquals(originalCommand.getCommand(), deserializedCommand.getCommand()); + assertEquals(originalCommand.getParameter(), deserializedCommand.getParameter()); + assertEquals(originalCommand.getCommandType(), deserializedCommand.getCommandType()); + } +} diff --git a/src/test/java/com/bigboxer23/switch_bot/data/DeviceTest.java b/src/test/java/com/bigboxer23/switch_bot/data/DeviceTest.java new file mode 100644 index 0000000..bd9b2a2 --- /dev/null +++ b/src/test/java/com/bigboxer23/switch_bot/data/DeviceTest.java @@ -0,0 +1,240 @@ +package com.bigboxer23.switch_bot.data; + +import static org.junit.jupiter.api.Assertions.*; + +import com.squareup.moshi.JsonAdapter; +import com.squareup.moshi.Moshi; +import java.io.IOException; +import java.util.Arrays; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class DeviceTest { + + private Device device; + private Moshi moshi; + private JsonAdapter adapter; + + @BeforeEach + void setUp() { + device = new Device(); + moshi = new Moshi.Builder().build(); + adapter = moshi.adapter(Device.class); + } + + @Test + public void testIsDryWithDryStatus() { + device.setWaterDetectorStatus(0); + assertTrue(device.isDry()); + assertFalse(device.isWet()); + } + + @Test + public void testIsWetWithWetStatus() { + device.setWaterDetectorStatus(1); + assertTrue(device.isWet()); + assertFalse(device.isDry()); + } + + @Test + public void testWaterDetectorStatusEdgeCases() { + device.setWaterDetectorStatus(-1); + assertFalse(device.isDry()); + assertFalse(device.isWet()); + + device.setWaterDetectorStatus(2); + assertFalse(device.isDry()); + assertFalse(device.isWet()); + } + + @Test + public void testIsPowerOnWithOnStatus() { + device.setPower("on"); + assertTrue(device.isPowerOn()); + + device.setPower("ON"); + assertTrue(device.isPowerOn()); + + device.setPower("On"); + assertTrue(device.isPowerOn()); + } + + @Test + public void testIsPowerOnWithOffStatus() { + device.setPower("off"); + assertFalse(device.isPowerOn()); + + device.setPower("OFF"); + assertFalse(device.isPowerOn()); + + device.setPower("Off"); + assertFalse(device.isPowerOn()); + } + + @Test + public void testIsPowerOnWithNullPower() { + device.setPower(null); + assertFalse(device.isPowerOn()); + } + + @Test + public void testIsPowerOnWithInvalidPower() { + device.setPower("invalid"); + assertFalse(device.isPowerOn()); + + device.setPower(""); + assertFalse(device.isPowerOn()); + + device.setPower(" "); + assertFalse(device.isPowerOn()); + } + + @Test + public void testDeviceBasicProperties() { + device.setDeviceId("test-device-123"); + device.setDeviceName("Test Device"); + device.setDeviceType("Plug"); + device.setHumidity(45); + device.setTemperature(23.5f); + device.setLightLevel(300); + device.setVersion("1.2.3"); + device.setBattery(85); + + assertEquals("test-device-123", device.getDeviceId()); + assertEquals("Test Device", device.getDeviceName()); + assertEquals("Plug", device.getDeviceType()); + assertEquals(45, device.getHumidity()); + assertEquals(23.5f, device.getTemperature(), 0.01); + assertEquals(300, device.getLightLevel()); + assertEquals("1.2.3", device.getVersion()); + assertEquals(85, device.getBattery()); + } + + @Test + public void testDeviceGroupProperties() { + device.setGroup(true); + device.setMaster(false); + device.setGroupName("Living Room Group"); + device.setGroupingDevicesIds(Arrays.asList("device1", "device2", "device3")); + device.setCurtainDevicesIds(Arrays.asList("curtain1", "curtain2")); + + assertTrue(device.isGroup()); + assertFalse(device.isMaster()); + assertEquals("Living Room Group", device.getGroupName()); + assertEquals(3, device.getGroupingDevicesIds().size()); + assertEquals("device1", device.getGroupingDevicesIds().get(0)); + assertEquals(2, device.getCurtainDevicesIds().size()); + assertEquals("curtain1", device.getCurtainDevicesIds().get(0)); + } + + @Test + public void testDeviceCurtainProperties() { + device.setOpenDirection("left"); + device.setMoving(true); + device.setSlidePosition(75); + + assertEquals("left", device.getOpenDirection()); + assertTrue(device.isMoving()); + assertEquals(75, device.getSlidePosition()); + } + + @Test + public void testDeviceElectricalProperties() { + device.setVoltage(120.5f); + device.setWatts(15.3f); + device.setElectricityOfDay(250); + device.setElectricCurrent(1.25f); + + assertEquals(120.5f, device.getVoltage(), 0.01); + assertEquals(15.3f, device.getWatts(), 0.01); + assertEquals(250, device.getElectricityOfDay()); + assertEquals(1.25f, device.getElectricCurrent(), 0.01); + } + + @Test + public void testDeviceEnvironmentalProperties() { + device.setCo2(400); + device.setCalibrate(true); + device.setHubDeviceId("hub-123"); + device.setEnableCloudService(false); + + assertEquals(400, device.getCo2()); + assertTrue(device.isCalibrate()); + assertEquals("hub-123", device.getHubDeviceId()); + assertFalse(device.isEnableCloudService()); + } + + @Test + public void testDeviceJsonSerialization() throws IOException { + device.setDeviceId("json-test-device"); + device.setDeviceName("JSON Test Device"); + device.setWatts(25.8f); + device.setCo2(350); + + String json = adapter.toJson(device); + assertNotNull(json); + assertTrue(json.contains("json-test-device")); + assertTrue(json.contains("JSON Test Device")); + assertTrue(json.contains("\"weight\":25.8")); + assertTrue(json.contains("\"CO2\":350")); + } + + @Test + public void testDeviceJsonDeserialization() throws IOException { + String json = "{" + + "\"deviceId\":\"deserialize-test\"," + + "\"deviceName\":\"Deserialize Test\"," + + "\"power\":\"on\"," + + "\"waterDetectorStatus\":1," + + "\"weight\":30.5," + + "\"CO2\":420" + + "}"; + + Device deserializedDevice = adapter.fromJson(json); + + assertNotNull(deserializedDevice); + assertEquals("deserialize-test", deserializedDevice.getDeviceId()); + assertEquals("Deserialize Test", deserializedDevice.getDeviceName()); + assertEquals("on", deserializedDevice.getPower()); + assertTrue(deserializedDevice.isPowerOn()); + assertEquals(1, deserializedDevice.getWaterDetectorStatus()); + assertTrue(deserializedDevice.isWet()); + assertEquals(30.5f, deserializedDevice.getWatts(), 0.01); + assertEquals(420, deserializedDevice.getCo2()); + } + + @Test + public void testDeviceJsonDeserializationWithNullValues() throws IOException { + String json = "{" + "\"deviceId\":\"null-test\"," + "\"power\":null," + "\"groupName\":null" + "}"; + + Device deserializedDevice = adapter.fromJson(json); + + assertNotNull(deserializedDevice); + assertEquals("null-test", deserializedDevice.getDeviceId()); + assertNull(deserializedDevice.getPower()); + assertFalse(deserializedDevice.isPowerOn()); + assertNull(deserializedDevice.getGroupName()); + } + + @Test + public void testDeviceDefaultValues() { + Device newDevice = new Device(); + + assertEquals(0, newDevice.getHumidity()); + assertEquals(0.0f, newDevice.getTemperature(), 0.01); + assertEquals(0, newDevice.getLightLevel()); + assertEquals(0, newDevice.getBattery()); + assertFalse(newDevice.isGroup()); + assertFalse(newDevice.isMaster()); + assertFalse(newDevice.isMoving()); + assertEquals(0, newDevice.getSlidePosition()); + assertEquals(0.0f, newDevice.getVoltage(), 0.01); + assertEquals(0.0f, newDevice.getWatts(), 0.01); + assertEquals(0, newDevice.getElectricityOfDay()); + assertEquals(0.0f, newDevice.getElectricCurrent(), 0.01); + assertEquals(0, newDevice.getWaterDetectorStatus()); + assertEquals(0, newDevice.getCo2()); + assertFalse(newDevice.isCalibrate()); + assertFalse(newDevice.isEnableCloudService()); + } +} From 708d2ccad5a1de81e7901704ad3ae0b30ba1362b Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Fri, 15 Aug 2025 14:46:18 -0500 Subject: [PATCH 2/2] feat: adding model tests --- pom.xml | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/pom.xml b/pom.xml index a0a7ea6..58e5223 100644 --- a/pom.xml +++ b/pom.xml @@ -176,46 +176,6 @@ test - - check - - check - - - - - BUNDLE - - - INSTRUCTION - COVEREDRATIO - 0.80 - - - BRANCH - COVEREDRATIO - 0.75 - - - - - CLASS - - *Test - *IT - *IntegrationTest - - - - LINE - COVEREDRATIO - 0.70 - - - - - -