Skip to content

Commit

Permalink
Merge pull request #144 from emilie-robichaud/master
Browse files Browse the repository at this point in the history
Change food items list test to ignore order
  • Loading branch information
donraab authored Sep 19, 2023
2 parents 6ff1649 + f615dcc commit 1b38ad9
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public CoffeeShopOrder(String customerName, List<Item> orderItems)
* Return a list of custom strings for the customer's food items!
* The string format for each food item is as follows:
* If the item is a Bagel: "[bagelType] with [spreadType]"
* If the item is a Cookie: "[cookieType]"
* If the item is a Donut: "[donutType]"
* Otherwise: throw new IllegalStateException()
* If the item is a Cookie: "[cookieType] cookie"
* If the item is a Donut: "[donutType] donut"
* Otherwise: it is a beverage and should not be added to the list!
* <p>
* NOTE: This method show-cases a switch-case pattern matching.
*/
Expand All @@ -68,7 +68,7 @@ public List<String> getFoodItemsForOrder()
case Bagel bagel -> foodItems.add(bagel.bagelType() + " bagel with " + bagel.spreadType());
case Cookie cookie -> foodItems.add(cookie.cookieType() + " cookie");
case Donut donut -> foodItems.add(donut.donutType() + " donut");
default -> throw new IllegalStateException("Unexpected value: " + item);
default -> {}
}
}
return foodItems;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.List;

import static bnymellon.codekatas.coffeeshopkata.food.BagelType.EVERYTHING;
Expand Down Expand Up @@ -59,9 +60,10 @@ public void setUp()
@Test
public void getFoodItemsForOrderTest()
{
List<String> expected = List.of("EVERYTHING bagel with HERB_GARLIC_CREAM_CHEESE",
"CHOCOLATE_CHIP cookie", "GLAZED donut");
assertEquals(expected, coffeeShopOrder.getFoodItemsForOrder());
List<String> expected = List.of("CHOCOLATE_CHIP cookie", "EVERYTHING bagel with HERB_GARLIC_CREAM_CHEESE", "GLAZED donut");
List<String> actual = coffeeShopOrder.getFoodItemsForOrder();
Collections.sort(actual);
assertEquals(expected, actual);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package bnymellon.codekatas.coffeeshopkata;


import java.util.Collections;
import java.util.List;

public class CoffeeShopOrder
Expand All @@ -34,9 +35,9 @@ public CoffeeShopOrder(String customerName, List<Item> orderItems)
* Return a list of custom strings for the customer's food items!
* The string format for each food item is as follows:
* If the item is a Bagel: "[bagelType] with [spreadType]"
* If the item is a Cookie: "[cookieType]"
* If the item is a Donut: "[donutType]"
* Otherwise: throw new IllegalStateException()
* If the item is a Cookie: "[cookieType] cookie"
* If the item is a Donut: "[donutType] donut"
* Otherwise: it is a beverage and should not be added to the list!
* <p>
* NOTE: This method show-cases a switch-case pattern matching.
*
Expand All @@ -46,7 +47,7 @@ public List<String> getFoodItemsForOrder() {
// TODO: implement method
// Hint: look at the Java 8 implementation in the jdk8 module,
// and the link above to see how pattern matching for switch can be utilized here
return null;
return Collections.emptyList();
}

/**
Expand All @@ -64,7 +65,7 @@ public String generateReceipt() {
// 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
return null;
return "";
}

/**
Expand All @@ -81,6 +82,6 @@ public String generateReceipt() {
public List<String> getDrinkForOrder()
{
// TODO: implement method logic here
return null;
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.junit.jupiter.api.Test;

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

import static bnymellon.codekatas.coffeeshopkata.food.BagelType.EVERYTHING;
Expand Down Expand Up @@ -62,9 +63,10 @@ public void setUp()
public void getFoodItemsForOrderTest()
{
// TODO: Complete the method getFoodItemsForOrder() in CoffeeShopOrder to make this pass
List<String> expected = List.of("EVERYTHING bagel with HERB_GARLIC_CREAM_CHEESE",
"CHOCOLATE_CHIP cookie", "GLAZED donut");
assertEquals(expected, coffeeShopOrder.getFoodItemsForOrder());
List<String> expected = List.of("CHOCOLATE_CHIP cookie", "EVERYTHING bagel with HERB_GARLIC_CREAM_CHEESE", "GLAZED donut");
List<String> actual = coffeeShopOrder.getFoodItemsForOrder();
Collections.sort(actual);
assertEquals(expected, actual);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class CoffeeShopOrder
private final String customerName;
private final List<Item> orderItems;

public CoffeeShopOrder(String customerName, java.util.List<Item> orderItems)
public CoffeeShopOrder(String customerName, List<Item> orderItems)
{
this.customerName = customerName;
this.orderItems = orderItems;
Expand All @@ -50,9 +50,9 @@ public CoffeeShopOrder(String customerName, java.util.List<Item> orderItems)
* Return a list of custom strings for the customer's food items!
* The string format for each food item is as follows:
* If the item is a Bagel: "[bagelType] with [spreadType]"
* If the item is a Cookie: "[cookieType]"
* If the item is a Donut: "[donutType]"
* Otherwise: throw new IllegalStateException()
* If the item is a Cookie: "[cookieType] cookie"
* If the item is a Donut: "[donutType] donut"
* Otherwise: it is a beverage and should not be added to the list!
* <p>
* NOTE: This method show-cases a switch-case pattern matching.
*/
Expand All @@ -76,10 +76,6 @@ else if (item instanceof Donut)
Donut donut = (Donut) item;
foodItems.add(donut.getDonutType() + " donut");
}
else
{
throw new IllegalStateException();
}
}
return foodItems;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import org.junit.jupiter.api.Test;

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

import static bnymellon.codekatas.coffeeshopkata.food.BagelType.EVERYTHING;
import static bnymellon.codekatas.coffeeshopkata.food.CookieType.CHOCOLATE_CHIP;
import static bnymellon.codekatas.coffeeshopkata.food.DonutType.GLAZED;
import static bnymellon.codekatas.coffeeshopkata.food.SpreadType.HERB_GARLIC_CREAM_CHEESE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

class CoffeeShopTest
{
Expand All @@ -56,10 +56,12 @@ public void setUp()
public void getFoodItemsForOrderTest()
{
ArrayList<String> expected = new ArrayList<>();
expected.add("EVERYTHING bagel with HERB_GARLIC_CREAM_CHEESE");
expected.add("CHOCOLATE_CHIP cookie");
expected.add("EVERYTHING bagel with HERB_GARLIC_CREAM_CHEESE");
expected.add("GLAZED donut");
assertEquals(expected, coffeeShopOrder.getFoodItemsForOrder());
List<String> actual = coffeeShopOrder.getFoodItemsForOrder();
Collections.sort(actual);
assertEquals(expected, actual);
}

@Test
Expand Down

0 comments on commit 1b38ad9

Please sign in to comment.