Commit 1efa4fc9 authored by Jakub Balga's avatar Jakub Balga
Browse files

User tests - passing

parent f46fdecb
Pipeline #131957 passed with stages
in 1 minute and 55 seconds
......@@ -43,9 +43,8 @@ public class UserTests extends PersistenceServiceTestBase<UserDto, User> {
@Test
void testGetAllByRole() {
getPersistenceService();
var dao = getMockedDao();
Mockito.when(((UserDao)dao).getAll(UserRoleType.ADMIN)).thenReturn(List.of(getTestEntity()));
Mockito.when((userDao).getAll(UserRoleType.ADMIN)).thenReturn(List.of(getTestEntity()));
userService = new UserServiceImpl(userDao, userEntityMapper);
var dto = userService.getAll(UserRoleType.ADMIN);
assertThat(equals(dto.get(0), getTestEntity())).isTrue();
}
......@@ -58,15 +57,7 @@ public class UserTests extends PersistenceServiceTestBase<UserDto, User> {
userDto.setFirstName("John");
userDto.setLastName("Brown");
userDto.setPasswordHash("pass");
userDto.setReviewIds(List.of(1L));
userDto.setOrderIds(List.of(1L));
var roleDto = new UserRoleDto();
roleDto.setId(1);
roleDto.setRole(UserRoleType.ADMIN);
roleDto.setUserId(1);
userDto.setRoles(Set.of(roleDto));
userDto.setRoles(List.of(UserRoleType.USER, UserRoleType.ADMIN));
return userDto;
}
......@@ -79,25 +70,14 @@ public class UserTests extends PersistenceServiceTestBase<UserDto, User> {
user.setLastName("Brown");
user.setPasswordHash("pass");
var review = new ProductReview();
review.setId(1);
review.setGrade((short)3);
review.setUser(user);
var order = new Order();
order.setId(1);
order.setShipped(true);
order.setDateTime(LocalDateTime.of(2022, 1, 1, 0, 0));
order.setUser(user);
var role = new UserRole();
role.setId(1);
role.setRole(UserRoleType.ADMIN);
role.setUser(user);
user.setReviews(Set.of(review));
user.setOrders(Set.of(order));
user.setRoles(Set.of(role));
var roleAdmin = new UserRole();
roleAdmin.setId(2);
roleAdmin.setRole(UserRoleType.USER);
roleAdmin.setUser(user);
var roleUser = new UserRole();
roleUser.setId(3);
roleUser.setRole(UserRoleType.ADMIN);
roleUser.setUser(user);
return user;
}
......@@ -111,15 +91,10 @@ public class UserTests extends PersistenceServiceTestBase<UserDto, User> {
userDto.getLastName().equals(user.getLastName()) &&
userDto.getPasswordHash().equals(user.getPasswordHash());
var reviewEquals =
userDto.getReviewIds().equals(user.getReviews().stream().map(rev -> rev.getId()).collect(Collectors.toList()));
var orderEquals =
userDto.getOrderIds().equals(user.getOrders().stream().map(ord -> ord.getId()).collect(Collectors.toList()));
var roleEquals =
userDto.getRoles().stream().map(rol -> rol.getId()).collect(Collectors.toSet()).equals(
user.getRoles().stream().map(rol -> rol.getId()).collect(Collectors.toSet()));
var roleEquals = Set.copyOf(userDto.getRoles()).equals(
user.getRoles().stream().map(role -> role.getRole()).collect(Collectors.toSet()));
return attributeEquals && reviewEquals && orderEquals && roleEquals;
return attributeEquals && roleEquals;
}
@Override
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment