use of com.laurentiuspilca.ssc6.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceTest method lockUserAlsoLocked.
@Test
public void lockUserAlsoLocked() {
User penny = UserUtils.clientPennyTeller(1L);
Timestamp current = new Timestamp(System.currentTimeMillis());
penny.setLockDate(current);
UserInfoDTO resultDTO = userService.lockUser(penny);
assertEquals(current, resultDTO.getLockDate());
verify(userRepoMock, never()).save(any(User.class));
}
use of com.laurentiuspilca.ssc6.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceTest method searchUsersSuccess.
@Test
public void searchUsersSuccess() {
User sheldonCooper = UserUtils.adminSheldonCooper(1L);
List<User> users = new ArrayList<>();
users.add(sheldonCooper);
Page<User> userPage = new PageImpl<>(users);
Pageable pageable = PageRequest.of(0, 2);
String searchPhrase = "sh co";
String resultSearchPhrase = "sh:* & co:*";
when(userRepoMock.searchUsers(resultSearchPhrase, pageable)).thenReturn(userPage);
List<UserInfoDTO> resultDTO = userService.searchUsers(searchPhrase, pageable);
List<UserInfoDTO> perfectDTO = new ArrayList<>();
perfectDTO.add(UserUtils.createUserDTO(sheldonCooper));
assertEquals(perfectDTO, resultDTO);
verify(userRepoMock, times(1)).searchUsers(resultSearchPhrase, pageable);
}
use of com.laurentiuspilca.ssc6.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceTest method changePasswordNewPassNotSame.
@Test
public void changePasswordNewPassNotSame() {
Long userId = 1L;
User rajesh = UserUtils.clientRajeshKoothrappali(userId);
String oldPass = "password";
String newPass = "koothrappali";
String newPass2 = "wrongNewPass";
PasswordChangeDTO passwordDTO = new PasswordChangeDTO();
passwordDTO.setNewPassword(newPass);
passwordDTO.setNewPasswordConfirm(newPass2);
passwordDTO.setOldPassword(oldPass);
Exception exception = assertThrows(PasswordsMismatchException.class, () -> {
userService.changePassword(rajesh, passwordDTO);
});
verify(userRepoMock, never()).save(any(User.class));
}
use of com.laurentiuspilca.ssc6.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceTest method deleteUserByIdSuccess.
@Test
public void deleteUserByIdSuccess() {
Long userId = 1L;
User rajesh = UserUtils.clientRajeshKoothrappali(userId);
when(userRepoMock.findById(userId)).thenReturn(Optional.of(rajesh));
doNothing().when(userRepoMock).delete(rajesh);
boolean result = userService.deleteUserById(userId);
assertTrue(result);
verify(userRepoMock, times(1)).findById(userId);
verify(userRepoMock, times(1)).delete(rajesh);
}
use of com.laurentiuspilca.ssc6.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceTest method getAllUsersSuccess.
@Test
public void getAllUsersSuccess() {
User penny = UserUtils.clientPennyTeller(1L);
User leonard = UserUtils.moderatorLeonardHofstadter(2L);
List<User> users = new ArrayList<>();
users.add(penny);
users.add(leonard);
Page<User> userPage = new PageImpl<>(users);
Pageable pageable = PageRequest.of(0, 2);
when(userRepoMock.findAll(pageable)).thenReturn(userPage);
List<UserInfoDTO> resultDTO = userService.getAllUsers(pageable);
List<UserInfoDTO> perfectDTO = users.stream().map(user -> UserUtils.createUserDTO(user)).collect(Collectors.toList());
assertEquals(perfectDTO, resultDTO);
verify(userRepoMock, times(1)).findAll(pageable);
}
Aggregations