use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.
the class ProductServiceTest method getProductDTOByIdInShowCaseSuccess.
@Test
public void getProductDTOByIdInShowCaseSuccess() {
Long productId = 1L;
Product product = ProductUtils.createMilkInShowcase(productId);
when(productRepoMock.findById(productId)).thenReturn(Optional.of(product));
ProductDTO resultDTO = productService.getProductDTOByIdInShowcase(productId);
ProductDTO perfectDTO = ProductUtils.createProductDTO(product);
verify(productRepoMock, times(1)).findById(productId);
assertEquals(perfectDTO, resultDTO);
}
use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.
the class ProductServiceTest method getProductsNullResult.
@Test
public void getProductsNullResult() {
Pageable pageable = PageRequest.of(0, 2);
Page<Product> productsPage = new PageImpl<>(new ArrayList<Product>(), pageable, 0);
Long warehouseId = 4L;
Point geo = makeGeo();
WarehouseInfoDTO warehouseInfoDTO = new WarehouseInfoDTO(warehouseId, null, null, null, null, false);
when(warehouseServiceMock.getNearestWarehouse(geo)).thenReturn(warehouseInfoDTO);
when(productRepoMock.findAll(warehouseId, pageable)).thenReturn(productsPage);
CoordsDTO coordsDTO = makeCoordsDTO();
List<ProductDTO> resultList = productService.getProducts(coordsDTO, pageable);
List<ProductDTO> perfectList = new ArrayList<>();
verify(warehouseServiceMock, times(1)).getNearestWarehouse(geo);
verify(productRepoMock, times(1)).findAll(warehouseId, pageable);
assertEquals(perfectList, resultList);
}
use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.
the class ProductServiceTest method getProductDTOByIdInShowCaseError.
@Test
public void getProductDTOByIdInShowCaseError() {
Long productId = 1L;
Product product = ProductUtils.createMilkNOTinShowcase(productId);
when(productRepoMock.findById(productId)).thenReturn(Optional.of(product));
Exception exception = assertThrows(NotFoundEx.class, () -> {
productService.getProductDTOByIdInShowcase(productId);
});
String resultMessage = exception.getMessage();
String perfectMessage = new NotFoundEx(productId.toString()).getMessage();
verify(productRepoMock, times(1)).findById(productId);
assertEquals(perfectMessage, resultMessage);
}
use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.
the class ProductServiceTest method getProductsSuccess.
// TODO: rewrite tests!!!
@Test
public void getProductsSuccess() {
Pageable pageable = PageRequest.of(0, 2);
Page<Product> productsPage = ProductUtils.createPageWithMilkProducts(pageable);
Long warehouseId = 4L;
Point geo = makeGeo();
WarehouseInfoDTO warehouseInfoDTO = new WarehouseInfoDTO(warehouseId, null, null, null, null, false);
when(warehouseServiceMock.getNearestWarehouse(geo)).thenReturn(warehouseInfoDTO);
when(productRepoMock.findAll(warehouseId, pageable)).thenReturn(productsPage);
CoordsDTO coordsDTO = makeCoordsDTO();
List<ProductDTO> resultList = productService.getProducts(coordsDTO, pageable);
List<ProductDTO> perfectList = ProductUtils.createProductDTOListFromPage(productsPage);
verify(warehouseServiceMock, times(1)).getNearestWarehouse(geo);
verify(productRepoMock, times(1)).findAll(warehouseId, pageable);
assertEquals(perfectList, resultList);
}
use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.
the class ProductUtils method createPageWithMilkProducts.
public static Page<Product> createPageWithMilkProducts(Pageable pageable) {
Product milk = createMilkInShowcase(1L);
Product milkElite = createMilkNOTinShowcase(2L);
List<Product> products = new ArrayList<>();
products.add(milkElite);
products.add(milk);
return new PageImpl<Product>(products, pageable, products.size());
}
Aggregations