Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.3 kB
1
Indexable
Never
package gr.athtech.model;

import gr.athtech.model.Customer;
import org.junit.jupiter.api.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.junit.jupiter.api.Assertions.fail;

@DisplayName("Customer test")
public class CustomerTest {
    private static final Logger logger = LoggerFactory.getLogger(Main.class);

    private CartService cartService;

    @BeforeEach
    void initializeForEachTest(){
        logger.info("hello before each test");
        cartService = new CartService(500);
    }

    @Nested
    @DisplayName("when trying to add an item")
    class Added {
        @Test
        @DisplayName("which is correct, it should be added to the cart as expected")
        public void addsItemCorrectly(){
            Item item = new Item("Not Iphone", 100, 1);
            cartService.addItem(item);
            if(cartService.getCartItems().size() < 1){
                fail();
            }
        }

        @Test
        @DisplayName("which has 0 quantity, it should not be added to the cart")
        public void addsItemIncorrectly(){
            Item item = new Item("Not Iphone", 100, 0);
            cartService.addItem(item);
            if(cartService.getCartItems().size() > 0){
                fail();
            }
        }
    }
}