From 4d16ab36117f605d4e86e528f0ed5ca8c52f42ce Mon Sep 17 00:00:00 2001 From: Aqsa Malik Date: Tue, 19 Sep 2023 20:38:24 -0400 Subject: [PATCH] add step in setup file, fix methods in coffeeShopOrder class Signed-off-by: Aqsa Malik --- .../coffeeshopkata/CoffeeShopOrder.java | 18 ++++--- .../coffeeshopkata/beverage/Americano.java | 2 +- .../coffeeshopkata/CoffeeShopTest.java | 42 +++++++++------- coffee-shop-kata/README.md | 4 +- coffee-shop-kata/SETUP.md | 12 +++-- .../coffeeshopkata/CoffeeShopOrder.java | 2 +- .../coffeeshopkata/beverage/Americano.java | 2 +- .../coffeeshopkata/beverage/CoffeeDrink.java | 1 + .../coffeeshopkata/beverage/Latte.java | 2 +- .../coffeeshopkata/beverage/Macchiato.java | 2 +- .../coffeeshopkata/CoffeeShopTest.java | 48 ++++++++++-------- .../coffeeshopkata/CoffeeShopOrder.java | 19 ++++--- .../coffeeshopkata/CoffeeShopTest.java | 50 +++++++++++-------- 13 files changed, 115 insertions(+), 89 deletions(-) diff --git a/coffee-shop-kata-solutions/src/main/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopOrder.java b/coffee-shop-kata-solutions/src/main/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopOrder.java index 2e138b49..41e85654 100644 --- a/coffee-shop-kata-solutions/src/main/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopOrder.java +++ b/coffee-shop-kata-solutions/src/main/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopOrder.java @@ -83,30 +83,32 @@ public List getFoodItemsForOrder() *

* NOTE: The method highlights the usage of a record deconstruction pattern */ - public String generateReceipt() + public String generateReceiptForFoodItems() { double total = 0.0; - StringBuilder receiptBuilder = new StringBuilder(); + List receiptItems = new ArrayList<>(); for (Item item : this.orderItems) { if (item instanceof Donut(DonutType donutType)) { - receiptBuilder.append("Donut: ").append(donutType).append(" $").append(item.getPrice()).append("\n"); + receiptItems.add("Donut: "+ donutType + " $" + item.getPrice()); + total += item.getPrice(); } else if (item instanceof Bagel(BagelType bagelType, SpreadType spreadType, boolean toasted)) { - receiptBuilder.append("Bagel: ").append(bagelType).append(" $").append(item.getPrice()).append("\n"); + receiptItems.add("Bagel: "+ bagelType +" $" + item.getPrice()); + total += item.getPrice(); } else if (item instanceof Cookie(CookieType cookieType, boolean warmed)) { - receiptBuilder.append("Cookie: ").append(cookieType).append(" $").append(item.getPrice()).append("\n"); + receiptItems.add("Cookie: " + cookieType +" $" + item.getPrice()); + total += item.getPrice(); } - total += item.getPrice(); } + receiptItems.add("Total: $" + total); - receiptBuilder.append("Total: $").append(total); - return receiptBuilder.toString(); + return String.join("\n", receiptItems); } /** diff --git a/coffee-shop-kata-solutions/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/Americano.java b/coffee-shop-kata-solutions/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/Americano.java index 878fe1da..be6f6a1a 100644 --- a/coffee-shop-kata-solutions/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/Americano.java +++ b/coffee-shop-kata-solutions/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/Americano.java @@ -16,7 +16,7 @@ package bnymellon.codekatas.coffeeshopkata.beverage; -public final class Americano implements CoffeeDrink +public non-sealed class Americano implements CoffeeDrink { private final DrinkTemperature drinkTemperature; diff --git a/coffee-shop-kata-solutions/src/test/java/bnymellon/codekata/coffeeshopkata/CoffeeShopTest.java b/coffee-shop-kata-solutions/src/test/java/bnymellon/codekata/coffeeshopkata/CoffeeShopTest.java index 15b57744..685c2fa7 100644 --- a/coffee-shop-kata-solutions/src/test/java/bnymellon/codekata/coffeeshopkata/CoffeeShopTest.java +++ b/coffee-shop-kata-solutions/src/test/java/bnymellon/codekata/coffeeshopkata/CoffeeShopTest.java @@ -20,6 +20,7 @@ import bnymellon.codekatas.coffeeshopkata.Item; import bnymellon.codekatas.coffeeshopkata.beverage.Americano; import bnymellon.codekatas.coffeeshopkata.beverage.CoffeeDrink; +import bnymellon.codekatas.coffeeshopkata.beverage.DrinkTemperature; import bnymellon.codekatas.coffeeshopkata.beverage.Latte; import bnymellon.codekatas.coffeeshopkata.beverage.Macchiato; import bnymellon.codekatas.coffeeshopkata.food.Bagel; @@ -46,6 +47,7 @@ public class CoffeeShopTest private Bagel bagel1; private Cookie cookie1; private Donut donut1; + private Americano americano; @BeforeEach public void setUp() @@ -53,17 +55,26 @@ public void setUp() bagel1 = new Bagel(EVERYTHING, HERB_GARLIC_CREAM_CHEESE, true); cookie1 = new Cookie(CHOCOLATE_CHIP, true); donut1 = new Donut(GLAZED); - itemList = List.of(bagel1, cookie1, donut1); + americano = new Americano(DrinkTemperature.HOT); + itemList = List.of(bagel1, cookie1, donut1, americano); coffeeShopOrder = new CoffeeShopOrder("Emilie", itemList); } @Test - public void getFoodItemsForOrderTest() + public void testBagelRecord() { - List expected = List.of("CHOCOLATE_CHIP cookie", "EVERYTHING bagel with HERB_GARLIC_CREAM_CHEESE", "GLAZED donut"); - List actual = coffeeShopOrder.getFoodItemsForOrder(); - Collections.sort(actual); - assertEquals(expected, actual); + Bagel bagel2 = new Bagel(EVERYTHING, HERB_GARLIC_CREAM_CHEESE, true); + assertTrue(Bagel.class.isRecord()); + assertEquals(bagel1, bagel2); + assertEquals("Bagel[bagelType=EVERYTHING, spreadType=HERB_GARLIC_CREAM_CHEESE, toasted=true]", bagel1.toString()); + } + + @Test + public void testBagelGetters() + { + assertTrue(bagel1.toasted()); + assertEquals(bagel1.bagelType(), EVERYTHING); + assertEquals(bagel1.spreadType(), HERB_GARLIC_CREAM_CHEESE); } @Test @@ -74,25 +85,18 @@ public void generateReceiptTest() Cookie: CHOCOLATE_CHIP $1.25 Donut: GLAZED $1.75 Total: $5.5"""; - assertEquals(expectedReceipt, coffeeShopOrder.generateReceipt()); + assertEquals(expectedReceipt, coffeeShopOrder.generateReceiptForFoodItems()); } @Test - public void testBagelRecord() + public void getFoodItemsForOrderTest() { - Bagel bagel2 = new Bagel(EVERYTHING, HERB_GARLIC_CREAM_CHEESE, true); - assertTrue(Bagel.class.isRecord()); - assertEquals(bagel1, bagel2); - assertEquals("Bagel[bagelType=EVERYTHING, spreadType=HERB_GARLIC_CREAM_CHEESE, toasted=true]", bagel1.toString()); + List expected = List.of("CHOCOLATE_CHIP cookie", "EVERYTHING bagel with HERB_GARLIC_CREAM_CHEESE", "GLAZED donut"); + List actual = coffeeShopOrder.getFoodItemsForOrder(); + Collections.sort(actual); + assertEquals(expected, actual); } - @Test - public void testBagelGetters() - { - assertTrue(bagel1.toasted()); - assertEquals(bagel1.bagelType(), EVERYTHING); - assertEquals(bagel1.spreadType(), HERB_GARLIC_CREAM_CHEESE); - } @Test public void testSealedClasses() diff --git a/coffee-shop-kata/README.md b/coffee-shop-kata/README.md index 7aff4235..0bc4dfe1 100644 --- a/coffee-shop-kata/README.md +++ b/coffee-shop-kata/README.md @@ -1,6 +1,6 @@ ## What is the Coffee Shop Kata? ## -The Coffee Kata exercise is designed to provide a hands-on experience in learning and demonstrating the usage of latest +The Coffee Shop Kata exercise is designed to provide a hands-on experience in learning and demonstrating the usage of latest Java features while comparing them with older. The domain for the kata is a Coffee Shop. There are several domain @@ -29,9 +29,9 @@ problems; there are no TODOs in this module. For technical setup, follow the ins ## Getting started ## The following Java concepts will be useful in completing the kata: -* [Pattern matching for switch](https://openjdk.org/jeps/441) * [Records](https://openjdk.org/jeps/395) * [Record patterns](https://openjdk.org/jeps/440) +* [Pattern matching for switch](https://openjdk.org/jeps/441) * [Sealed classes](https://openjdk.org/jeps/409) There are failing tests in [CoffeeShopTest](jdk21/src/test/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopTest.java). diff --git a/coffee-shop-kata/SETUP.md b/coffee-shop-kata/SETUP.md index aa375469..1b661874 100644 --- a/coffee-shop-kata/SETUP.md +++ b/coffee-shop-kata/SETUP.md @@ -8,12 +8,18 @@ ### Project setup 1. Git clone the entire [code-katas](https://github.com/BNYMellon/CodeKatas) project from GitHub or download the project as a .zip file. -2. Launch the project in the IDE as a maven project. You can find instructions on how to do +2. Launch the project in the IDE and point to the pom.xml to be opened as a project. + You can find more instructions on how to do that [here](https://www.jetbrains.com/idea/guide/tutorials/working-with-maven/importing-a-project/). -3. To verify that the Java 8 module is set up correctly, +3. To use Java 20 preview features in IntelliJ IDEA, follow these steps: + - Go to File | Project Structure. + - Set the Project SDK to 20. + - Set the Project language level to "20 (Preview)...". + - Make sure you have the correct JDK selected. +4. To verify that the Java 8 module is set up correctly, run [CoffeeShopTest](jdk8/src/test/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopTest.java) in the jdk8 module - the class should compile and all tests will pass. -4. To verify that the Java 21 module is set up correctly, +5. To verify that the Java 21 module is set up correctly, run [CoffeeShopTest](jdk21/src/test/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopTest.java) in the jdk21 module - the class should compile but most tests will fail. diff --git a/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopOrder.java b/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopOrder.java index 03387b4d..549c3054 100644 --- a/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopOrder.java +++ b/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopOrder.java @@ -61,7 +61,7 @@ public List getFoodItemsForOrder() { * * @see ... */ - public String generateReceipt() { + public String generateReceiptForFoodItems() { // TODO: Implement the receipt generation logic here. // Hint: look at the Java 8 implementation in the jdk8 module, // and the link above to see how record patterns can be utilized here diff --git a/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/Americano.java b/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/Americano.java index 878fe1da..10278d27 100644 --- a/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/Americano.java +++ b/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/Americano.java @@ -16,7 +16,7 @@ package bnymellon.codekatas.coffeeshopkata.beverage; -public final class Americano implements CoffeeDrink +public class Americano implements CoffeeDrink { private final DrinkTemperature drinkTemperature; diff --git a/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/CoffeeDrink.java b/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/CoffeeDrink.java index 5754681a..c1c4a68e 100644 --- a/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/CoffeeDrink.java +++ b/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/CoffeeDrink.java @@ -23,6 +23,7 @@ * establish a controlled hierarchy for extensions. * Modify the following class to permit only the classes * Latte, Macchiato, and Americano, while excluding Tea. + * Make Americano, Macchiato "non-sealed" class and Latte as a "final" class * * NOTE: This class hierarchy shows the usage of sealed classes * @see ... diff --git a/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/Latte.java b/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/Latte.java index 634ed7fb..63b41265 100644 --- a/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/Latte.java +++ b/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/Latte.java @@ -21,7 +21,7 @@ import bnymellon.codekatas.coffeeshopkata.beverage.FlavorSyrup; import bnymellon.codekatas.coffeeshopkata.beverage.MilkType; -public final class Latte implements CoffeeDrink +public class Latte implements CoffeeDrink { private final MilkType milkType; private final boolean extraFoam; diff --git a/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/Macchiato.java b/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/Macchiato.java index b2907e20..dd2f67fb 100644 --- a/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/Macchiato.java +++ b/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/Macchiato.java @@ -16,7 +16,7 @@ package bnymellon.codekatas.coffeeshopkata.beverage; -public final class Macchiato implements CoffeeDrink +public class Macchiato implements CoffeeDrink { private final MilkType milkType; private final FlavorSyrup flavorSyrup; diff --git a/coffee-shop-kata/jdk21/src/test/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopTest.java b/coffee-shop-kata/jdk21/src/test/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopTest.java index 1d60f2f7..a20eeb08 100644 --- a/coffee-shop-kata/jdk21/src/test/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopTest.java +++ b/coffee-shop-kata/jdk21/src/test/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopTest.java @@ -18,6 +18,7 @@ import bnymellon.codekatas.coffeeshopkata.beverage.Americano; import bnymellon.codekatas.coffeeshopkata.beverage.CoffeeDrink; +import bnymellon.codekatas.coffeeshopkata.beverage.DrinkTemperature; import bnymellon.codekatas.coffeeshopkata.beverage.Latte; import bnymellon.codekatas.coffeeshopkata.beverage.Macchiato; import bnymellon.codekatas.coffeeshopkata.food.Bagel; @@ -45,6 +46,7 @@ public class CoffeeShopTest private Bagel bagel1; private Cookie cookie1; private Donut donut1; + private Americano americano; @BeforeEach public void setUp() @@ -52,35 +54,15 @@ public void setUp() bagel1 = new Bagel(EVERYTHING, HERB_GARLIC_CREAM_CHEESE, true); cookie1 = new Cookie(CHOCOLATE_CHIP, true); donut1 = new Donut(GLAZED); + americano = new Americano(DrinkTemperature.HOT); itemList = new ArrayList<>(); itemList.add(bagel1); itemList.add(cookie1); itemList.add(donut1); + itemList.add(americano); coffeeShopOrder = new CoffeeShopOrder("Emilie", itemList); } - @Test - public void getFoodItemsForOrderTest() - { - // TODO: Complete the method getFoodItemsForOrder() in CoffeeShopOrder to make this pass - List expected = List.of("CHOCOLATE_CHIP cookie", "EVERYTHING bagel with HERB_GARLIC_CREAM_CHEESE", "GLAZED donut"); - List actual = coffeeShopOrder.getFoodItemsForOrder(); - Collections.sort(actual); - assertEquals(expected, actual); - } - - @Test - public void generateReceiptTest() - { - // TODO: Complete the method generateReceipt() in CoffeeShopOrder to make this pass - String expectedReceipt = """ - Bagel: EVERYTHING $2.5 - Cookie: CHOCOLATE_CHIP $1.25 - Donut: GLAZED $1.75 - Total: $5.5"""; - assertEquals(expectedReceipt, coffeeShopOrder.generateReceipt()); - } - @Test public void testBagelRecord() { @@ -100,6 +82,28 @@ public void testBagelGetters() assertEquals(bagel1.getSpreadType(), HERB_GARLIC_CREAM_CHEESE); } + @Test + public void generateReceiptForFoodItems() + { + // TODO: Complete the method generateReceipt() in CoffeeShopOrder to make this pass + String expectedReceipt = """ + Bagel: EVERYTHING $2.5 + Cookie: CHOCOLATE_CHIP $1.25 + Donut: GLAZED $1.75 + Total: $5.5"""; + assertEquals(expectedReceipt, coffeeShopOrder.generateReceiptForFoodItems()); + } + + @Test + public void getFoodItemsForOrderTest() + { + // TODO: Complete the method getFoodItemsForOrder() in CoffeeShopOrder to make this pass + List expected = List.of("CHOCOLATE_CHIP cookie", "EVERYTHING bagel with HERB_GARLIC_CREAM_CHEESE", "GLAZED donut"); + List actual = coffeeShopOrder.getFoodItemsForOrder(); + Collections.sort(actual); + assertEquals(expected, actual); + } + @Test public void testSealedClasses() { diff --git a/coffee-shop-kata/jdk8/src/main/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopOrder.java b/coffee-shop-kata/jdk8/src/main/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopOrder.java index 5408994d..d7fff805 100644 --- a/coffee-shop-kata/jdk8/src/main/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopOrder.java +++ b/coffee-shop-kata/jdk8/src/main/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopOrder.java @@ -31,6 +31,7 @@ import bnymellon.codekatas.coffeeshopkata.food.CookieType; import bnymellon.codekatas.coffeeshopkata.food.Donut; import bnymellon.codekatas.coffeeshopkata.food.DonutType; +import bnymellon.codekatas.coffeeshopkata.food.SpreadType; import java.util.ArrayList; import java.util.List; @@ -90,10 +91,10 @@ else if (item instanceof Donut) * NOTE: The method highlights the usage of a data extraction * HINT: Use instanceOf */ - public String generateReceipt() + public String generateReceiptForFoodItems() { double total = 0.0; - StringBuilder receiptBuilder = new StringBuilder(); + List receiptItems = new ArrayList<>(); for (Item item : this.orderItems) { @@ -101,25 +102,27 @@ public String generateReceipt() { Donut donut = (Donut) item; DonutType donutType = donut.getDonutType(); - receiptBuilder.append("Donut: ").append(donutType).append(" $").append(item.getPrice()).append("\n"); + receiptItems.add("Donut: "+ donutType + " $" + item.getPrice()); + total += item.getPrice(); } else if (item instanceof Bagel) { Bagel bagel = (Bagel) item; BagelType bagelType = bagel.getBagelType(); - receiptBuilder.append("Bagel: ").append(bagelType).append(" $").append(item.getPrice()).append("\n"); + receiptItems.add("Bagel: "+ bagelType +" $" + item.getPrice()); + total += item.getPrice(); } else if (item instanceof Cookie) { Cookie cookie = (Cookie) item; CookieType cookieType = cookie.getCookieType(); - receiptBuilder.append("Cookie: ").append(cookieType).append(" $").append(item.getPrice()).append("\n"); + receiptItems.add("Cookie: " + cookieType +" $" + item.getPrice()); + total += item.getPrice(); } - total += item.getPrice(); } + receiptItems.add("Total: $" + total); - receiptBuilder.append("Total: $").append(total); - return receiptBuilder.toString(); + return String.join("\n", receiptItems); } /** diff --git a/coffee-shop-kata/jdk8/src/test/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopTest.java b/coffee-shop-kata/jdk8/src/test/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopTest.java index 98771e92..b52c4025 100644 --- a/coffee-shop-kata/jdk8/src/test/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopTest.java +++ b/coffee-shop-kata/jdk8/src/test/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopTest.java @@ -15,6 +15,8 @@ */ package bnymellon.codekatas.coffeeshopkata; +import bnymellon.codekatas.coffeeshopkata.beverage.Americano; +import bnymellon.codekatas.coffeeshopkata.beverage.DrinkTemperature; import bnymellon.codekatas.coffeeshopkata.food.Bagel; import bnymellon.codekatas.coffeeshopkata.food.Cookie; import bnymellon.codekatas.coffeeshopkata.food.Donut; @@ -39,56 +41,60 @@ class CoffeeShopTest private Cookie cookie1; private Donut donut1; + private Americano americano; + @BeforeEach public void setUp() { bagel1 = new Bagel(EVERYTHING, HERB_GARLIC_CREAM_CHEESE, true); cookie1 = new Cookie(CHOCOLATE_CHIP, true); donut1 = new Donut(GLAZED); + americano = new Americano(DrinkTemperature.HOT); itemList = new ArrayList<>(); itemList.add(bagel1); itemList.add(cookie1); itemList.add(donut1); + itemList.add(americano); coffeeShopOrder = new CoffeeShopOrder("Emilie", itemList); } @Test - public void getFoodItemsForOrderTest() + public void testBagelClass() { - ArrayList expected = new ArrayList<>(); - expected.add("CHOCOLATE_CHIP cookie"); - expected.add("EVERYTHING bagel with HERB_GARLIC_CREAM_CHEESE"); - expected.add("GLAZED donut"); - List actual = coffeeShopOrder.getFoodItemsForOrder(); - Collections.sort(actual); - assertEquals(expected, actual); + Bagel bagel2 = new Bagel(EVERYTHING, HERB_GARLIC_CREAM_CHEESE, true); + assertEquals(bagel1, bagel2); + assertEquals("Bagel[bagelType=EVERYTHING, spreadType=HERB_GARLIC_CREAM_CHEESE, toasted=true]", bagel1.toString()); + } + + @Test + public void testBagelGetters() + { + assertTrue(bagel1.isToasted()); + assertEquals(bagel1.getBagelType(), EVERYTHING); + assertEquals(bagel1.getSpreadType(), HERB_GARLIC_CREAM_CHEESE); } @Test - public void generateReceiptTest() + public void generateReceiptForFoodItems() { String expectedReceipt = "Bagel: EVERYTHING $2.5\n" + "Cookie: CHOCOLATE_CHIP $1.25\n" + "Donut: GLAZED $1.75\n" + "Total: $5.5"; - assertEquals(expectedReceipt, coffeeShopOrder.generateReceipt()); + assertEquals(expectedReceipt, coffeeShopOrder.generateReceiptForFoodItems()); } @Test - public void testBagelClass() - { - Bagel bagel2 = new Bagel(EVERYTHING, HERB_GARLIC_CREAM_CHEESE, true); - assertEquals(bagel1, bagel2); - assertEquals("Bagel[bagelType=EVERYTHING, spreadType=HERB_GARLIC_CREAM_CHEESE, toasted=true]", bagel1.toString()); - } - - @Test - public void testBagelGetters() + public void getFoodItemsForOrderTest() { - assertTrue(bagel1.isToasted()); - assertEquals(bagel1.getBagelType(), EVERYTHING); - assertEquals(bagel1.getSpreadType(), HERB_GARLIC_CREAM_CHEESE); + ArrayList expected = new ArrayList<>(); + expected.add("CHOCOLATE_CHIP cookie"); + expected.add("EVERYTHING bagel with HERB_GARLIC_CREAM_CHEESE"); + expected.add("GLAZED donut"); + List actual = coffeeShopOrder.getFoodItemsForOrder(); + Collections.sort(actual); + assertEquals(expected, actual); } @Test