diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java index 878bfe3..a014e79 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java @@ -44,8 +44,6 @@ public class SensorController { newSensor.setName(s.getName()); newSensor.setRoomId(s.getRoomId()); newSensor.setValue(s.getValue()); - // newSensor.setError(s.getError()); - // newSensor.setTypical(s.getTypical()); return deviceService.saveAsOwner(newSensor, principal.getName()); } diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorControllerTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorControllerTests.java index 484564f..c56537e 100644 --- a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorControllerTests.java +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorControllerTests.java @@ -108,4 +108,25 @@ public class SensorControllerTests { assertThat(sensorController.updateValue(1L, BigDecimal.valueOf(30), mockPrincipal)) .isSameAs(s); } + + @Test + public void testUpdateSimulation() throws NotFoundException { + final Sensor s = new Sensor(); + when(sensorRepository.findByIdAndUsername(1L, "user")).thenReturn(Optional.of(s)); + when(sensorRepository.findByIdAndUsername(2L, "user")).thenReturn(Optional.empty()); + when(sensorService.updateSimulationFromSensor( + s, BigDecimal.valueOf(30), BigDecimal.valueOf(10))) + .thenAnswer( + i -> { + s.setError(i.getArgument(1)); + s.setTypical(i.getArgument(2)); + return s; + }); + assertThatThrownBy(() -> sensorController.updateValue(2L, BigDecimal.ZERO, mockPrincipal)) + .isInstanceOf(NotFoundException.class); + assertThat( + sensorController.updateSimulation( + 1L, BigDecimal.valueOf(30), BigDecimal.valueOf(10), mockPrincipal)) + .isSameAs(s); + } }