diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightControllerTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightControllerTests.java index c73b9be..cca260e 100644 --- a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightControllerTests.java +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightControllerTests.java @@ -11,17 +11,8 @@ import static org.mockito.Mockito.when; import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.DimmableSaveRequest; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.DuplicateStateException; 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.DimmableLight; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLightRepository; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableState; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Scene; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.SceneRepository; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.State; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.StateRepository; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.UserRepository; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; import ch.usi.inf.sa4.sanmarinoes.smarthut.service.DeviceService; -import ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils; import java.security.Principal; import java.util.Optional; import lombok.SneakyThrows; @@ -115,12 +106,13 @@ public class DimmableLightControllerTests { when(deviceService.saveAsGuest(any(DimmableLight.class), eq("user"), anyLong())) .thenAnswer(i -> i.getArguments()[0]); - when(Utils.returnIfGuest( - any(UserRepository.class), - any(DimmableLight.class), - anyLong(), - any(Principal.class))) - .thenAnswer(i -> i.getArguments()[1]); + User guest = new User(); + User host = new User(); + host.getGuests().add(guest); + guest.getHosts().add(host); + + when(userRepository.findById(20L)).thenReturn(Optional.of(host)); + when(userRepository.findByUsername("user")).thenReturn(guest); MockHttpServletRequest request = new MockHttpServletRequest(); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));