use of com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO 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.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO 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.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO 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);
}
use of com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceTest method lockUserSuccess.
@Test
public void lockUserSuccess() {
User penny = UserUtils.clientPennyTeller(1L);
when(userRepoMock.save(any(User.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
UserInfoDTO resultDTO = userService.lockUser(penny);
assertTrue(resultDTO.getLockDate() != null);
verify(userRepoMock, times(1)).save(any(User.class));
}
use of com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceTest method unlockUserAlsoUnlocked.
@Test
public void unlockUserAlsoUnlocked() {
User penny = UserUtils.clientPennyTeller(1L);
penny.setLockDate(null);
UserInfoDTO resultDTO = userService.unlockUser(penny);
assertEquals(null, resultDTO.getLockDate());
verify(userRepoMock, never()).save(any(User.class));
}
Aggregations