Skip to content
Snippets Groups Projects
Commit 584a43fd authored by Pedro Pablo Cardona Arroyave's avatar Pedro Pablo Cardona Arroyave
Browse files

A test was fixed

parent 7ab5e7f4
No related branches found
No related tags found
No related merge requests found
package ntnu.idatt2016.v233.SmartMat.controller.product; package ntnu.idatt2016.v233.SmartMat.controller.product;
import ntnu.idatt2016.v233.SmartMat.dto.request.ProductRequest; import ntnu.idatt2016.v233.SmartMat.dto.request.ProductRequest;
import ntnu.idatt2016.v233.SmartMat.entity.product.Allergy;
import ntnu.idatt2016.v233.SmartMat.entity.product.Category; import ntnu.idatt2016.v233.SmartMat.entity.product.Category;
import ntnu.idatt2016.v233.SmartMat.entity.product.Product; import ntnu.idatt2016.v233.SmartMat.entity.product.Product;
import ntnu.idatt2016.v233.SmartMat.service.AllergyService; import ntnu.idatt2016.v233.SmartMat.service.AllergyService;
...@@ -31,6 +32,9 @@ public class ProductControllerTest { ...@@ -31,6 +32,9 @@ public class ProductControllerTest {
@Mock @Mock
private CategoryService categoryService; private CategoryService categoryService;
@Mock
private AllergyService allergyService;
@InjectMocks @InjectMocks
private ProductController productController; private ProductController productController;
...@@ -42,14 +46,17 @@ public class ProductControllerTest { ...@@ -42,14 +46,17 @@ public class ProductControllerTest {
.name("Test Product") .name("Test Product")
.description("A test product kylling") .description("A test product kylling")
.image("http://test.com/image.jpg") .image("http://test.com/image.jpg")
.allergies(List.of("Gluten", "Melk"))
.build(); .build();
when(productService.getProductById(123L)).thenReturn(Optional.empty()); when(productService.getProductById(123L)).thenReturn(Optional.empty());
when(productService.getProductVolume(123L)).thenReturn(Optional.of(List.of("1", "kg"))); when(productService.getProductVolume(123L)).thenReturn(Optional.of(List.of("1", "kg")));
when(categoryService.getCategoryByName(anyString())).thenReturn(Optional.of(Category.builder() when(categoryService.getCategoryByName(anyString())).thenReturn(Optional.of(Category.builder()
.categoryName("Kjøtt") .categoryName("Kjøtt")
.build())); .build()));
when(allergyService.getAllergyByName(anyString())).thenReturn(Optional.of(Allergy.builder().name("test-allergy").build()));
// Act // Act
ResponseEntity<Product> response = productController.createProduct(productRequest); ResponseEntity<Product> response = productController.createProduct(productRequest);
Product product = response.getBody(); Product product = response.getBody();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment