Skip to content

Commit

Permalink
Change behaviour of getFoodItemsForOrder to ignore Beverage items, no…
Browse files Browse the repository at this point in the history
… exception thrown

Signed-off-by: Emilie <[email protected]>
  • Loading branch information
emilie-robichaud committed Sep 19, 2023
1 parent a881857 commit 9834d40
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions coffee-shop-kata-solutions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.24.2</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public CoffeeShopOrder(String customerName, List<Item> orderItems)
* If the item is a Bagel: "[bagelType] with [spreadType]"
* If the item is a Cookie: "[cookieType] cookie"
* If the item is a Donut: "[donutType] donut"
* Otherwise: throw new IllegalStateException()
* 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
1 change: 1 addition & 0 deletions coffee-shop-kata/jdk21/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.24.2</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public CoffeeShopOrder(String customerName, List<Item> orderItems)
* If the item is a Bagel: "[bagelType] with [spreadType]"
* If the item is a Cookie: "[cookieType] cookie"
* If the item is a Donut: "[donutType] donut"
* Otherwise: throw new IllegalStateException()
* 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 Down
1 change: 1 addition & 0 deletions coffee-shop-kata/jdk8/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.24.2</version>
<scope>test</scope>
</dependency>
</dependencies>

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 @@ -52,7 +52,7 @@ public CoffeeShopOrder(String customerName, java.util.List<Item> orderItems)
* If the item is a Bagel: "[bagelType] with [spreadType]"
* If the item is a Cookie: "[cookieType] cookie"
* If the item is a Donut: "[donutType] donut"
* Otherwise: throw new IllegalStateException()
* 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

0 comments on commit 9834d40

Please sign in to comment.