Skip to content

Instantly share code, notes, and snippets.

@ian-ellis
Created January 16, 2017 22:44
Show Gist options
  • Save ian-ellis/72225082c03f5e42adb2a50a51e2a18e to your computer and use it in GitHub Desktop.
Save ian-ellis/72225082c03f5e42adb2a50a51e2a18e to your computer and use it in GitHub Desktop.
private CatalogProductEntity mockProduct(String sku, String name, String brandName, Double price, Double specialPrice, List<String> imageUrls){
BrandEntity brand = mock(BrandEntity.class);
when(brand.getName()).thenReturn(brandName);
ArrayList<ImageEntity> images = new ArrayList<>();
for(String imageUrl : imageUrls){
ImageEntity imageEntity = mock(ImageEntity.class);
when(imageEntity.getUrl()).thenReturn(imageUrl);
images.add(imageEntity);
}
CatalogProductEntity product = mock(CatalogProductEntity.class);
when(product.getImages()).thenReturn(images);
when(product.getBrand()).thenReturn(brand);
when(product.getSku()).thenReturn(sku);
when(product.getName()).thenReturn(name);
when(product.getPrice()).thenReturn(price);
when(product.getSpecialPrice()).thenReturn(specialPrice);
return product;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment