From 7d634c073994d526a7ff0f70d85fd4e6fb8f276a Mon Sep 17 00:00:00 2001 From: omenem Date: Tue, 26 May 2020 17:59:38 +0200 Subject: [PATCH] wip --- .../InputDeviceConnectionControllerTests.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/InputDeviceConnectionControllerTests.java diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/InputDeviceConnectionControllerTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/InputDeviceConnectionControllerTests.java new file mode 100644 index 0000000..1f24754 --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/InputDeviceConnectionControllerTests.java @@ -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 inputRepository; + + @Mock DeviceRepository 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 l = new ArrayList<>(); + l.add(10L); + + Connection toTest = knobDimmerController.addOutput(5L, l, "user"); + } +}