use of com.laurentiuspilca.springsecurityc2.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class ModeratorServiceTest method getModeratorByIdSuccess.
@Test
public void getModeratorByIdSuccess() {
Long userId = 1L;
User user = new User();
user.setId(userId);
user.setFullName("Howard Joel Wolowitz");
user.setRole(Role.MODERATOR);
Moderator moderator = new Moderator();
moderator.setUser(user);
moderator.setWarehouseId(1L);
when(moderatorRepoMock.findById(userId)).thenReturn(Optional.of(moderator));
Moderator result = moderatorService.getModeratorById(userId);
verify(moderatorRepoMock, times(1)).findById(userId);
assertEquals(moderator, result);
}
use of com.laurentiuspilca.springsecurityc2.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class ModeratorServiceTest method getModeratorDTObyIDSuccess.
@Test
public void getModeratorDTObyIDSuccess() {
Long userId = 1L;
User user = new User();
user.setId(userId);
user.setFullName("Howard Joel Wolowitz");
user.setRole(Role.MODERATOR);
Moderator moderator = new Moderator();
moderator.setUser(user);
moderator.setWarehouseId(1L);
when(moderatorRepoMock.findById(userId)).thenReturn(Optional.of(moderator));
ModeratorInfoDTO resultModeratorDTO = moderatorService.getModeratorDTOById(userId);
ModeratorInfoDTO perfectModeratorDTO = createModeratorDTO(moderator);
verify(moderatorRepoMock, times(1)).findById(userId);
assertEquals(perfectModeratorDTO, resultModeratorDTO);
}
use of com.laurentiuspilca.springsecurityc2.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceTest method changeEmailSuccess.
@Test
public void changeEmailSuccess() {
Long userId = 1L;
User howard = UserUtils.courierHowardWolowitz(userId);
String newEmail = "happy-howard@bigbang.theory";
User howardWithNewEmail = UserUtils.courierHowardWolowitz(userId);
howardWithNewEmail.setEmail(newEmail);
when(userRepoMock.findByEmail(newEmail)).thenReturn(null);
when(userRepoMock.save(howardWithNewEmail)).thenReturn(howardWithNewEmail);
String password = "password";
EmailChangeDTO changeDTO = new EmailChangeDTO();
changeDTO.setEmail(newEmail);
changeDTO.setPassword(password);
boolean result = userService.changeEmail(howard, changeDTO);
assertTrue(result);
verify(userRepoMock, times(1)).findByEmail(newEmail);
verify(userRepoMock, times(1)).save(howardWithNewEmail);
}
use of com.laurentiuspilca.springsecurityc2.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceTest method changeFullNameSuccess.
@Test
public void changeFullNameSuccess() {
Long userId = 1L;
User penny = UserUtils.clientPennyTeller(userId);
String newFullName = "Penny Hofstadter";
User pennyWithNewFullName = UserUtils.clientPennyTeller(userId);
pennyWithNewFullName.setFullName(newFullName);
when(userRepoMock.findById(userId)).thenReturn(Optional.of(penny));
when(userRepoMock.save(pennyWithNewFullName)).thenReturn(pennyWithNewFullName);
boolean result = userService.changeFullName(userId, newFullName);
assertTrue(result);
verify(userRepoMock, times(1)).findById(userId);
verify(userRepoMock, times(1)).save(pennyWithNewFullName);
}
use of com.laurentiuspilca.springsecurityc2.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceTest method setLastSigninSuccess.
@Test
public void setLastSigninSuccess() {
User howard = UserUtils.courierHowardWolowitz(1L);
Timestamp current = new Timestamp(System.currentTimeMillis());
howard.setLastSigninDate(current);
when(userRepoMock.save(any(User.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
userService.setLastSigninFromNow(howard);
assertTrue(current.before(howard.getLastSigninDate()));
verify(userRepoMock, times(1)).save(any());
}
Aggregations