diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/CameraConfigurationServiceTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/CameraConfigurationServiceTests.java new file mode 100644 index 0000000..69d95dc --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/CameraConfigurationServiceTests.java @@ -0,0 +1,15 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.config; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +public class CameraConfigurationServiceTests { + + @Test + public void test() { + final CameraConfigurationService c = new CameraConfigurationService(); + c.setVideoUrl("cose"); + assertThat(c.getVideoUrl()).isEqualTo("cose"); + } +} diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/InputDeviceTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/InputDeviceTests.java new file mode 100644 index 0000000..269a051 --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/InputDeviceTests.java @@ -0,0 +1,14 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.models; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +public class InputDeviceTests { + + @Test + public void test() { + final InputDevice motionSensor = new MotionSensor(); + assertThat(motionSensor.getOutputs()).isEmpty(); + } +} diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/JWTUserDetailsServiceTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/JWTUserDetailsServiceTests.java new file mode 100644 index 0000000..684c241 --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/JWTUserDetailsServiceTests.java @@ -0,0 +1,34 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.when; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.UserRepository; +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.core.userdetails.UsernameNotFoundException; + +@ExtendWith({MockitoExtension.class}) +public class JWTUserDetailsServiceTests { + + @InjectMocks private JWTUserDetailsService jwtUserDetailsService; + + @Mock private UserRepository userRepository; + + @Test + public void testLoadByUsername() { + final User u = new User(); + u.setUsername("username"); + u.setPassword("password"); + when(userRepository.findByUsername("username")).thenReturn(u); + assertThatThrownBy(() -> jwtUserDetailsService.loadUserByUsername("username")) + .isInstanceOf(UsernameNotFoundException.class); + u.setEnabled(true); + assertThat(jwtUserDetailsService.loadUserByUsername("username")).isNotNull(); + } +}