diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableStateTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableStateTests.java index 8fcd326..7ad5998 100644 --- a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableStateTests.java +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SwitchableStateTests.java @@ -14,6 +14,7 @@ public class SwitchableStateTests { @BeforeEach public void createSwitchableState() { switchableState = new SwitchableState(); + switchableState.setDevice(new RegularLight()); } @Test @@ -22,5 +23,10 @@ public class SwitchableStateTests { switchableState.setOn(true); assertTrue(switchableState.isOn()); + + switchableState.apply(); + assertTrue(((Switchable) switchableState.getDevice()).isOn()); + + assertTrue(switchableState.copy().isOn()); } } diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/ThermostatServiceTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/ThermostatServiceTests.java index 05a0447..978b157 100644 --- a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/ThermostatServiceTests.java +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/ThermostatServiceTests.java @@ -10,6 +10,7 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User; import ch.usi.inf.sa4.sanmarinoes.smarthut.socket.SensorSocketEndpoint; import java.math.BigDecimal; import java.util.List; +import java.util.Optional; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -63,4 +64,14 @@ public class ThermostatServiceTests { when(thermostatRepository.findAllByUsername("user")).thenReturn(List.of(t)); assertThat(thermostatService.findAll("user")).containsExactly(t); } + + @Test + public void testFindById() { + final Thermostat t = new Thermostat(); + when(thermostatRepository.findByIdAndUsername(2L, "user")).thenReturn(Optional.empty()); + when(thermostatRepository.findByIdAndUsername(1L, "user")).thenReturn(Optional.of(t)); + doNothing().when(thermostatPopulationService).populateMeasuredTemperature(t); + assertThat(thermostatService.findById(2L, "user")).isEmpty(); + assertThat(thermostatService.findById(1L, "user")).isNotEmpty(); + } }