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 72a6eab9..15b57744 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
@@ -94,38 +94,6 @@ public void testBagelGetters()
assertEquals(bagel1.spreadType(), HERB_GARLIC_CREAM_CHEESE);
}
- @Test
- public void testCookieRecord()
- {
- Cookie cookie2 = new Cookie(CHOCOLATE_CHIP, true);
- assertTrue(Cookie.class.isRecord());
- assertEquals(cookie1, cookie2);
- assertEquals("Cookie[cookieType=CHOCOLATE_CHIP, warmed=true]", cookie1.toString());
- }
-
- @Test
- public void testCookieGetters()
- {
- assertTrue(cookie1.warmed());
- assertEquals(cookie1.cookieType(), CHOCOLATE_CHIP);
- }
-
- @Test
- public void testDonutRecord()
- {
- Donut donut2 = new Donut(GLAZED);
- assertTrue(Donut.class.isRecord());
- assertEquals(donut1.donutType(), GLAZED);
- assertEquals(donut1, donut2);
- assertEquals("Donut[donutType=GLAZED]", donut1.toString());
- }
-
- @Test
- public void testDonutGetters()
- {
- assertEquals(donut1.donutType(), GLAZED);
- }
-
@Test
public void testSealedClasses()
{
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 a4685d43..ffbd2edf 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,65 +16,10 @@
package bnymellon.codekatas.coffeeshopkata.food;
-import java.util.Objects;
-
-/**
- * Replace the entire class with a Record.
- * This replaces the need for a constructor, getters, toString(),
- * equals() and hashcode() method
- * NOTE: This example highlights the usage of a record to replace the
- * boilerplate of a plain Java class.
- *
- * @see ...
- */
-// TODO: convert class to record
-public class Cookie implements BakeryItem
-{
- private final CookieType cookieType;
- private final boolean warmed;
-
- public Cookie(CookieType cookieType, boolean warmed)
- {
- this.cookieType = cookieType;
- this.warmed = warmed;
- }
+public record Cookie(CookieType cookieType, boolean warmed) implements BakeryItem {
@Override
- public double getPrice()
- {
+ public double getPrice() {
return 1.25;
}
-
- public boolean isWarmed()
- {
- return warmed;
- }
-
- public CookieType getCookieType()
- {
- return cookieType;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj instanceof Cookie) {
- Cookie cookie = (Cookie) obj;
- return this.isWarmed() == cookie.isWarmed() && this.getCookieType() == cookie.getCookieType();
- }
- return false;
- }
-
- @Override
- public String toString()
- {
- return String.format("Cookie[cookieType=%s, warmed=%s]",
- this.getCookieType(), this.isWarmed());
- }
-
- @Override
- public int hashCode()
- {
- return Objects.hash(cookieType, warmed);
- }
}
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 1ba1460e..b238df69 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
@@ -16,58 +16,10 @@
package bnymellon.codekatas.coffeeshopkata.food;
-import java.util.Objects;
-
-/**
- * Replace the entire class with a Record.
- * This replaces the need for a constructor, getters, toString(),
- * equals() and hashcode() method
- * NOTE: This example highlights the usage of a record to replace the
- * boilerplate of a plain Java class.
- *
- * @see ...
- */
-// TODO: convert class to record
-public class Donut implements BakeryItem
-{
- private final DonutType donutType;
-
- public Donut(DonutType donutType)
- {
- this.donutType = donutType;
- }
+public record Donut(DonutType donutType) implements BakeryItem {
@Override
- public double getPrice()
- {
+ public double getPrice() {
return 1.75;
}
-
- public DonutType getDonutType()
- {
- return this.donutType;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj instanceof Donut) {
- Donut donut = (Donut) obj;
- return this.getDonutType() == donut.getDonutType();
- }
- return false;
- }
-
- @Override
- public String toString()
- {
- return String.format("Donut[donutType=%s]",
- this.getDonutType());
- }
-
- @Override
- public int hashCode()
- {
- return Objects.hash(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 51bcb148..1d60f2f7 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
@@ -100,41 +100,6 @@ public void testBagelGetters()
assertEquals(bagel1.getSpreadType(), HERB_GARLIC_CREAM_CHEESE);
}
- @Test
- public void testCookieRecord()
- {
- // TODO: Convert Cookie to record
- Cookie cookie2 = new Cookie(CHOCOLATE_CHIP, true);
- assertTrue(Cookie.class.isRecord());
- assertEquals(cookie1, cookie2);
- assertEquals("Cookie[cookieType=CHOCOLATE_CHIP, warmed=true]", cookie1.toString());
- }
-
- @Test
- public void testCookieGetters()
- {
- // TODO: Convert assertions to use Record getters
- assertTrue(cookie1.isWarmed());
- assertEquals(cookie1.getCookieType(), CHOCOLATE_CHIP);
- }
-
- @Test
- public void testDonutRecord()
- {
- // TODO: Convert Donut to record
- Donut donut2 = new Donut(GLAZED);
- assertTrue(Donut.class.isRecord());
- assertEquals(donut1, donut2);
- assertEquals("Donut[donutType=GLAZED]", donut1.toString());
- }
-
- @Test
- public void testDonutGetters()
- {
- // TODO: Convert assertions to use Record getters
- assertEquals(donut1.getDonutType(), GLAZED);
- }
-
@Test
public void testSealedClasses()
{
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 8917cd39..98771e92 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
@@ -91,35 +91,6 @@ public void testBagelGetters()
assertEquals(bagel1.getSpreadType(), HERB_GARLIC_CREAM_CHEESE);
}
- @Test
- public void testCookieClass()
- {
- Cookie cookie2 = new Cookie(CHOCOLATE_CHIP, true);
- assertEquals(cookie1, cookie2);
- assertEquals("Cookie[cookieType=CHOCOLATE_CHIP, warmed=true]", cookie1.toString());
- }
-
- @Test
- public void testCookieGetters()
- {
- assertTrue(cookie1.isWarmed());
- assertEquals(cookie1.getCookieType(), CHOCOLATE_CHIP);
- }
-
- @Test
- public void testDonutClass()
- {
- Donut donut2 = new Donut(GLAZED);
- assertEquals(donut1, donut2);
- assertEquals("Donut[donutType=GLAZED]", donut1.toString());
- }
-
- @Test
- public void testDonutGetters()
- {
- assertEquals(donut1.getDonutType(), GLAZED);
- }
-
@Test
public void getDrinkItems()
{