scene service

This commit is contained in:
omenem 2020-05-26 18:39:03 +02:00
parent e12163d2eb
commit 5e9a83da8b

View file

@ -1,11 +1,13 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.service; package ch.usi.inf.sa4.sanmarinoes.smarthut.service;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
@ -22,6 +24,8 @@ public class SceneServiceTests {
@Mock private SceneRepository sceneRepository; @Mock private SceneRepository sceneRepository;
@Mock private StateRepository<State> stateRepository;
@Mock private DevicePropagationService deviceService; @Mock private DevicePropagationService deviceService;
@Mock private DevicePopulationService devicePopulationService; @Mock private DevicePopulationService devicePopulationService;
@ -56,4 +60,20 @@ public class SceneServiceTests {
assertThat(sceneService.applyAsGuest(s, "user", 42L)).containsExactly(d); assertThat(sceneService.applyAsGuest(s, "user", 42L)).containsExactly(d);
assertThat(d.getIntensity()).isEqualTo(40); assertThat(d.getIntensity()).isEqualTo(40);
} }
@Test
public void testCopyStates() {
final State state = new DimmableState();
final Scene sceneFrom = new Scene();
sceneFrom.getStates().add(state);
final Scene sceneTo = new Scene();
when(stateRepository.save(any(State.class))).thenReturn(state);
List<State> s = sceneService.copyStates(sceneTo, sceneFrom);
assertEquals(s.get(0), state);
}
} }