added MotionSensorService tests
This commit is contained in:
parent
cffeeca9f8
commit
4970791792
1 changed files with 40 additions and 0 deletions
|
@ -0,0 +1,40 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut.service;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.socket.SensorSocketEndpoint;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@WithMockUser(username = "user")
|
||||
@DisplayName("MotionSensorService test")
|
||||
public class MotionSensorServiceTests {
|
||||
@InjectMocks private MotionSensorService service;
|
||||
|
||||
@Mock private SensorSocketEndpoint sensorSocketEndpoint;
|
||||
@Mock private DeviceService deviceService;
|
||||
@Mock private MotionSensorRepository motionSensorRepository;
|
||||
|
||||
@Test
|
||||
public void testUpdateDetectionFromMotionSensor() {
|
||||
MotionSensor sensor = new MotionSensor();
|
||||
sensor.setId(1L);
|
||||
User user = new User();
|
||||
user.setId(1L);
|
||||
when(deviceService.saveAsOwner(sensor, "user")).thenReturn(sensor);
|
||||
when(motionSensorRepository.findUser(sensor.getId())).thenReturn(user);
|
||||
doNothing().when(sensorSocketEndpoint).queueDeviceUpdate(sensor, user, false, null, false);
|
||||
MotionSensor returned = service.updateDetectionFromMotionSensor(sensor, true, "user");
|
||||
assertThat(returned).isEqualTo(sensor);
|
||||
assertTrue(returned.isDetected());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue