diff --git a/src/main/java/com/booleanuk/core/Basket.java b/src/main/java/com/booleanuk/core/Basket.java new file mode 100644 index 000000000..b53081c69 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Basket.java @@ -0,0 +1,69 @@ +package com.booleanuk.core; + +import com.booleanuk.core.Products.Bagel; + +import java.util.ArrayList; + +public class Basket { + private ArrayList bagels = new ArrayList<>(); + private String basketType; + private int capacity; + + public Basket(String basketType, int capacity) { + setBasketType(basketType); + setCapacity(capacity); + } + + public String getBasketType() { + return basketType; + } + + public void setBasketType(String basketType) { + if (basketType == null || basketType.toLowerCase().trim().isEmpty()) + basketType = "small"; + + this.basketType = basketType; + } + + public int getCapacity() { + return capacity; + } + + public boolean isFull() { + return bagels.size() == this.capacity; + } + + public void setCapacity(int capacity) { + if (capacity <= 0) + capacity = 5; + + this.capacity = capacity; + } + + public ArrayList getBagels() { + return bagels; + } + +// public void setBagels(ArrayList bagels) { +// this.bagels = bagels; +// } + + public boolean addBagel(Bagel bagel) { + if (!isFull()) + return bagels.add(bagel); + return false; + } + + public boolean removeBagel(Bagel bagel) { + return bagels.remove(bagel); + } + + public float getTotalCost() { + float totCost = 0; + for (Bagel bagel: bagels) + totCost += bagel.getPrice(); + + return totCost; + } + +} diff --git a/src/main/java/com/booleanuk/core/Customer.java b/src/main/java/com/booleanuk/core/Customer.java new file mode 100644 index 000000000..98b678c85 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Customer.java @@ -0,0 +1,100 @@ +package com.booleanuk.core; + +import com.booleanuk.core.Products.Bagel; +import com.booleanuk.core.Products.Filling; +import com.booleanuk.core.Products.Product; + +import java.sql.Time; +import java.util.ArrayList; +import java.util.List; + +public class Customer { + private Basket basket = null; +// private Inventory inventory = null; + private List products = null; + + public Customer(Basket basket, List inventory) { + this.basket = basket; + this.products = inventory; + } + + public void addBagelToBasket(Bagel bagel) { + for (Product p: products) + if (p.getSku().equals(bagel.getSku())) { + if (basket.addBagel(bagel)) { + System.out.println("Added to basket."); + break; + } else + System.out.println("Basket is full, you cant add more bagelZ"); + } + } + + public void removeBagelFromBasket(Bagel bagel) { + if (basket.removeBagel(bagel)) + System.out.println("Bagel removed from basket"); + else + System.out.println("Nothing to remove."); + } + + public float getTotalCost() { + ArrayList bagels = basket.getBagels(); + + float totCost = 0; + for (Bagel bagel : bagels) + totCost += bagel.getPrice(); + + return totCost; + } + + public float getBagelPrice(Bagel bagel) { + ArrayList bagels = basket.getBagels(); + for (Bagel b : bagels) + if (b.getSku().equals(bagel.getSku())) + return b.getPrice(); + + return -1; + } + + public void viewFillingsAndPrice() { + for (Product product: products) + if (product.getType() == Product.ProductType.FILLING) { + System.out.printf("Filling: %-20s --> %.2f SEK\n", product.getVariant(), product.getPrice()); + } + } + + public Bagel getBagelAndPickFilling(String filling){ + Filling fill = (Filling) products.stream() + .filter(product -> product.getType() == Product.ProductType.FILLING && + product.getVariant().equalsIgnoreCase(filling.trim())) + .map(product -> (Filling) product).findFirst().orElse(null); + + Bagel bagel = (Bagel) products.stream() + .filter(product -> product.getType() == Product.ProductType.BAGEL && + product.getVariant().equalsIgnoreCase("plain")) + .map(product -> (Bagel) product).findFirst().orElse(null); + + if (bagel != null && fill != null) + bagel.setFilling(fill); + basket.addBagel(bagel); + System.out.printf("Bagel with %s added. \n", fill.getVariant()); + +// bagel.setFilling(fill); +// basket.addBagel(bagel); + + return bagel; + } + + public String orderBagelAtSpecificTime(Time time, String bagelType) { + + Bagel bagel = (Bagel) products.stream().filter(product -> product.getVariant() + .equalsIgnoreCase(bagelType)) + .map(product -> (Bagel) product).findFirst().orElse(null); + + return (bagel != null) ? "Order: " + time + ", Bagel: " + bagel.toString() : "Camon little boy"; + } + + public int getAmountOfBagelsInBasket() { + return this.basket.getBagels().size(); + } + +} diff --git a/src/main/java/com/booleanuk/core/Inventory.java b/src/main/java/com/booleanuk/core/Inventory.java new file mode 100644 index 000000000..7cc25f489 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Inventory.java @@ -0,0 +1,39 @@ +package com.booleanuk.core; + +import com.booleanuk.core.Products.Product; + +import java.util.ArrayList; +import java.util.List; + +public class Inventory { + private List products = new ArrayList<>(); + + public void addProduct(Product product) { + products.add(product); + } + + public void removeProduct(Product product) { + products.remove(product); + } + + public List getInventoryList() { + return this.products; + } + + public Product getProduct(Product.ProductType type, String variant) { + for (Product p: products) + if (p.getType() == type && p.getVariant().toLowerCase().equals(variant.toLowerCase().trim())) + return p; + return null; + } + + public void printInventory() { + for (Product p : products) { + System.out.println(p); +// if (p instanceof Bagel) { +// System.out.println("ISSA BAGEL"); +// } + } + } + +} diff --git a/src/main/java/com/booleanuk/core/Main.java b/src/main/java/com/booleanuk/core/Main.java new file mode 100644 index 000000000..41ed9f191 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Main.java @@ -0,0 +1,93 @@ +package com.booleanuk.core; + +import com.booleanuk.core.Products.Bagel; +import com.booleanuk.core.Products.Filling; +import com.booleanuk.core.Products.Product; + +import java.sql.Time; +import java.util.List; + +public class Main { + public static void main(String[] args) { + System.out.println("\n"); + // Load inventory on start + Inventory inv = loadInventoryOnStart(); + List list = inv.getInventoryList(); + // inv.printInventory(); + + Basket basket = new Basket("small", 5); + Customer customer = new Customer(basket, list); + + Bagel bagel1 = new Bagel("BGLO", 0.49f, "Onion", Product.ProductType.BAGEL); + Bagel bagel2 = new Bagel("BGLP", 0.39f, "Plain", Product.ProductType.BAGEL); + Bagel bagel3 = new Bagel("BGLE", 0.49f, "Everything", Product.ProductType.BAGEL); + Bagel bagel4 = new Bagel("BGLS", 0.49f, "Sesame", Product.ProductType.BAGEL); + Bagel bagel5 = new Bagel("BGLS", 0.49f, "Sesame", Product.ProductType.BAGEL); + Bagel bagel6 = new Bagel("BGLS", 0.49f, "Sesame", Product.ProductType.BAGEL); + + // Story 1: + Time time = Time.valueOf("07:45:00"); + String s = customer.orderBagelAtSpecificTime(time, "everything"); + System.out.println(s); + + // Story 2: + customer.addBagelToBasket(bagel1); + customer.removeBagelFromBasket(bagel1); + + // Story 3: + customer.addBagelToBasket(bagel1); + customer.addBagelToBasket(bagel2); + customer.addBagelToBasket(bagel3); + customer.addBagelToBasket(bagel4); + customer.addBagelToBasket(bagel5); + customer.addBagelToBasket(bagel6); // full + + // Story 4: + Manager manager = new Manager(inv); + manager.changeBasketCapacity(basket, 10); + customer.addBagelToBasket(bagel6); // not full anymore + + // Story 5: + customer.removeBagelFromBasket(bagel1); // should remove + customer.removeBagelFromBasket(bagel1); // nothing to remove + + // Story 6: + System.out.println(customer.getTotalCost()); + + // Story 7: + System.out.println(customer.getBagelPrice(bagel4)); + + // Story 8 and 9: + customer.viewFillingsAndPrice(); + customer.getBagelAndPickFilling("cheese"); + + // Story 10: + Bagel test = new Bagel("sku123", 10f, "test", Product.ProductType.BAGEL); + Bagel test2 = new Bagel("sku999", 10f, "test", Product.ProductType.BAGEL); + manager.addItemToInv(test); + customer.addBagelToBasket(test); // should work + customer.addBagelToBasket(test2); // should not work + } + + public static Inventory loadInventoryOnStart() { + // Add all items to the inventory + Inventory inventory = new Inventory(); + // Add Bagels + inventory.addProduct(new Bagel("BGLO", 0.49f, "Onion", Product.ProductType.BAGEL)); + inventory.addProduct(new Bagel("BGLP", 0.39f, "Plain", Product.ProductType.BAGEL)); + inventory.addProduct(new Bagel("BGLE", 0.49f, "Everything", Product.ProductType.BAGEL)); + inventory.addProduct(new Bagel("BGLS", 0.49f, "Sesame", Product.ProductType.BAGEL)); + + // Add Fillings + inventory.addProduct(new Filling("FILB", 0.12f, "Bacon", Product.ProductType.FILLING)); + inventory.addProduct(new Filling("FILE", 0.12f, "Egg", Product.ProductType.FILLING)); + inventory.addProduct(new Filling("FILC", 0.12f, "Cheese", Product.ProductType.FILLING)); + inventory.addProduct(new Filling("FILX", 0.12f, "Cream Cheese", Product.ProductType.FILLING)); + inventory.addProduct(new Filling("FILS", 0.12f, "Smoked Salmon", Product.ProductType.FILLING)); + inventory.addProduct(new Filling("FILH", 0.12f, "Ham", Product.ProductType.FILLING)); + + // Add Coffees + + return inventory; + } +} diff --git a/src/main/java/com/booleanuk/core/Manager.java b/src/main/java/com/booleanuk/core/Manager.java new file mode 100644 index 000000000..331d5b8d6 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Manager.java @@ -0,0 +1,25 @@ +package com.booleanuk.core; + + +import com.booleanuk.core.Products.Product; + +public class Manager { + private Inventory inventory; + + public Manager(Inventory inventory) { + this.inventory = inventory; + } + + public void changeBasketCapacity(Basket basket, int num) { + basket.setCapacity(num); + } + + public void addItemToInv(Product product) { + inventory.addProduct(product); + } + + public void removeItemToInv(Product product) { + inventory.removeProduct(product); + } + +} \ No newline at end of file diff --git a/src/main/java/com/booleanuk/core/Products/Bagel.java b/src/main/java/com/booleanuk/core/Products/Bagel.java new file mode 100644 index 000000000..5f59ac636 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Products/Bagel.java @@ -0,0 +1,43 @@ +package com.booleanuk.core.Products; + +public class Bagel extends Product { + private Filling filling; + + public Bagel(String sku, float price, String variant, ProductType type) { + super(sku, price, variant, type); + + setPrice(price); + } + + public void setPrice(float price) { + if (price <= 0) + throw new IllegalArgumentException("Price must be more than 0"); + + super.setPrice(price); + } + + @Override + public float getPrice() { + if (filling != null) + return super.getPrice() + filling.getPrice(); + else + return super.getPrice(); + } + + public Filling getFilling() { + return this.filling; + } + + public void setFilling(Filling filling) { + this.filling = filling; + } + + public float getFillingCost() { + return (this.filling != null) ? this.filling.getPrice() : 0f; + } + + @Override + public String toString() { + return this.getVariant(); + } +} diff --git a/src/main/java/com/booleanuk/core/Products/Filling.java b/src/main/java/com/booleanuk/core/Products/Filling.java new file mode 100644 index 000000000..27a4e07ca --- /dev/null +++ b/src/main/java/com/booleanuk/core/Products/Filling.java @@ -0,0 +1,50 @@ +package com.booleanuk.core.Products; + +public class Filling extends Product { + + public Filling(String sku, float price, String variant, ProductType type) { + super(sku, price, variant, type); + + setPrice(price); + setSku(sku); + } + + public float getPrice() { + return super.getPrice(); + } + + public void setPrice(float price) { + if (price < 0) + price = 1f; + super.setPrice(price); + } + + public String getSku() { + return super.getSku(); + } + + public void setSku(String sku) { + if (sku.toUpperCase().trim().isEmpty()) + sku = "FIL"; + + String upperCase = sku.toUpperCase().trim(); + + super.setSku(upperCase); + } + + public String getVariant() { + return super.getVariant(); + } + + public void setVariant(String variant) { + if (variant.trim().isEmpty()) + variant = "plain"; + + super.setVariant(variant); + } + + @Override + public String toString() { + return this.getVariant(); + } +} \ No newline at end of file diff --git a/src/main/java/com/booleanuk/core/Products/Product.java b/src/main/java/com/booleanuk/core/Products/Product.java new file mode 100644 index 000000000..11e23bd56 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Products/Product.java @@ -0,0 +1,57 @@ +package com.booleanuk.core.Products; + +public abstract class Product { + private String sku; + private float price; + private String variant; + private ProductType type; + + public Product(String sku, float price, String variant, ProductType type) { + setSku(sku); + setPrice(price); + setVariant(variant); + this.type = type; + } + + // Getters and setters + public String getSku() { + return sku; + } + + public void setSku(String sku) { + this.sku = sku; + } + + public float getPrice() { + return this.price; + } + + public void setPrice(float price) { + if (price == 0f || price < 0f) { + throw new IllegalArgumentException("Price must be greater than zero"); + } + + this.price = price; + } + + public String getVariant() { + return variant; + } + + public void setVariant(String variant) { + this.variant = variant; + } + + public Enum getType() { + return this.type; + } + + @Override + public String toString() { + return "Product [SKU=" + sku + ", Price=" + price + ", Variant=" + variant + "]"; + } + + public enum ProductType { + FILLING, BAGEL, COFFEE; + } +} diff --git a/src/main/java/com/booleanuk/core/models/domain-model.md b/src/main/java/com/booleanuk/core/models/domain-model.md new file mode 100644 index 000000000..a907ad004 --- /dev/null +++ b/src/main/java/com/booleanuk/core/models/domain-model.md @@ -0,0 +1,27 @@ +| **Classes** | **Methods** | **Scenario** | **Outputs** | +|-------------|-------------------------------------------|------------------------------------------------------------|------------------------------------------------| +| `Basket` | `addBagel(Bagel bagel)` | If user adds a bagel to an empty basket | Adds the bagel to the basket | +| | | If user adds a bagel and basket is full | Error message: "Basket is full." | +| | `removeBagel(Bagel bagel)` | If user tries to remove a bagel in the basket | Removes the bagel from the basket | +| | | If user tries to remove a bagel not in the basket | Error message: "Item not in basket." | +| | `getTotalCost()` | When the user checks the total cost of the basket | Returns total price of all items in the basket | +| | `isBasketFull()` | When customer tries to add new -> check if full | Returns true if full | +| `Bagel` | `getPrice()` | If user checks the price of a specific bagel | Returns price of the bagel | +| | `chooseFillings(List fillings)` | If user selects fillings for a bagel | Updates the bagel with selected fillings | +| | `getFillingCost(List fillings)` | If user checks the cost of fillings | Returns total cost of selected fillings | +| `Manager` | `changeBasketCapacity(int capacity)` | If manager decides to change basket capacity | Updates basket capacity | +| | `addToInventory(Bagel bagel)` | If manager adds new item to inventory not in inventory | Updates inventory | +| | | If manager adds new item which is in inventory | Returns error: "Item already exists." | +| `Customer` | `addBagelToBasket(String stu)` | If customer adds a bagel to their basket | Adds the bagel to the basket | +| | | If the bagel is out of stock | Returns error: "Bagel out of stock." | +| | | If the bagel is out of stock | Returns error: "Bagel out of stock." | +| | `removeBagelFromBasket(String stu)` | If customer removes a bagel from their basket | Removes the bagel from the basket | +| | | If the bagel is not in the basket | Returns error: "Bagel not in basket." | +| | `viewTotalCost()` | If customer checks the total cost of items in their basket | Returns total cost of all items in the basket | +| | `viewBagelPrice(Bagel bagel)` | If customer checks the price of a specific bagel | Returns price of the selected bagel | +| | `selectFillings(int option)` | If customer selects fillings for a bagel | Updates the bagel with selected fillings | +| | `viewFillingCost(List fillings)` | If customer checks the cost of selected fillings | Returns total cost of selected fillings | +| | `orderBagelAtSpecificTime` | If customer wants to order bagel before set time | | +| `Inventory` | `addItem` | If manager wants to add new item to inventory | Update inventory | +| | `removeItem` | If manager wants to remove item from inventory | Remove item from inventory | +| `Filling` | `` | | | \ No newline at end of file diff --git a/src/main/java/com/booleanuk/core/models/firstSc.png b/src/main/java/com/booleanuk/core/models/firstSc.png new file mode 100644 index 000000000..9e8896fb1 Binary files /dev/null and b/src/main/java/com/booleanuk/core/models/firstSc.png differ diff --git a/src/test/java/com/booleanuk/core/BagelTest.java b/src/test/java/com/booleanuk/core/BagelTest.java new file mode 100644 index 000000000..28637d172 --- /dev/null +++ b/src/test/java/com/booleanuk/core/BagelTest.java @@ -0,0 +1,39 @@ +package com.booleanuk.core; + +import static org.junit.jupiter.api.Assertions.*; + +import com.booleanuk.core.Products.Bagel; +import com.booleanuk.core.Products.Filling; +import com.booleanuk.core.Products.Product; +import org.junit.jupiter.api.Test; + +public class BagelTest { + + + @Test + public void bagelFillingShouldReturnFillingOrErrorMsg() { + Bagel bagel = new Bagel("test", 10, "nice one", Product.ProductType.BAGEL); + assertNull(bagel.getFilling()); + Bagel bagel2 = new Bagel("test", 10, "nice one", Product.ProductType.BAGEL); + Filling filling = new Filling("SKU", 0.5f, "filling", Product.ProductType.FILLING); + assertEquals(0.5f, filling.getPrice()); + filling.setPrice(0.13f); + bagel2.setFilling(filling); + assertEquals(0.13f, bagel2.getFilling().getPrice()); + } + + @Test + public void getCorrectFillingCost() { + Bagel bagel = new Bagel("SKU1", 10f, "nice one", Product.ProductType.BAGEL); + Filling filling = new Filling("SKU", 0.5f, "filling", Product.ProductType.FILLING); + assertEquals(10f, bagel.getPrice()); + bagel.setFilling(filling); + assertEquals(10.5f, bagel.getPrice()); + filling.setPrice(0.13f); + assertEquals(10.13f, bagel.getPrice()); + + assertThrows(IllegalArgumentException.class, () -> bagel.setPrice(0)); + assertDoesNotThrow(() -> bagel.setPrice(1)); + } + +} diff --git a/src/test/java/com/booleanuk/core/BasketTest.java b/src/test/java/com/booleanuk/core/BasketTest.java new file mode 100644 index 000000000..ce7160b83 --- /dev/null +++ b/src/test/java/com/booleanuk/core/BasketTest.java @@ -0,0 +1,50 @@ +package com.booleanuk.core; + +import static org.junit.jupiter.api.Assertions.*; + +import com.booleanuk.core.Products.Bagel; +import com.booleanuk.core.Products.Product; +import org.junit.jupiter.api.Test; + +public class BasketTest { + + @Test + public void testBasketConstructor() { + Basket basket = new Basket("small", 10); + assertEquals(10, basket.getCapacity()); + assertNotNull(basket.getBasketType()); + + Basket basket2 = new Basket(" ", 0); + assertNotEquals(0, basket2.getCapacity()); // Should default to 5; + assertEquals(5, basket2.getCapacity()); + assertNotNull(basket2.getBasketType()); // should default to small + } + + @Test + public void setBasketTypeNotNull() { + Basket basket = new Basket("small", 5); + + basket.setBasketType("medium"); + assertNotNull(basket.getBasketType()); + basket.setBasketType(""); + assertNotNull(basket.getBasketType()); + basket.setBasketType(" ab"); + assertNotNull(basket.getBasketType()); + basket.setBasketType(null); + assertNotNull(basket.getBasketType()); + } + + @Test + public void getTotalCostOfBasket() { + Basket basket = new Basket("", 0); + Bagel bagel = new Bagel("sku", 10, "nice one", Product.ProductType.BAGEL); + + basket.addBagel(bagel); + assertEquals(10, basket.getTotalCost()); + Bagel bagel2 = new Bagel("sku2", 55, "good one", Product.ProductType.BAGEL); + basket.addBagel(bagel2); + assertEquals(65, basket.getTotalCost()); + basket.removeBagel(bagel); + assertEquals(55, basket.getTotalCost()); + } +} diff --git a/src/test/java/com/booleanuk/core/CustomerTest.java b/src/test/java/com/booleanuk/core/CustomerTest.java new file mode 100644 index 000000000..d86d8a16a --- /dev/null +++ b/src/test/java/com/booleanuk/core/CustomerTest.java @@ -0,0 +1,91 @@ +package com.booleanuk.core; + +import static org.junit.jupiter.api.Assertions.*; + +import com.booleanuk.core.Products.Bagel; +import com.booleanuk.core.Products.Filling; +import com.booleanuk.core.Products.Product; +import org.junit.jupiter.api.Test; + +import java.sql.Time; +import java.util.List; + +public class CustomerTest { + TestHelper test = new TestHelper(); + List inventory = test.loadInventoryOnStart(); + + @Test + public void verifyBasketAfterAddAndRemove() { + Basket basket = new Basket("", 5); + Customer customer = new Customer(basket, inventory); + + Bagel bagel = new Bagel("BGLP", 0.39f, "Plain", Product.ProductType.BAGEL); + + customer.addBagelToBasket(new Bagel("BGLO", 0.49f, "Onion", Product.ProductType.BAGEL)); + customer.addBagelToBasket(new Bagel("BGLP", 0.39f, "Plain", Product.ProductType.BAGEL)); + assertEquals(2, customer.getAmountOfBagelsInBasket()); + customer.addBagelToBasket(bagel); + assertEquals(3, customer.getAmountOfBagelsInBasket()); + customer.removeBagelFromBasket(new Bagel("4", 11, "test1", Product.ProductType.BAGEL)); + assertEquals(3, customer.getAmountOfBagelsInBasket()); + customer.removeBagelFromBasket(bagel); + assertEquals(2, customer.getAmountOfBagelsInBasket()); + } + + @Test + public void orderBagelAtSpecificTimeShouldReturnTimeAndBagels() { + Basket basket = new Basket("", 5); + Customer customer = new Customer(basket, inventory); + Bagel bagel = new Bagel("BGLP", 0.39f, "Plain", Product.ProductType.BAGEL); + customer.addBagelToBasket(bagel); + Time time = Time.valueOf("10:00:00"); + assertEquals("Order: 10:00:00, Bagel: Plain", customer.orderBagelAtSpecificTime(time, "plain")); + } + + @Test + public void getCorrectTotalCostOfCustomerBasket() { + Customer customer = new Customer(new Basket("", 5), inventory); + customer.addBagelToBasket(new Bagel("BGLP", 0.39f, "Plain", Product.ProductType.BAGEL)); + customer.addBagelToBasket(new Bagel("BGLO", 0.49f, "Onion", Product.ProductType.BAGEL)); + + Bagel bagel = new Bagel("BGLO", 0.49f, "Onion", Product.ProductType.BAGEL); + Filling filling = new Filling("SKU123", 0.8f, "Chocolate", Product.ProductType.FILLING); + bagel.setFilling(filling); + customer.addBagelToBasket(bagel); + + assertEquals(2.17f, customer.getTotalCost()); + customer.removeBagelFromBasket(bagel); + assertEquals(0.8799999952316284, customer.getTotalCost()); + } + + @Test + public void getSingleBagelPriceFromBasket() { + Customer customer = new Customer(new Basket("", 5), inventory); + customer.addBagelToBasket(new Bagel("BGLO", 0.49f, "Onion", Product.ProductType.BAGEL)); + customer.addBagelToBasket(new Bagel("BGLO", 0.49f, "Onion", Product.ProductType.BAGEL)); + + Bagel bagel = new Bagel("BGLE", 0.49f, "Everything", Product.ProductType.BAGEL); + Filling filling = new Filling("SKU123", 0.8f, "Chocolate", Product.ProductType.FILLING); + bagel.setFilling(filling); + customer.addBagelToBasket(bagel); + + assertEquals(1.29f, customer.getBagelPrice(bagel)); + customer.removeBagelFromBasket(bagel); + assertNotEquals(0.98f, customer.getBagelPrice(bagel)); + assertEquals(-1, customer.getBagelPrice(bagel)); + } + +// @Test +// public void displayAllFillingsAndPrice() { +// Customer customer = new Customer(new Basket("", 5), inventory); +// customer.viewFillingsPrice(); +// } + + @Test + public void chooseAndRetrieveBagelWithFilling() { + Customer customer = new Customer(new Basket("", 5), inventory); + customer.getBagelAndPickFilling("bacon"); + assertEquals(1, customer.getAmountOfBagelsInBasket()); + assertEquals(0.51f, customer.getTotalCost()); + } +} diff --git a/src/test/java/com/booleanuk/core/FillingTest.java b/src/test/java/com/booleanuk/core/FillingTest.java new file mode 100644 index 000000000..a0a822013 --- /dev/null +++ b/src/test/java/com/booleanuk/core/FillingTest.java @@ -0,0 +1,43 @@ +package com.booleanuk.core; + +import static org.junit.jupiter.api.Assertions.*; + +import com.booleanuk.core.Products.Filling; +import com.booleanuk.core.Products.Product; +import org.junit.jupiter.api.Test; + +public class FillingTest { + + @Test + public void testFillingConstructor() { + Filling filling = new Filling("sku123", 10.0f, "Vanilla", Product.ProductType.FILLING); + + assertEquals(10.0f, filling.getPrice()); + assertEquals("SKU123", filling.getSku()); + assertEquals("Vanilla", filling.getVariant()); + } + + @Test + public void testSettersAndGetters() { + Filling filling = new Filling("sku123", 10.0f, "Vanilla", Product.ProductType.FILLING); + + filling.setPrice(12.5f); + filling.setSku("SKU456"); + filling.setVariant("Chocolate"); + + assertEquals(12.5f, filling.getPrice()); + assertEquals("SKU456", filling.getSku()); + assertEquals("Chocolate", filling.getVariant()); + } + + @Test + public void testNullOrEmptyValues() { + assertThrows(IllegalArgumentException.class, () -> { + new Filling("", 0.0f, "", Product.ProductType.FILLING); + }); + Filling filling = new Filling("", -1f, "", Product.ProductType.FILLING); + assertEquals(1f, filling.getPrice()); //defaults + assertEquals("FIL", filling.getSku()); //defaults + assertEquals("plain", filling.getVariant()); //defaults + } +} diff --git a/src/test/java/com/booleanuk/core/InventoryTest.java b/src/test/java/com/booleanuk/core/InventoryTest.java new file mode 100644 index 000000000..8b625b254 --- /dev/null +++ b/src/test/java/com/booleanuk/core/InventoryTest.java @@ -0,0 +1,54 @@ +package com.booleanuk.core; + +import com.booleanuk.core.Products.Bagel; +import com.booleanuk.core.Products.Product; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; +import java.util.List; + +public class InventoryTest { + + @Test + public void testAddProductToInventory() { + Inventory inventory = new Inventory(); + Product product = new Bagel("ABC123", 99.99f, "Red", Product.ProductType.BAGEL); + + inventory.addProduct(product); + List products = inventory.getInventoryList(); + assertEquals(1, products.size()); // 1 product in the inventory + assertEquals(product, products.get(0)); // + } + + @Test + public void testGetInventoryList() { + Inventory inventory = new Inventory(); + Product product1 = new Bagel("ABC123", 99.99f, "Red", Product.ProductType.BAGEL); + Product product2 = new Bagel("DEF456", 29.99f, "Blue", Product.ProductType.BAGEL); + + inventory.addProduct(product1); + inventory.addProduct(product2); + + List products = inventory.getInventoryList(); + assertEquals(2, products.size()); // 2 products + assertTrue(products.contains(product1)); + assertTrue(products.contains(product2)); + } + + @Test + public void testRemoveProductFromInventory() { + Inventory inventory = new Inventory(); + Product product1 = new Bagel("ABC123", 99.99f, "Red", Product.ProductType.BAGEL); + Product product2 = new Bagel("DEF456", 29.99f, "Blue", Product.ProductType.BAGEL); + + inventory.addProduct(product1); + inventory.addProduct(product2); + + inventory.removeProduct(product1); + + List products = inventory.getInventoryList(); + assertEquals(1, products.size()); // 1 product + assertFalse(products.contains(product1)); // false + assertTrue(products.contains(product2)); // true + } +} + diff --git a/src/test/java/com/booleanuk/core/ProductTest.java b/src/test/java/com/booleanuk/core/ProductTest.java new file mode 100644 index 000000000..af13264f9 --- /dev/null +++ b/src/test/java/com/booleanuk/core/ProductTest.java @@ -0,0 +1,37 @@ +package com.booleanuk.core; + +import com.booleanuk.core.Products.Bagel; +import com.booleanuk.core.Products.Product; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +public class ProductTest { + + @Test + public void testProductCreationWithValidData() { + Product product = new Bagel("ABC123", 99.99f, "Red", Product.ProductType.BAGEL); + + // Check if the product's SKU, price, and variant are set correctly + assertEquals("ABC123", product.getSku()); + assertEquals(99.99f, product.getPrice()); + assertEquals("Red", product.getVariant()); + + product.setSku("ABC"); + assertEquals("ABC", product.getSku()); + } + + @Test + public void testSetPriceThrowsExceptionForNegativePrice() { + assertThrows(IllegalArgumentException.class, () -> { + new Bagel("XYZ456", -50f, "Blue", Product.ProductType.BAGEL); + }); + } + + @Test + public void testSetPriceThrowsExceptionForZeroPrice() { + assertThrows(IllegalArgumentException.class, () -> { + new Bagel("XYZ456", 0f, "Blue", Product.ProductType.BAGEL); + }); + } +} + diff --git a/src/test/java/com/booleanuk/core/TestHelper.java b/src/test/java/com/booleanuk/core/TestHelper.java new file mode 100644 index 000000000..55871e8d9 --- /dev/null +++ b/src/test/java/com/booleanuk/core/TestHelper.java @@ -0,0 +1,33 @@ +package com.booleanuk.core; + +import com.booleanuk.core.Products.Bagel; +import com.booleanuk.core.Products.Filling; +import com.booleanuk.core.Products.Product; + +import java.util.List; + +public class TestHelper { + + public List loadInventoryOnStart() { + // Add all items to the inventory + Inventory inventory = new Inventory(); + // Add Bagels + inventory.addProduct(new Bagel("BGLO", 0.49f, "Onion", Product.ProductType.BAGEL)); + inventory.addProduct(new Bagel("BGLP", 0.39f, "Plain", Product.ProductType.BAGEL)); + inventory.addProduct(new Bagel("BGLE", 0.49f, "Everything", Product.ProductType.BAGEL)); + inventory.addProduct(new Bagel("BGLS", 0.49f, "Sesame", Product.ProductType.BAGEL)); + + // Add Fillings + inventory.addProduct(new Filling("FILB", 0.12f, "Bacon", Product.ProductType.FILLING)); + inventory.addProduct(new Filling("FILE", 0.12f, "Egg", Product.ProductType.FILLING)); + inventory.addProduct(new Filling("FILC", 0.12f, "Cheese", Product.ProductType.FILLING)); + inventory.addProduct(new Filling("FILX", 0.12f, "Cream Cheese", Product.ProductType.FILLING)); + inventory.addProduct(new Filling("FILS", 0.12f, "Smoked Salmon", Product.ProductType.FILLING)); + inventory.addProduct(new Filling("FILH", 0.12f, "Ham", Product.ProductType.FILLING)); + + // Add Coffees + + return inventory.getInventoryList(); + } + +}