wip
This commit is contained in:
parent
9a86220a79
commit
7d634c0739
1 changed files with 54 additions and 0 deletions
|
@ -0,0 +1,54 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DeviceRepository;
|
||||
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.KnobDimmer;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.KnobDimmerRepository;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
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")
|
||||
public class InputDeviceConnectionControllerTests {
|
||||
|
||||
@InjectMocks KnobDimmerController knobDimmerController;
|
||||
|
||||
@Mock DeviceService deviceService;
|
||||
|
||||
@Mock KnobDimmerRepository knobDimmerRepository;
|
||||
|
||||
@Mock DeviceRepository<KnobDimmer> inputRepository;
|
||||
|
||||
@Mock DeviceRepository<Dimmable> outputRepository;
|
||||
|
||||
@Test
|
||||
public void testConnection() throws NotFoundException {
|
||||
KnobDimmer knobDimmer = new KnobDimmer();
|
||||
DimmableLight dimmableLight = new DimmableLight();
|
||||
knobDimmer.addDimmable(dimmableLight);
|
||||
|
||||
when(inputRepository.findByIdAndUsername(anyLong(), anyString()))
|
||||
.thenReturn(java.util.Optional.of(knobDimmer));
|
||||
|
||||
when(outputRepository.findByIdAndUsername(anyLong(), anyString()))
|
||||
.thenReturn(java.util.Optional.of(dimmableLight));
|
||||
|
||||
List<Long> l = new ArrayList<>();
|
||||
l.add(10L);
|
||||
|
||||
Connection toTest = knobDimmerController.addOutput(5L, l, "user");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue