Skip to content

Commit

Permalink
Merge pull request #141 from emilie-robichaud/master
Browse files Browse the repository at this point in the history
Update README, SETUP, add links and more descriptive TODO, fix pom issues
  • Loading branch information
donraab authored Sep 16, 2023
2 parents 050089e + 7f93906 commit 3dbbd35
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion .github/workflows/solutions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
16 changes: 9 additions & 7 deletions coffee-shop-kata-solutions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand All @@ -32,8 +32,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.source>20</maven.compiler.source>
<maven.compiler.target>20</maven.compiler.target>
<junit5.version>5.9.3</junit5.version>
</properties>

Expand All @@ -59,10 +59,12 @@
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<argLine>--enable-preview</argLine>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public CoffeeShopOrder(String customerName, List<Item> 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]
Expand Down
22 changes: 18 additions & 4 deletions coffee-shop-kata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)!
## 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!
30 changes: 17 additions & 13 deletions coffee-shop-kata/SETUP.md
Original file line number Diff line number Diff line change
@@ -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
### Getting started
* Follow the [README](README.md) for instructions on how to complete the kata.
40 changes: 33 additions & 7 deletions coffee-shop-kata/jdk21/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
Expand All @@ -29,17 +29,43 @@
<artifactId>jdk21</artifactId>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>20</maven.compiler.source>
<maven.compiler.target>20</maven.compiler.target>
<junit5.version>5.9.3</junit5.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.0</version>
<scope>test</scope>
<artifactId>junit-jupiter</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ public CoffeeShopOrder(String customerName, List<Item> 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]
* <p>
* NOTE: This method show-cases a switch-case pattern matching.
*
* @see <a href="https://openjdk.org/jeps/441">...</a>
*/
public List<String> getFoodItemsForOrder()
{
public List<String> 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;
}

Expand All @@ -54,11 +56,13 @@ public List<String> getFoodItemsForOrder()
* Total: $Total Price
* <p>
* NOTE: The method highlights the usage of a record deconstruction pattern
*
* @see <a href="https://openjdk.org/jeps/440">...</a>
*/
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

import java.util.Objects;

/**
* TODO: convert class to record
*
* @see <a href="https://openjdk.org/jeps/395">...</a>
*/
public class Bagel implements BakeryItem
{
private final BagelType bagelType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://openjdk.org/jeps/395">...</a>
*/
public class Cookie implements BakeryItem
{
private final CookieType cookieType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

import java.util.Objects;

/**
* TODO: convert class to record
*
* @see <a href="https://openjdk.org/jeps/395">...</a>
*/
public class Donut implements BakeryItem
{
private final DonutType donutType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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<String> expected = List.of("HOT Americano", "HOT CARAMEL Latte with ALMOND_MILK",
"HOT VANILLA Macchiato with WHOLE_MILK", "MATCHA Tea");
assertEquals(expected, coffeeShopOrder.getDrinkForOrder());
Expand Down
9 changes: 5 additions & 4 deletions coffee-shop-kata/jdk8/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
Expand All @@ -32,13 +32,14 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit5.version>5.9.3</junit5.version>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.0</version>
<artifactId>junit-jupiter</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public CoffeeShopOrder(String customerName, java.util.List<Item> 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]
Expand Down
25 changes: 3 additions & 22 deletions coffee-shop-kata/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand All @@ -25,7 +25,7 @@

<artifactId>coffee-shop-kata</artifactId>

<name>coffee-shop-kata</name>
<name>Coffee Shop Kata</name>
<packaging>pom</packaging>

<properties>
Expand All @@ -37,23 +37,4 @@
<module>jdk21</module>
</modules>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

0 comments on commit 3dbbd35

Please sign in to comment.