wip
This commit is contained in:
parent
7d634c0739
commit
a843786759
2 changed files with 19 additions and 2 deletions
|
@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||||
public abstract class InputDeviceConnectionController<
|
public abstract class InputDeviceConnectionController<
|
||||||
I extends InputDevice & Connectable<O>, O extends OutputDevice> {
|
I extends InputDevice & Connectable<O>, O extends OutputDevice> {
|
||||||
|
|
||||||
private class Connection {
|
protected class Connection {
|
||||||
private final I input;
|
private final I input;
|
||||||
private final List<O> outputs;
|
private final List<O> outputs;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyIterable;
|
||||||
import static org.mockito.ArgumentMatchers.anyLong;
|
import static org.mockito.ArgumentMatchers.anyLong;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
@ -10,9 +12,12 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Dimmable;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLight;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLight;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.KnobDimmer;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.KnobDimmer;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.KnobDimmerRepository;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.KnobDimmerRepository;
|
||||||
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.OutputDevice;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService;
|
||||||
|
import java.security.Principal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
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;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
|
@ -34,6 +39,13 @@ public class InputDeviceConnectionControllerTests {
|
||||||
|
|
||||||
@Mock DeviceRepository<Dimmable> outputRepository;
|
@Mock DeviceRepository<Dimmable> outputRepository;
|
||||||
|
|
||||||
|
@Mock private Principal mockPrincipal;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setup() {
|
||||||
|
when(mockPrincipal.getName()).thenReturn("user");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnection() throws NotFoundException {
|
public void testConnection() throws NotFoundException {
|
||||||
KnobDimmer knobDimmer = new KnobDimmer();
|
KnobDimmer knobDimmer = new KnobDimmer();
|
||||||
|
@ -46,9 +58,14 @@ public class InputDeviceConnectionControllerTests {
|
||||||
when(outputRepository.findByIdAndUsername(anyLong(), anyString()))
|
when(outputRepository.findByIdAndUsername(anyLong(), anyString()))
|
||||||
.thenReturn(java.util.Optional.of(dimmableLight));
|
.thenReturn(java.util.Optional.of(dimmableLight));
|
||||||
|
|
||||||
|
when(deviceService.saveAllAsOwner(anyIterable(), anyString()))
|
||||||
|
.thenReturn(List.of(new DimmableLight()));
|
||||||
|
|
||||||
List<Long> l = new ArrayList<>();
|
List<Long> l = new ArrayList<>();
|
||||||
l.add(10L);
|
l.add(10L);
|
||||||
|
|
||||||
Connection toTest = knobDimmerController.addOutput(5L, l, "user");
|
List<OutputDevice> toCheck = knobDimmerController.addLight(1L, l, mockPrincipal);
|
||||||
|
|
||||||
|
assertEquals(l.get(0), toCheck.get(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue