Changed checkIfTheUserIsOnlineTest for exception case
@@ -41,6 +41,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.LocalDateTime;
+import java.time.Month;
import java.time.ZonedDateTime;
import java.util.*;
@@ -835,7 +836,7 @@ public class UserServiceImplTest {
@Test
void checkIfTheUserIsOnlineExceptionTest() {
- assertThrows(UserLastActivityTimeNotFoundException.class, () ->
+ assertThrows(WrongIdException.class, () ->
userService.checkIfTheUserIsOnline(null)
);
}
@@ -843,7 +844,9 @@ public class UserServiceImplTest {
@Test
void checkIfTheUserIsOnlineEqualsTrueTest() {
ReflectionTestUtils.setField(userService, "timeAfterLastActivity", 300000);
- Date userLastActivityTime = new Date();
+ LocalDateTime userLastActivityTime = LocalDateTime.now();
+ User user = ModelUtils.getUser();
+ when(userRepo.findById(anyLong())).thenReturn(Optional.of(user));
when(userRepo.findLastActivityTimeById(anyLong())).thenReturn(Optional.of(userLastActivityTime));
assertTrue(userService.checkIfTheUserIsOnline(1L));
}
@@ -851,9 +854,11 @@ public class UserServiceImplTest {
@Test
void checkIfTheUserIsOnlineEqualsFalseTest() {
ReflectionTestUtils.setField(userService, "timeAfterLastActivity", 300000);
- Date userLastActivityTime = new Date(System.currentTimeMillis() - 300000);
+ LocalDateTime userLastActivityTime = LocalDateTime.of(2015,
+ Month.JULY, 29, 19, 30, 40);
+ User user = ModelUtils.getUser();
+ when(userRepo.findById(anyLong())).thenReturn(Optional.of(user));
when(userRepo.findLastActivityTimeById(anyLong())).thenReturn(Optional.of(userLastActivityTime));
assertFalse(userService.checkIfTheUserIsOnline(1L));
}
-
}
\ No newline at end of file
