medon3

Untitled

May 18th, 2022
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. package com.telerikacademy.oop.cosmetics.tests.models;
  2.  
  3. import Utils.TestData;
  4. import com.telerikacademy.oop.cosmetics.core.ProductRepositoryImpl;
  5. import com.telerikacademy.oop.cosmetics.core.contracts.CommandFactory;
  6. import com.telerikacademy.oop.cosmetics.core.contracts.ProductRepository;
  7. import com.telerikacademy.oop.cosmetics.exceptions.InvalidUserInputException;
  8. import com.telerikacademy.oop.cosmetics.models.CategoryImpl;
  9. import com.telerikacademy.oop.cosmetics.models.GenderType;
  10. import com.telerikacademy.oop.cosmetics.models.ProductImpl;
  11. import com.telerikacademy.oop.cosmetics.models.contracts.Category;
  12. import com.telerikacademy.oop.cosmetics.models.contracts.Product;
  13. import org.junit.jupiter.api.Assertions;
  14. import org.junit.jupiter.api.Test;
  15.  
  16. public class CategoryImplTests {
  17.  
  18. @Test
  19. public void constructor_should_createCategory_when_argumentsAreValid() {
  20. ProductRepository repository = new ProductRepositoryImpl();
  21. repository.createCategory(TestData.CategoryData.VALID_NAME);
  22. Assertions.assertEquals(1,repository.getCategories().size());
  23. };
  24.  
  25. @Test
  26. public void constructor_should_throwException_when_nameShorterThanExpected() {
  27.  
  28. //Arrange, Act, Assert
  29. Assertions.assertThrows(InvalidUserInputException.class,() -> new CategoryImpl(TestData.CategoryData.INVALID_NAME));
  30. }
  31.  
  32. @Test
  33. public void addProduct_should_addProductToList() {
  34.  
  35. // Arrange
  36. Category category = new CategoryImpl(TestData.CategoryData.VALID_NAME);
  37. Product productToAdd = new ProductImpl(TestData.ProductData.VALID_NAME,
  38. TestData.ProductData.VALID_BRAND_NAME, 10, GenderType.MEN);
  39. category.addProduct(productToAdd);
  40. // Act, Assert
  41. Assertions.assertEquals(1, category.getProducts().size());
  42. }
  43.  
  44. @Test
  45. public void removeProduct_should_removeProductFromList_when_pProductExist() {
  46.  
  47. // Arrange, Act
  48. Category category = new CategoryImpl(TestData.CategoryData.VALID_NAME);
  49. Product product = new ProductImpl(TestData.ProductData.VALID_NAME, TestData.ProductData.VALID_BRAND_NAME, 10, GenderType.WOMEN);
  50.  
  51. category.addProduct(product);
  52. category.removeProduct(product);
  53.  
  54. // Act, Assert
  55. Assertions.assertEquals(0, category.getProducts().size());
  56. }
  57.  
  58. @Test
  59. public void removeProduct_should_notRemoveProductFromList_when_productNotExist() {
  60.  
  61. // Arrange, Act
  62. Category category = new CategoryImpl(TestData.CategoryData.VALID_NAME);
  63. Product productToAdd = new ProductImpl(TestData.ProductData.VALID_NAME, TestData.ProductData.VALID_BRAND_NAME, 10, GenderType.MEN);
  64. Product productToRemove = new ProductImpl(TestData.ProductData.VALID_NAME, TestData.ProductData.VALID_BRAND_NAME, 12, GenderType.UNISEX);
  65.  
  66. category.addProduct(productToAdd);
  67. category.removeProduct(productToRemove);
  68.  
  69. // Act, Assert
  70. Assertions.assertEquals(1,category.getProducts().size());
  71. }
  72.  
  73. @Test
  74. public void should_Print_When_productsList_Is_Empty(){
  75. ProductRepository productRepository = new ProductRepositoryImpl();
  76. productRepository.createCategory(TestData.CategoryData.VALID_NAME);
  77. Category category = productRepository.findCategoryByName(TestData.CategoryData.VALID_NAME);
  78. Assertions.assertTrue(Boolean.parseBoolean(String.valueOf(String.format("#Category: %s%n #No product in this category",
  79. category.getName()).equals(category.print()))));
  80.  
  81. }
  82.  
  83. @Test
  84. public void should_Print_When_productsList_isNot_Empty(){
  85. ProductRepository productRepository = new ProductRepositoryImpl();
  86. productRepository.createCategory(TestData.CategoryData.VALID_NAME);
  87. Category category = productRepository.findCategoryByName(TestData.CategoryData.VALID_NAME);
  88. Product product = new ProductImpl(TestData.ProductData.VALID_NAME,TestData.ProductData.VALID_BRAND_NAME,25,GenderType.MEN);
  89. category.addProduct(product);
  90. Assertions.assertTrue(Boolean.parseBoolean(String.valueOf(String.format("#Category: %s%n#%s %s%n #Price: $%.2f%n #Gender: %s%n ===%n",
  91. category.getName(),
  92. product.getName(), product.getBrand(), product.getPrice(), product.getGender()).equals(category.print()))));
  93. }
  94.  
  95. }
  96.  
Advertisement
Add Comment
Please, Sign In to add comment