Search in sources :

Example 21 with NotFoundEx

use of com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx in project 2021-msk-food-delivery by netcracker-edu.

the class UserServiceTest method getUserDTOByIdNotFound.

@Test
public void getUserDTOByIdNotFound() {
    Long userId = 0L;
    when(userRepoMock.findById(userId)).thenReturn(Optional.empty());
    Exception exception = assertThrows(NotFoundEx.class, () -> {
        userService.getUserDTOById(userId);
    });
    String resultMessage = exception.getMessage();
    String perfectMessage = new NotFoundEx(userId.toString()).getMessage();
    assertEquals(perfectMessage, resultMessage);
    verify(userRepoMock, times(1)).findById(userId);
}
Also used : NotFoundEx(com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx) AlreadyExistsException(com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException) PasswordsMismatchException(com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with NotFoundEx

use of com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx in project 2021-msk-food-delivery by netcracker-edu.

the class UserServiceTest method getUserByIdNotFound.

@Test
public void getUserByIdNotFound() {
    Long userId = 0L;
    when(userRepoMock.findById(userId)).thenReturn(Optional.empty());
    Exception exception = assertThrows(NotFoundEx.class, () -> {
        userService.getUserById(userId);
    });
    String resultMessage = exception.getMessage();
    String perfectMessage = new NotFoundEx(userId.toString()).getMessage();
    assertEquals(perfectMessage, resultMessage);
    verify(userRepoMock, times(1)).findById(userId);
}
Also used : NotFoundEx(com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx) AlreadyExistsException(com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException) PasswordsMismatchException(com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

NotFoundEx (com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx)20 Test (org.junit.jupiter.api.Test)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 ProductPosition (com.ncedu.fooddelivery.api.v1.entities.productPosition.ProductPosition)6 CustomAccessDeniedException (com.ncedu.fooddelivery.api.v1.errors.security.CustomAccessDeniedException)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 OrderProductPosition (com.ncedu.fooddelivery.api.v1.entities.orderProductPosition.OrderProductPosition)3 AlreadyExistsException (com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException)3 PasswordsMismatchException (com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException)3 ResponseEntity (org.springframework.http.ResponseEntity)3 WarehouseInfoDTO (com.ncedu.fooddelivery.api.v1.dto.warehouseDTOs.WarehouseInfoDTO)2 Client (com.ncedu.fooddelivery.api.v1.entities.Client)2 Order (com.ncedu.fooddelivery.api.v1.entities.order.Order)2 BadFileExtensionException (com.ncedu.fooddelivery.api.v1.errors.badrequest.BadFileExtensionException)2 ProductAvailabilityEx (com.ncedu.fooddelivery.api.v1.errors.orderRegistration.ProductAvailabilityEx)2 WarehouseCoordsBindingEx (com.ncedu.fooddelivery.api.v1.errors.orderRegistration.WarehouseCoordsBindingEx)2 IOException (java.io.IOException)2 UserChangeInfoDTO (com.ncedu.fooddelivery.api.v1.dto.user.UserChangeInfoDTO)1 File (com.ncedu.fooddelivery.api.v1.entities.File)1 Product (com.ncedu.fooddelivery.api.v1.entities.Product)1