Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.telerikacademy.oop.cosmetics.tests.models;
- import Utils.TestData;
- import com.telerikacademy.oop.cosmetics.core.ProductRepositoryImpl;
- import com.telerikacademy.oop.cosmetics.core.contracts.CommandFactory;
- import com.telerikacademy.oop.cosmetics.core.contracts.ProductRepository;
- import com.telerikacademy.oop.cosmetics.exceptions.InvalidUserInputException;
- import com.telerikacademy.oop.cosmetics.models.CategoryImpl;
- import com.telerikacademy.oop.cosmetics.models.GenderType;
- import com.telerikacademy.oop.cosmetics.models.ProductImpl;
- import com.telerikacademy.oop.cosmetics.models.contracts.Category;
- import com.telerikacademy.oop.cosmetics.models.contracts.Product;
- import org.junit.jupiter.api.Assertions;
- import org.junit.jupiter.api.Test;
- public class CategoryImplTests {
- @Test
- public void constructor_should_createCategory_when_argumentsAreValid() {
- ProductRepository repository = new ProductRepositoryImpl();
- repository.createCategory(TestData.CategoryData.VALID_NAME);
- Assertions.assertEquals(1,repository.getCategories().size());
- };
- @Test
- public void constructor_should_throwException_when_nameShorterThanExpected() {
- //Arrange, Act, Assert
- Assertions.assertThrows(InvalidUserInputException.class,() -> new CategoryImpl(TestData.CategoryData.INVALID_NAME));
- }
- @Test
- public void addProduct_should_addProductToList() {
- // Arrange
- Category category = new CategoryImpl(TestData.CategoryData.VALID_NAME);
- Product productToAdd = new ProductImpl(TestData.ProductData.VALID_NAME,
- TestData.ProductData.VALID_BRAND_NAME, 10, GenderType.MEN);
- category.addProduct(productToAdd);
- // Act, Assert
- Assertions.assertEquals(1, category.getProducts().size());
- }
- @Test
- public void removeProduct_should_removeProductFromList_when_pProductExist() {
- // Arrange, Act
- Category category = new CategoryImpl(TestData.CategoryData.VALID_NAME);
- Product product = new ProductImpl(TestData.ProductData.VALID_NAME, TestData.ProductData.VALID_BRAND_NAME, 10, GenderType.WOMEN);
- category.addProduct(product);
- category.removeProduct(product);
- // Act, Assert
- Assertions.assertEquals(0, category.getProducts().size());
- }
- @Test
- public void removeProduct_should_notRemoveProductFromList_when_productNotExist() {
- // Arrange, Act
- Category category = new CategoryImpl(TestData.CategoryData.VALID_NAME);
- Product productToAdd = new ProductImpl(TestData.ProductData.VALID_NAME, TestData.ProductData.VALID_BRAND_NAME, 10, GenderType.MEN);
- Product productToRemove = new ProductImpl(TestData.ProductData.VALID_NAME, TestData.ProductData.VALID_BRAND_NAME, 12, GenderType.UNISEX);
- category.addProduct(productToAdd);
- category.removeProduct(productToRemove);
- // Act, Assert
- Assertions.assertEquals(1,category.getProducts().size());
- }
- @Test
- public void should_Print_When_productsList_Is_Empty(){
- ProductRepository productRepository = new ProductRepositoryImpl();
- productRepository.createCategory(TestData.CategoryData.VALID_NAME);
- Category category = productRepository.findCategoryByName(TestData.CategoryData.VALID_NAME);
- Assertions.assertTrue(Boolean.parseBoolean(String.valueOf(String.format("#Category: %s%n #No product in this category",
- category.getName()).equals(category.print()))));
- }
- @Test
- public void should_Print_When_productsList_isNot_Empty(){
- ProductRepository productRepository = new ProductRepositoryImpl();
- productRepository.createCategory(TestData.CategoryData.VALID_NAME);
- Category category = productRepository.findCategoryByName(TestData.CategoryData.VALID_NAME);
- Product product = new ProductImpl(TestData.ProductData.VALID_NAME,TestData.ProductData.VALID_BRAND_NAME,25,GenderType.MEN);
- category.addProduct(product);
- Assertions.assertTrue(Boolean.parseBoolean(String.valueOf(String.format("#Category: %s%n#%s %s%n #Price: $%.2f%n #Gender: %s%n ===%n",
- category.getName(),
- product.getName(), product.getBrand(), product.getPrice(), product.getGender()).equals(category.print()))));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment