From 7f939067f8ca7c1189318b40a4e369e57f6cf609 Mon Sep 17 00:00:00 2001 From: Emilie Date: Fri, 15 Sep 2023 17:50:36 -0400 Subject: [PATCH] Update README, SETUP and add more descriptive TODO comments Signed-off-by: Emilie --- .github/workflows/maven.yml | 2 +- .github/workflows/solutions.yml | 2 +- coffee-shop-kata-solutions/pom.xml | 16 ++++---- .../coffeeshopkata/CoffeeShopOrder.java | 2 +- coffee-shop-kata/README.md | 22 ++++++++-- coffee-shop-kata/SETUP.md | 30 ++++++++------ coffee-shop-kata/jdk21/pom.xml | 40 +++++++++++++++---- .../coffeeshopkata/CoffeeShopOrder.java | 22 +++++----- .../codekatas/coffeeshopkata/food/Bagel.java | 5 +++ .../codekatas/coffeeshopkata/food/Cookie.java | 8 ++-- .../codekatas/coffeeshopkata/food/Donut.java | 5 +++ .../coffeeshopkata/CoffeeShopTest.java | 4 +- coffee-shop-kata/jdk8/pom.xml | 9 +++-- .../coffeeshopkata/CoffeeShopOrder.java | 2 +- coffee-shop-kata/pom.xml | 25 ++---------- 15 files changed, 119 insertions(+), 75 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index f9bc3f6e..74e068af 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -47,6 +47,6 @@ jobs: restore-keys: | ${{ runner.os }}-maven- - name: Maven - run: mvn verify -DskipTests=true -Dmaven.javadoc.skip=true -B -V --no-transfer-progress + run: mvn verify -DskipTests=true -Dmaven.javadoc.skip=true -B -V --no-transfer-progress -pl !coffee-shop-kata/jdk21,!coffee-shop-kata-solutions env: MAVEN_OPTS: "-Dmaven.repo.local=$HOME/.m2/repository -Xmx1g -Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss:SSS" diff --git a/.github/workflows/solutions.yml b/.github/workflows/solutions.yml index 1605fe55..9a6eeb72 100644 --- a/.github/workflows/solutions.yml +++ b/.github/workflows/solutions.yml @@ -47,6 +47,6 @@ jobs: restore-keys: | ${{ runner.os }}-maven- - name: Maven - run: mvn -pl calendar-kata-solutions,code-point-kata-solutions,deck-of-cards-kata-solutions,donut-kata-solutions,java-lambda-kata-solutions,pitest-mutation-kata-solutions,coffee-shop-kata-solutions,kata-of-katas-solutions verify -Dmaven.javadoc.skip=true -B -V --no-transfer-progress + run: mvn -pl calendar-kata-solutions,code-point-kata-solutions,deck-of-cards-kata-solutions,donut-kata-solutions,java-lambda-kata-solutions,pitest-mutation-kata-solutions,kata-of-katas-solutions verify -Dmaven.javadoc.skip=true -B -V --no-transfer-progress env: MAVEN_OPTS: "-Dmaven.repo.local=$HOME/.m2/repository -Xmx1g -Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss:SSS" diff --git a/coffee-shop-kata-solutions/pom.xml b/coffee-shop-kata-solutions/pom.xml index 44bcd3a7..ee0fddc5 100644 --- a/coffee-shop-kata-solutions/pom.xml +++ b/coffee-shop-kata-solutions/pom.xml @@ -15,8 +15,8 @@ ~ limitations under the License. --> - 4.0.0 @@ -32,8 +32,8 @@ UTF-8 - 21 - 21 + 20 + 20 5.9.3 @@ -59,10 +59,12 @@ org.apache.maven.plugins - maven-surefire-plugin - 3.1.2 + maven-compiler-plugin + 3.11.0 - --enable-preview + ${maven.compiler.source} + ${maven.compiler.target} + --enable-preview 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 10449b60..20494b7e 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 @@ -49,7 +49,7 @@ public CoffeeShopOrder(String customerName, List orderItems) } /** - * Print out a list of custom strings for the customer's food items! + * Return a list of custom strings for the customer's food items! * If the item is a Bagel: Print [bagelType] with [spreadType] * If the item is a Cookie: Print [cookieType] * If the item is a Donut: Print [donutType] diff --git a/coffee-shop-kata/README.md b/coffee-shop-kata/README.md index 0db20785..7aff4235 100644 --- a/coffee-shop-kata/README.md +++ b/coffee-shop-kata/README.md @@ -5,8 +5,8 @@ Java features while comparing them with older. The domain for the kata is a Coffee Shop. There are several domain classes that are shared by all the exercises. These are -[`Items`](src/main/java/bnymellon/codekatas/coffeeshopkata/Item.java), -[`CoffeeShopOrder`](src/main/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopOrder.java), +[`Items`](jdk8/src/main/java/bnymellon/codekatas/coffeeshopkata/Item.java), +[`CoffeeShopOrder`](jdk8/src/main/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopOrder.java), [`Beverage`](jdk8/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/Beverage.java), [`Tea`](jdk8/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/Tea.java), [`CoffeeDrink`](jdk8/src/main/java/bnymellon/codekatas/coffeeshopkata/beverage/CoffeeDrink.java), @@ -20,5 +20,19 @@ classes that are shared by all the exercises. These are ![Diagram](CoffeeShopDomain.png) -## Getting Started ## -This kata involves refactoring existing code and implementing missing code! In the [`new-java-features`](./new-java-features) module, you will find a test class called [bnymellon.codekata.coffeeshopkata.CoffeeShopTest](src/test/java/bnymellon/codekata/coffeeshopkata/jdk21/bnymellon.codekata.coffeeshopkata.CoffeeShopTest.java). Each test case contains a TODO that needs to be completed in order to make the code pass. All the code you need to complete is in the [`new-java-features`](./new-java-features) module, with the corresponding solutions in [`coffee-shop-kata-solutions/new-java-features`](../coffee-shop-kata-solutions/new-java-features-solutions). The purpose of the [`old-java-features`](./old-java-features) module is to show you the Java 8 way of solving these problems; there are no TODOs in this module. For technical setup, follow the instructions in [`SETUP.md`](./SETUP.md)! \ No newline at end of file +## Overview ## +This kata involves refactoring existing code and implementing missing code! All the code you need to complete is in +the [`jdk21`](./jdk21) module, with the corresponding solutions +in [`coffee-shop-kata-solutions`](../coffee-shop-kata-solutions). The +purpose of the [`jdk8`](./jdk8) module is to show you the Java 8 way of solving these +problems; there are no TODOs in this module. For technical setup, follow the instructions in [`SETUP.md`](./SETUP.md)! + +## 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) +* [Sealed classes](https://openjdk.org/jeps/409) + +There are failing tests in [CoffeeShopTest](jdk21/src/test/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopTest.java). +Make all the test cases pass by following the TODOs! \ No newline at end of file diff --git a/coffee-shop-kata/SETUP.md b/coffee-shop-kata/SETUP.md index aca4ff63..305e0df0 100644 --- a/coffee-shop-kata/SETUP.md +++ b/coffee-shop-kata/SETUP.md @@ -1,17 +1,21 @@ ## Setting up the project -### Tooling used -* [JDK 20.0.2+](https://jdk.java.net/20/) installed on your computer -* IntelliJ IDEA 2023.1+ or similar IDE for Java +### Requirements +* [JDK 20](https://jdk.java.net/20/) installed on your computer +* [Maven 3.6.1+](https://maven.apache.org/download.cgi) installed on your computer +* [IntelliJ IDEA 2023.1+](https://www.jetbrains.com/idea/download/?section=windows) or similar IDE for Java -### Initial setup -1. Launch the project in the IDE (can be configured as a maven project, pointing to the root pom.xml) +### 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 + 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, + run [CoffeeShopTest](/jdk8/src/test/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopTest.java) in the + old-java-features module - the class should compile and all tests will pass. +4. To verify that the Java 21 module is set up correctly, + run [CoffeeShopTest](/jdk21/src/test/java/bnymellon/codekatas/coffeeshopkata/CoffeeShopTest.java) in the + new-java-features module - the class should compile but most tests will fail. -#### Test Java 8 module -1. Verify that the module old-java-features uses JDK 8 -2. Run [bnymellon.codekata.coffeeshopkata.CoffeeShopTest](/old-java-features/src/test/java/bnymellon.codekata.coffeeshopkata.CoffeeShopTest.java), all tests should pass -#### Test Java 21 module -1. Verify that the module old-java-features uses JDK 20 -2. Run [bnymellon.codekata.coffeeshopkata.CoffeeShopTest](/bnymellon/codekata/coffeeshopkata/newjavafeatures/bnymellon.codekata.coffeeshopkata.CoffeeShopTest.java), most tests should fail -#### Get started -* Make the failing tests in [bnymellon.codekata.coffeeshopkata.CoffeeShopTest](/bnymellon/codekata/coffeeshopkata/newjavafeatures/bnymellon.codekata.coffeeshopkata.CoffeeShopTest.java) pass by following and completing TODOs \ No newline at end of file +### Getting started +* Follow the [README](README.md) for instructions on how to complete the kata. \ No newline at end of file diff --git a/coffee-shop-kata/jdk21/pom.xml b/coffee-shop-kata/jdk21/pom.xml index be277dff..2b5c1a04 100644 --- a/coffee-shop-kata/jdk21/pom.xml +++ b/coffee-shop-kata/jdk21/pom.xml @@ -15,8 +15,8 @@ ~ limitations under the License. --> - 4.0.0 @@ -29,17 +29,43 @@ jdk21 - 21 - 21 UTF-8 + 20 + 20 + 5.9.3 + + + + org.junit.jupiter + junit-jupiter + ${junit5.version} + test + + + + org.junit.jupiter - junit-jupiter-api - 5.10.0 - test + junit-jupiter + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + ${maven.compiler.source} + ${maven.compiler.target} + --enable-preview + + + + + 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 6cf89876..329edc25 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 @@ -32,17 +32,19 @@ public CoffeeShopOrder(String customerName, List orderItems) } /** - * Print out a list of custom strings for the customer's food items! - * Start with, "Order #[orderNumber] for [customerName] includes: " - * If the item is a Bagel: Print [toasted] [bagelType] with [spreadType] - * If the item is a Cookie: Print [warmed] [cookieType] + * Return a list of custom strings for the customer's food items! + * If the item is a Bagel: Print [bagelType] with [spreadType] + * If the item is a Cookie: Print [cookieType] * If the item is a Donut: Print [donutType] *

* NOTE: This method show-cases a switch-case pattern matching. + * + * @see ... */ - public List getFoodItemsForOrder() - { + public List getFoodItemsForOrder() { // TODO implement method + // Hint: look at the Java 8 implementation in the old-java-features module, + // and the link above to see how pattern matching for switch can be utilized here return null; } @@ -54,11 +56,13 @@ public List getFoodItemsForOrder() * Total: $Total Price *

* NOTE: The method highlights the usage of a record deconstruction pattern + * + * @see ... */ - public String generateReceipt() - { + public String generateReceipt() { // TODO: Implement the receipt generation logic here. - // Use the instanceof operator and the record pattern to differentiate between different food items. + // Hint: look at the Java 8 implementation in the old-java-features module, + // and the link above to see how record patterns can be utilized here return null; } diff --git a/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/food/Bagel.java b/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/food/Bagel.java index 56ef599d..c7165651 100644 --- a/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/food/Bagel.java +++ b/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/food/Bagel.java @@ -18,6 +18,11 @@ import java.util.Objects; +/** + * TODO: convert class to record + * + * @see ... + */ public class Bagel implements BakeryItem { private final BagelType bagelType; diff --git a/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/food/Cookie.java b/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/food/Cookie.java index 04f39d50..2106df04 100644 --- a/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/food/Cookie.java +++ b/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/food/Cookie.java @@ -16,11 +16,13 @@ package bnymellon.codekatas.coffeeshopkata.food; -import bnymellon.codekatas.coffeeshopkata.food.BakeryItem; -import bnymellon.codekatas.coffeeshopkata.food.CookieType; - import java.util.Objects; +/** + * TODO: convert class to record + * + * @see ... + */ public class Cookie implements BakeryItem { private final CookieType cookieType; diff --git a/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/food/Donut.java b/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/food/Donut.java index 2f52c40b..abf8b930 100644 --- a/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/food/Donut.java +++ b/coffee-shop-kata/jdk21/src/main/java/bnymellon/codekatas/coffeeshopkata/food/Donut.java @@ -18,6 +18,11 @@ import java.util.Objects; +/** + * TODO: convert class to record + * + * @see ... + */ public class Donut implements BakeryItem { private final DonutType donutType; 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 a56fa2a2..898efaf0 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 @@ -135,7 +135,7 @@ public void testDonutGetters() @Test public void testSealedClasses() { - //TODO Convert Coffee Drink to sealed class + // TODO: Convert Coffee Drink to sealed class assertTrue(CoffeeDrink.class.isSealed()); assertFalse(Americano.class.isSealed()); assertFalse(Macchiato.class.isSealed()); @@ -145,7 +145,7 @@ public void testSealedClasses() @Test public void getDrinkItems() { - //TODO Complete the method getDrinkForOrder() in CoffeeShopOrder to make this pass + // TODO: Complete the method getDrinkForOrder() in CoffeeShopOrder to make this pass List expected = List.of("HOT Americano", "HOT CARAMEL Latte with ALMOND_MILK", "HOT VANILLA Macchiato with WHOLE_MILK", "MATCHA Tea"); assertEquals(expected, coffeeShopOrder.getDrinkForOrder()); diff --git a/coffee-shop-kata/jdk8/pom.xml b/coffee-shop-kata/jdk8/pom.xml index b6ca98f9..e47fb918 100644 --- a/coffee-shop-kata/jdk8/pom.xml +++ b/coffee-shop-kata/jdk8/pom.xml @@ -15,8 +15,8 @@ ~ limitations under the License. --> - 4.0.0 @@ -32,13 +32,14 @@ 8 8 UTF-8 + 5.9.3 org.junit.jupiter - junit-jupiter-api - 5.10.0 + junit-jupiter + ${junit5.version} test 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 bc6ed836..8d9c6d95 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,7 +31,7 @@ public CoffeeShopOrder(String customerName, java.util.List orderItems) } /** - * Print out a list of custom strings for the customer's food items! + * Return a list of custom strings for the customer's food items! * If the item is a Bagel: Print [bagelType] with [spreadType] * If the item is a Cookie: Print [cookieType] * If the item is a Donut: Print [donutType] diff --git a/coffee-shop-kata/pom.xml b/coffee-shop-kata/pom.xml index b555ba49..430280e9 100644 --- a/coffee-shop-kata/pom.xml +++ b/coffee-shop-kata/pom.xml @@ -15,8 +15,8 @@ ~ limitations under the License. --> - 4.0.0 @@ -25,7 +25,7 @@ coffee-shop-kata - coffee-shop-kata + Coffee Shop Kata pom @@ -37,23 +37,4 @@ jdk21 - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.11.0 - - - org.apache.maven.plugins - maven-surefire-plugin - 3.1.2 - - --enable-preview - - - - -