Untitled

 avatar
unknown
plain_text
6 months ago
1.6 kB
3
Indexable
package onlineshopping;

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import onlineshopping.*;

import java.util.ArrayList;
import java.util.List;

public class ShoppingCartTest {
	private Product product1;
	private Product product2;
    private CartItem cartItem1;
    private CartItem cartItem2;
    private ShoppingCart cart;
    private DiscountService discountService;
    private Customer customer;
    
    @BeforeEach
    public void setUp() {
        // Sample products
        product1 = new Product("Laptop", 1000.00, 10);
        product2 = new Product("Mouse", 50.00, 20);

        // Cart items
        cartItem1 = new CartItem(product1, 1);  // 1 Laptop
        cartItem2 = new CartItem(product2, 2);  // 2 Mice

        // Customer setup (e.g., regular customer)
        customer = new Customer("Craig", CustomerType.REGULAR);

        // DiscountService instance
        discountService = new DiscountService();

        // ShoppingCart instance
        cart = new ShoppingCart(customer, discountService);
    }
    
    @Test
    public void testAddItemToCart() {
        cart.addItem(cartItem1);
        cart.addItem(cartItem2);
        
        // Verify items were added
        assertEquals(2, cart.getItems().size(), "Cart should contain two items.");
        assertEquals(cartItem1, cart.getItems().get(0), "First item should be the laptop.");
        assertEquals(cartItem2, cart.getItems().get(1), "Second item should be the mouse.");
    }
    
}
Editor is loading...
Leave a Comment